-
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.
update xc-transfer page, balances (#85)
- Loading branch information
Showing
14 changed files
with
323 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.container { | ||
display: flex; | ||
gap: 1rem; | ||
} | ||
|
||
.balanceItem { | ||
display: flex; | ||
gap: 0.5rem; | ||
align-items: center; | ||
} | ||
|
||
.balanceWrapper { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
line-height: 1.5; | ||
height: fit-content; | ||
padding: 0.5rem 1.25rem; | ||
border-radius: 2rem; | ||
min-width: 8rem; | ||
font-weight: 500; | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/components/Elements/Selectors/ChainSelector/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,16 @@ | ||
.chainItem { | ||
display: flex; | ||
gap: 0.5rem; | ||
align-items: center; | ||
} | ||
|
||
.icon { | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
border-radius: 100%; | ||
} | ||
|
||
.label { | ||
font-size: 1rem; | ||
line-height: 1.5; | ||
} |
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,3 +1,4 @@ | ||
export * from './AssetSelector'; | ||
export * from './ChainSelector'; | ||
export * from './RecipientSelector'; | ||
export * from './RegionSelector'; |
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,123 @@ | ||
import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
|
||
import { useAccounts } from '../account'; | ||
import { useCoretimeApi, useRelayApi } from '../apis'; | ||
import { ApiState } from '../apis/types'; | ||
import { useToast } from '../toast'; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
} | ||
|
||
interface BalanceData { | ||
balance: { | ||
coretime: number; | ||
relay: number; | ||
}; | ||
} | ||
|
||
const defaultBalanceData: BalanceData = { | ||
balance: { | ||
coretime: 0, | ||
relay: 0, | ||
}, | ||
}; | ||
|
||
const BalanceContext = createContext<BalanceData>(defaultBalanceData); | ||
|
||
const BalanceProvider = ({ children }: Props) => { | ||
const { | ||
state: { activeAccount }, | ||
} = useAccounts(); | ||
const { toastWarning } = useToast(); | ||
const { | ||
state: { | ||
api: coretimeApi, | ||
apiState: coretimeApiState, | ||
symbol: coretimeSymbol, | ||
name: coretimeChain, | ||
}, | ||
} = useCoretimeApi(); | ||
const { | ||
state: { | ||
api: relayApi, | ||
apiState: relayApiState, | ||
symbol: relaySymbol, | ||
name: relayChain, | ||
}, | ||
} = useRelayApi(); | ||
|
||
const [coretimeBalance, setCoretimeBalance] = useState(0); | ||
const [relayBalance, setRelayBalance] = useState(0); | ||
|
||
useEffect(() => { | ||
const subscribeBalances = async () => { | ||
if (!activeAccount) { | ||
setCoretimeBalance(0); | ||
setRelayBalance(0); | ||
return; | ||
} | ||
if ( | ||
coretimeApiState !== ApiState.READY || | ||
relayApiState !== ApiState.READY | ||
) | ||
return; | ||
|
||
if (!coretimeApi || !relayApi) return; | ||
|
||
const { address } = activeAccount; | ||
|
||
const unsubscribeCoretime = await coretimeApi.queryMulti( | ||
[[coretimeApi.query.system.account, address]], | ||
([ | ||
{ | ||
data: { free }, | ||
}, | ||
]: [any]) => { | ||
setCoretimeBalance(free as number); | ||
free === 0 && | ||
toastWarning( | ||
`The selected account does not have any ${coretimeSymbol} tokens on ${coretimeChain}.` | ||
); | ||
} | ||
); | ||
|
||
const unsubscribeRelay = await relayApi.queryMulti( | ||
[[relayApi.query.system.account, address]], | ||
([ | ||
{ | ||
data: { free }, | ||
}, | ||
]: [any]) => { | ||
setRelayBalance(free as number); | ||
free === 0 && | ||
toastWarning( | ||
`The selected account does not have any ${relaySymbol} tokens on ${relayChain}.` | ||
); | ||
} | ||
); | ||
return () => { | ||
unsubscribeCoretime(); | ||
unsubscribeRelay(); | ||
}; | ||
}; | ||
subscribeBalances(); | ||
}, [activeAccount, coretimeApi, coretimeApiState, relayApi, relayApiState]); | ||
|
||
return ( | ||
<BalanceContext.Provider | ||
value={{ | ||
balance: { | ||
coretime: coretimeBalance, | ||
relay: relayBalance, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</BalanceContext.Provider> | ||
); | ||
}; | ||
|
||
const useBalances = () => useContext(BalanceContext); | ||
|
||
export { BalanceProvider, useBalances }; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.