-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add info to the Bedeem from Backstop pool UI (#291)
* feat: backstop pool withdraw info * refactor: fee * feat: token price on redeem ui --------- Co-authored-by: Gonza Montiel <[email protected]>
- Loading branch information
1 parent
cdf598e
commit 208dacd
Showing
11 changed files
with
171 additions
and
40 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
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 type WithdrawLiquidityValues = { | ||
amount: number; | ||
address: string; | ||
}; |
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
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,44 @@ | ||
import { Abi } from '@polkadot/api-contract'; | ||
import { useSharesTargetWorth } from '../../../../hooks/nabla/useSharesTargetWorth'; | ||
import { useDebouncedValue } from '../../../../hooks/useDebouncedValue'; | ||
import { FixedU128Decimals, nativeToDecimal, prettyNumbers } from '../../../../shared/parseNumbers'; | ||
import { Skeleton } from '../../../Skeleton'; | ||
|
||
export interface TokenAmountProps { | ||
address: string; | ||
abi?: Abi | Record<string, unknown>; | ||
amount?: number; | ||
debounce?: number; | ||
loader?: boolean; | ||
symbol?: ReactNode; | ||
fallback?: string | number; | ||
} | ||
|
||
const TokenAmount = ({ | ||
symbol, | ||
abi, | ||
fallback, | ||
address, | ||
amount = 0, | ||
loader = true, | ||
debounce = 800, | ||
}: TokenAmountProps): JSX.Element | null => { | ||
const debouncedAmount = useDebouncedValue(amount, debounce); | ||
const arg = debounce ? debouncedAmount : amount; | ||
const { isLoading, data } = useSharesTargetWorth({ | ||
address, | ||
abi, | ||
amount: arg, | ||
}); | ||
if (isLoading || (!!debounce && amount !== debouncedAmount)) { | ||
return loader ? <Skeleton className="inline-flex">10000</Skeleton> : null; | ||
} | ||
|
||
return ( | ||
<span title={data?.toString()}> | ||
{data ? prettyNumbers(nativeToDecimal(data || '0', FixedU128Decimals).toNumber()) : fallback ?? null} | ||
{symbol ? symbol : null} | ||
</span> | ||
); | ||
}; | ||
export default TokenAmount; |
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 { Abi } from '@polkadot/api-contract'; | ||
import { cacheKeys, inactiveOptions } from '../../constants/cache'; | ||
import { swapPoolAbi } from '../../contracts/nabla/SwapPool'; | ||
import { QueryOptions } from '../../shared/helpers'; | ||
import { useContract } from '../../shared/useContract'; | ||
|
||
export type UseSharesTargetWorthProps = { | ||
address: string | undefined; | ||
amount: number | undefined; | ||
abi?: Abi | Dict; | ||
}; | ||
|
||
export const useSharesTargetWorth = ( | ||
{ address, amount, abi = swapPoolAbi }: UseSharesTargetWorthProps, | ||
options?: QueryOptions, | ||
) => { | ||
return useContract([cacheKeys.sharesTargetWorth], { | ||
...inactiveOptions['1m'], | ||
...options, | ||
address, | ||
abi, | ||
method: 'sharesTargetWorth', | ||
args: [amount], | ||
enabled: Boolean(address && amount && options?.enabled !== false), | ||
}); | ||
}; |