-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tangle-dapp): Implement Liquifier
unlock NFTs
unstake requests…
… table (#2521)
- Loading branch information
1 parent
6a0f28e
commit a881ede
Showing
88 changed files
with
3,824 additions
and
1,710 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
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
58 changes: 58 additions & 0 deletions
58
apps/tangle-dapp/components/LiquidStaking/stakeAndUnstake/FeeDetailItem.tsx
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,58 @@ | ||
import { BN, BN_ZERO } from '@polkadot/util'; | ||
import { FC, useMemo } from 'react'; | ||
|
||
import { LsProtocolId } from '../../../constants/liquidStaking/types'; | ||
import formatBn from '../../../utils/formatBn'; | ||
import getLsProtocolDef from '../../../utils/liquidStaking/getLsProtocolDef'; | ||
import scaleAmountByPermill from '../../../utils/scaleAmountByPermill'; | ||
import DetailItem from './DetailItem'; | ||
import useLsFeePermill from './useLsFeePermill'; | ||
|
||
export type FeeDetailItemProps = { | ||
isMinting: boolean; | ||
inputAmount: BN | null; | ||
protocolId: LsProtocolId; | ||
}; | ||
|
||
const FeeDetailItem: FC<FeeDetailItemProps> = ({ | ||
isMinting, | ||
inputAmount, | ||
protocolId, | ||
}) => { | ||
const feePermill = useLsFeePermill(protocolId, isMinting); | ||
|
||
const protocol = getLsProtocolDef(protocolId); | ||
|
||
// TODO: Add liquifier fees, and select either parachain or liquifier fees based on the given protocol's id. | ||
|
||
const feeAmount = useMemo(() => { | ||
// Propagate error or loading state. | ||
if (typeof feePermill !== 'number') { | ||
return feePermill; | ||
} | ||
|
||
return scaleAmountByPermill(inputAmount ?? BN_ZERO, feePermill); | ||
}, [feePermill, inputAmount]); | ||
|
||
const formattedFeeAmount = useMemo(() => { | ||
// Propagate error or loading state. | ||
if (!(feeAmount instanceof BN)) { | ||
return feeAmount; | ||
} | ||
|
||
const formattedAmount = formatBn(feeAmount, protocol.decimals, { | ||
includeCommas: true, | ||
}); | ||
|
||
return `${formattedAmount} ${protocol.token}`; | ||
}, [feeAmount, protocol.decimals, protocol.token]); | ||
|
||
const feeTitle = | ||
typeof feePermill !== 'number' | ||
? 'Fee' | ||
: `Fee (${(feePermill * 100).toFixed(2)}%)`; | ||
|
||
return <DetailItem title={feeTitle} value={formattedFeeAmount} />; | ||
}; | ||
|
||
export default FeeDetailItem; |
Oops, something went wrong.