Skip to content

Commit

Permalink
Update token info
Browse files Browse the repository at this point in the history
  • Loading branch information
polarker committed Mar 1, 2024
1 parent fc52e6a commit d20a683
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/components/Token/TokenInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@ function isContractUpgradable(contract: codec.contract.Contract): boolean {
}))
}

function isContractDestroyable(contract: codec.contract.Contract): boolean {
return contract.methods.some((method) => {
return method.instrs.some((instr) => instr.code === codec.DestroySelf.code)
})
}

async function isAdditionalTokenIssuanceAllowed(
explorerProvider: ExplorerProvider,
contract: codec.contract.Contract,
address: Address,
): Promise<boolean> {
const result = await explorerProvider.contracts.getContractsContractAddressParent(address)
return result.parent !== undefined && contract.methods.some((method) => {
return method.instrs.some((instr) => instr.code === codec.DestroySelf.code)
})
return result.parent !== undefined && isContractDestroyable(contract)
}

type TokenInfo = FungibleTokenMetaData & {
verified: boolean
tokenId: string
tokenAddress: string
upgradable: boolean
destroyable: boolean
additionalIssuanceAllowed: boolean
}

Expand Down Expand Up @@ -66,15 +71,16 @@ function TokenInfo() {
const contractState = await nodeProvider.contracts.getContractsAddressState(tokenAddress, { group })
const contract = codec.contract.contractCodec.decodeContract(Buffer.from(contractState.bytecode, 'hex'))
const upgradable = isContractUpgradable(contract)
const destroyable = isContractDestroyable(contract)
const additionalIssuanceAllowed = await isAdditionalTokenIssuanceAllowed(explorerProvider, contract, tokenAddress)
setTokenInfo({ ...tokenMetadata, verified, tokenId, tokenAddress, upgradable, additionalIssuanceAllowed })
setTokenInfo({ ...tokenMetadata, verified, tokenId, tokenAddress, upgradable, destroyable, additionalIssuanceAllowed })
} else {
setTokenInfo(undefined)
}
}, [])

return (
<Center h={rem('80%')}>
<Center mt={"xl"}>
<Stack>
<TextInput
w={rem('40rem')}
Expand All @@ -89,7 +95,6 @@ function TokenInfo() {
<Box mt={'xl'} w={rem('55rem')}>
<MyTable
data={{
Verified: `${tokenInfo?.verified}`,
Name: `${tokenInfo ? hexToString(tokenInfo.name) : undefined}`,
Symbol: `${
tokenInfo ? hexToString(tokenInfo.symbol) : undefined
Expand All @@ -114,6 +119,7 @@ function TokenInfo() {
'undefined'
),
'Token Contract Upgradable': `${tokenInfo?.upgradable}`,
'Token Contract Destroyable': `${tokenInfo?.destroyable}`,
'Additional Issuance Allowed': `${tokenInfo?.additionalIssuanceAllowed}`
}}
/>
Expand Down

0 comments on commit d20a683

Please sign in to comment.