-
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.
- Loading branch information
Showing
5 changed files
with
65 additions
and
49 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
54 changes: 54 additions & 0 deletions
54
src/extensions/artcpaclub/src/previews/UnstakeActionPreview.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,54 @@ | ||
import { Config } from '../config' | ||
import { EsdtPool, NftPool } from '../types' | ||
import BigNumber from 'bignumber.js' | ||
import React, { useEffect, useState } from 'react' | ||
import { ExtensionConfig } from '../../../../shared/types' | ||
import { ProposalAction, toActionArgsBigNumber, toFormattedTokenAmount } from '@peerme/core-ts' | ||
import { ActionPreviewHighlight } from '../../../../shared/ui/elements' | ||
|
||
type Props = { | ||
action: ProposalAction | ||
config: ExtensionConfig | ||
} | ||
|
||
export function UnstakeActionPreview(props: Props) { | ||
const [selectedPool, setSelectedPool] = useState<EsdtPool | NftPool | null>(null) | ||
const isNft = props.action.arguments.length === 3 | ||
const poolId = props.action.arguments[0] as number | ||
const nonce = (isNft ? props.action.arguments[1] : null) as number | null | ||
const optAmount = (isNft ? props.action.arguments[2] : props.action.arguments[1]) as number | null | ||
const amountBig = optAmount ? toActionArgsBigNumber(optAmount) : new BigNumber(0) | ||
|
||
useEffect(() => { | ||
if (!poolId) return | ||
const apiEndpoint = isNft ? 'nftstaking' : 'tokenstaking' | ||
fetch(Config.ApiBaseUrl(props.config.network) + '/' + apiEndpoint + '/' + poolId).then(async (res) => { | ||
const data = await res.json() | ||
setSelectedPool(data) | ||
}) | ||
}, [poolId]) | ||
|
||
if (isNft) { | ||
return ( | ||
<ActionPreviewHighlight> | ||
unstake{' '} | ||
<strong> | ||
{amountBig.toNumber()} {selectedPool ? selectedPool.stake_token_id : ''} | ||
</strong>{' '} | ||
with Nonce <strong>{nonce}</strong>{' '} | ||
{selectedPool ? `from pool ${selectedPool.title}` : `from pool with id ${poolId}`}. | ||
</ActionPreviewHighlight> | ||
) | ||
} | ||
|
||
return ( | ||
<ActionPreviewHighlight> | ||
unstake{' '} | ||
<strong> | ||
{toFormattedTokenAmount(amountBig, (selectedPool as EsdtPool)?.stake_token_decimal || 0)}{' '} | ||
{selectedPool ? selectedPool.stake_token_id : ''} | ||
</strong>{' '} | ||
{selectedPool ? `from pool ${selectedPool.title}` : `from pool with id ${poolId}`}. | ||
</ActionPreviewHighlight> | ||
) | ||
} |
38 changes: 0 additions & 38 deletions
38
src/extensions/artcpaclub/src/previews/UnstakeEsdtActionPreview.tsx
This file was deleted.
Oops, something went wrong.