-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cross-chain token transfer * native transfer works * cross-chain transfers * symbol * lint fix * refactor utililty methods * update transfer page * update purchase page * small fixes * add network icon * add border radius * add rococo * fix * update asset & chain selector * fixes * fixes --------- Co-authored-by: topeth <supernathanliu@gmail.com>
- Loading branch information
Showing
19 changed files
with
614 additions
and
190 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,26 @@ | ||
import { Typography, useTheme } from '@mui/material'; | ||
|
||
import { formatBalance } from '@/utils/functions'; | ||
|
||
interface BalanceProps { | ||
coretimeBalance: number; | ||
relayBalance: number; | ||
symbol: string; | ||
} | ||
|
||
const Balance = ({ relayBalance, coretimeBalance, symbol }: BalanceProps) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<Typography sx={{ color: theme.palette.text.primary, my: '0.5em' }}> | ||
{`Relay chain: ${formatBalance(relayBalance.toString(), false)} ${symbol}`} | ||
</Typography> | ||
<Typography sx={{ color: theme.palette.text.primary, my: '0.5em' }}> | ||
{`Coretime chain: ${formatBalance(coretimeBalance.toString(), false)} ${symbol}`} | ||
</Typography> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Balance; |
9 changes: 9 additions & 0 deletions
9
src/components/Elements/Selectors/AssetSelector/index.module.scss
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,9 @@ | ||
.options { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.option { | ||
min-width: 250px; | ||
margin: 1em 5em; | ||
} |
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,45 @@ | ||
import { ToggleButton, ToggleButtonGroup, useTheme } from '@mui/material'; | ||
import FormControl from '@mui/material/FormControl'; | ||
|
||
import { AssetType } from '@/models'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
interface AssetSelectorProps { | ||
asset: AssetType; | ||
setAsset: (_: AssetType) => void; | ||
symbol: string; | ||
} | ||
|
||
export default function AssetSelector({ | ||
asset, | ||
setAsset, | ||
symbol, | ||
}: AssetSelectorProps) { | ||
const theme = useTheme(); | ||
return ( | ||
<FormControl> | ||
<ToggleButtonGroup | ||
value={asset} | ||
exclusive // This ensures only one can be selected at a time | ||
onChange={(e: any) => setAsset(parseInt(e.target.value) as AssetType)} | ||
className={styles.options} | ||
> | ||
<ToggleButton | ||
className={styles.option} | ||
sx={{ color: theme.palette.text.primary }} | ||
value={AssetType.TOKEN} | ||
> | ||
{symbol} | ||
</ToggleButton> | ||
<ToggleButton | ||
className={styles.option} | ||
sx={{ color: theme.palette.text.primary }} | ||
value={AssetType.REGION} | ||
> | ||
Region | ||
</ToggleButton> | ||
</ToggleButtonGroup> | ||
</FormControl> | ||
); | ||
} |
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
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 |
---|---|---|
@@ -1,42 +1,73 @@ | ||
import { ApiPromise } from '@polkadot/api'; | ||
import { useInkathon } from '@scio-labs/use-inkathon'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
import { useCoretimeApi } from '@/contexts/apis'; | ||
import { parseHNString } from '@/utils/functions'; | ||
|
||
import { useCoretimeApi, useRelayApi } from '@/contexts/apis'; | ||
import { ApiState } from '@/contexts/apis/types'; | ||
import { useToast } from '@/contexts/toast'; | ||
|
||
// React hook for fetching balance. | ||
const useBalance = () => { | ||
const { | ||
state: { api, apiState, symbol }, | ||
state: { api: coretimeApi, apiState: coretimeApiState, symbol }, | ||
} = useCoretimeApi(); | ||
const { | ||
state: { api: relayApi, apiState: relayApiState }, | ||
} = useRelayApi(); | ||
|
||
const { activeAccount } = useInkathon(); | ||
|
||
const [balance, setBalance] = useState(0); | ||
const [coretimeBalance, setCoretimeBalance] = useState(0); | ||
const [relayBalance, setRelayBalance] = useState(0); | ||
|
||
const { toastWarning } = useToast(); | ||
|
||
const fetchBalance = useCallback(async () => { | ||
if (api && apiState == ApiState.READY && activeAccount) { | ||
const fetchBalance = useCallback( | ||
async (api: ApiPromise): Promise<number | undefined> => { | ||
if (!activeAccount) return; | ||
|
||
const accountData: any = ( | ||
await api.query.system.account(activeAccount.address) | ||
).toHuman(); | ||
const balance = parseFloat(accountData.data.free.toString()); | ||
setBalance(balance); | ||
|
||
if (balance === 0) { | ||
toastWarning( | ||
`The selected account does not have any ${symbol} tokens on the Coretime chain.` | ||
); | ||
} | ||
const balance = parseHNString(accountData.data.free.toString()); | ||
|
||
return balance; | ||
}, | ||
[activeAccount] | ||
); | ||
|
||
const fetchBalances = useCallback(() => { | ||
if (coretimeApi && coretimeApiState == ApiState.READY) { | ||
fetchBalance(coretimeApi).then((balance) => { | ||
balance !== undefined && setCoretimeBalance(balance); | ||
balance === 0 && | ||
toastWarning( | ||
`The selected account does not have any ${symbol} tokens on the Coretime chain.` | ||
); | ||
}); | ||
} | ||
if (relayApi && relayApiState == ApiState.READY) { | ||
fetchBalance(relayApi).then((balance) => { | ||
balance !== undefined && setRelayBalance(balance); | ||
}); | ||
} | ||
}, [api, apiState, activeAccount, toastWarning, symbol]); | ||
}, [ | ||
fetchBalance, | ||
toastWarning, | ||
symbol, | ||
coretimeApi, | ||
coretimeApiState, | ||
relayApi, | ||
relayApiState, | ||
]); | ||
|
||
useEffect(() => { | ||
fetchBalance(); | ||
}, [fetchBalance]); | ||
fetchBalances(); | ||
}); | ||
|
||
return balance; | ||
return { coretimeBalance, relayBalance, fetchBalances }; | ||
}; | ||
|
||
export default useBalance; |
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
Oops, something went wrong.