-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite): add CMAccount creation functionality and a new partners …
…section partner profile
- Loading branch information
Showing
23 changed files
with
6,702 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Box, Typography } from '@mui/material' | ||
import React from 'react' | ||
|
||
const Alert = ({ | ||
variant, | ||
title, | ||
content, | ||
}: { | ||
variant: 'info' | 'negative' | ||
title?: string | ||
content: string | ||
}) => { | ||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
gap: '14px', | ||
padding: '16px', | ||
border: '1px solid', | ||
borderColor: | ||
variant === 'info' ? 'rgba(0, 133, 255, 0.5)' : 'rgba(229, 67, 31, 0.5)', | ||
background: | ||
variant === 'info' ? 'rgba(0, 133, 255, 0.05)' : 'rgba(229, 67, 31, 0.05)', | ||
borderRadius: '6px', | ||
maxWidth: '350px', | ||
...(!title && { alignItems: 'center' }), | ||
}} | ||
> | ||
<Box sx={{ ...(!title && { display: 'flex', alignItems: 'center' }) }}> | ||
{variant === 'info' && ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 22C17.5 22 22 17.5 22 12C22 6.5 17.5 2 12 2C6.5 2 2 6.5 2 12C2 17.5 6.5 22 12 22ZM11 7H13V9H11V7ZM14 17H10V15H11V13H10V11H13V15H14V17Z" | ||
fill="#0085FF" | ||
/> | ||
</svg> | ||
)} | ||
{variant === 'negative' && ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 2C17.53 2 22 6.47 22 12C22 17.53 17.53 22 12 22C6.47 22 2 17.53 2 12C2 6.47 6.47 2 12 2ZM15.59 7L12 10.59L8.41 7L7 8.41L10.59 12L7 15.59L8.41 17L12 13.41L15.59 17L17 15.59L13.41 12L17 8.41L15.59 7Z" | ||
fill="#E5431F" | ||
/> | ||
</svg> | ||
)} | ||
</Box> | ||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '8px' }}> | ||
{title && ( | ||
<Typography variant="body2" fontWeight={600}> | ||
{title} | ||
</Typography> | ||
)} | ||
{content && <Typography variant="caption">{content}</Typography>} | ||
</Box> | ||
</Box> | ||
) | ||
} | ||
|
||
export default Alert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import Big from 'big.js' | ||
import BN from 'bn.js' | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
|
||
Big.PE = 32 | ||
|
||
function bnToBig(val, denomination) { | ||
return new Big(val.toString()).div(Math.pow(10, denomination)) | ||
} | ||
|
||
function bigToBN(val, denomination) { | ||
return new BN(val.mul(Math.pow(10, denomination)).toString()) | ||
} | ||
|
||
const DecimalInput = ({ | ||
denomination = 0, | ||
max = null, | ||
min = 0, | ||
step = null, | ||
placeholder, | ||
value, | ||
initial = null, | ||
onChange, | ||
}) => { | ||
const [val, setVal] = useState(bnToString(initial)) | ||
|
||
const bnToString = useCallback( | ||
val => { | ||
return val ? bnToBig(val, denomination).toString() : null | ||
}, | ||
[denomination], | ||
) | ||
|
||
const stringToBN = useCallback( | ||
strVal => { | ||
return bigToBN(new Big(strVal), denomination) | ||
}, | ||
[denomination], | ||
) | ||
|
||
const maxNumBN = max | ||
const maxNumString = bnToString(maxNumBN) | ||
|
||
const stepNum = (() => { | ||
if (!step) { | ||
if (denomination >= 2) { | ||
return 0.01 | ||
} else { | ||
return Math.pow(10, -denomination) | ||
} | ||
} | ||
try { | ||
return bnToString(step) | ||
} catch (e) { | ||
console.error(e) | ||
return '0.01' | ||
} | ||
})() | ||
|
||
useEffect(() => { | ||
if (!val) { | ||
onChange(new BN(0)) | ||
return | ||
} | ||
try { | ||
let splitVal = val.toString().split('.') | ||
let wholeVal = splitVal[0] | ||
let denomVal = splitVal[1] | ||
if (denomVal) { | ||
if (denomVal.length > denomination) { | ||
let newDenom = denomVal.substring(0, denomination) | ||
setVal(`${wholeVal}.${newDenom}`) | ||
return | ||
} | ||
} | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
if (parseFloat(val) < min) { | ||
setVal(min.toString()) | ||
return | ||
} | ||
let valBn = stringToBN(val) | ||
onChange(valBn) | ||
}, [val, denomination, min, onChange, stringToBN]) | ||
|
||
useEffect(() => { | ||
setVal(bnToString(value)) | ||
}, [value, bnToString]) | ||
|
||
const handleChange = e => { | ||
setVal(e.target.value) | ||
} | ||
|
||
const handleBlur = () => { | ||
// If number is above max amount, correct it | ||
const valBig = Big(val || '0') | ||
const valBN = bigToBN(valBig, denomination) | ||
if (maxNumBN != null) { | ||
if (valBN.gt(maxNumBN)) { | ||
setVal(bnToString(maxNumBN)) | ||
} | ||
} | ||
} | ||
|
||
const maxout = () => { | ||
if (maxNumBN != null) { | ||
setVal(bnToString(maxNumBN)) | ||
} | ||
} | ||
|
||
const clear = () => { | ||
setVal(undefined) | ||
} | ||
|
||
return ( | ||
<input | ||
type="number" | ||
inputMode="decimal" | ||
placeholder={placeholder} | ||
value={val} | ||
min={min} | ||
max={maxNumString} | ||
step={stepNum} | ||
onChange={handleChange} | ||
onBlur={handleBlur} | ||
style={{ | ||
textAlign: 'right', | ||
outline: 'none', | ||
WebkitAppearance: 'none', | ||
MozAppearance: 'textfield', | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export default DecimalInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { InputAdornment, Typography } from '@mui/material' | ||
import TextField from '@mui/material/TextField' // Import TextField if using Material-UI | ||
import React, { useMemo } from 'react' | ||
import { actionTypes, usePartnerConfigurationContext } from '../helpers/partnerConfigurationContext' | ||
|
||
const Input = ({ variant = 'outlined', ...rest }) => { | ||
const { state, dispatch } = usePartnerConfigurationContext() | ||
const error = useMemo(() => { | ||
if (!state.balance) return true | ||
let balance = parseFloat(state.balance) | ||
if (balance < 100) return true | ||
else return false | ||
}, [state]) | ||
return ( | ||
<TextField | ||
value={state.balance} | ||
onChange={e => { | ||
dispatch({ | ||
type: actionTypes.UPDATE_BALANCE, | ||
payload: { | ||
newValue: e.target.value, | ||
}, | ||
}) | ||
}} | ||
type="number" | ||
error={error} | ||
InputProps={{ | ||
sx: { | ||
'& input': { | ||
fontSize: '16px', | ||
}, | ||
}, | ||
startAdornment: ( | ||
<InputAdornment | ||
position="start" | ||
sx={{ | ||
width: 'fit-content', | ||
color: theme => theme.palette.text.primary, | ||
}} | ||
> | ||
<Typography variant="body2">Prefund Amount:</Typography> | ||
</InputAdornment> | ||
), | ||
endAdornment: error ? ( | ||
<InputAdornment position="end" sx={{ width: 'fit-contnet' }}> | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 2C17.53 2 22 6.47 22 12C22 17.53 17.53 22 12 22C6.47 22 2 17.53 2 12C2 6.47 6.47 2 12 2ZM15.59 7L12 10.59L8.41 7L7 8.41L10.59 12L7 15.59L8.41 17L12 13.41L15.59 17L17 15.59L13.41 12L17 8.41L15.59 7Z" | ||
fill="#E5431F" | ||
/> | ||
</svg> | ||
</InputAdornment> | ||
) : ( | ||
<InputAdornment position="end" sx={{ width: 'fit-contnet' }}> | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 2C6.5 2 2 6.5 2 12C2 17.5 6.5 22 12 22C17.5 22 22 17.5 22 12C22 6.5 17.5 2 12 2ZM10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z" | ||
fill="#18B728" | ||
/> | ||
</svg> | ||
</InputAdornment> | ||
), | ||
}} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
export default Input |
Oops, something went wrong.