Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display more fungible token details #14

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
},
"dependencies": {
"@alephium/token-list": "^0.0.15",
"@alephium/web3": "^0.21.0",
"@alephium/web3-react": "^0.21.0",
"@alephium/web3": "0.30.0-beta.1",
"@alephium/web3-react": "0.30.0-beta.1",
"@emotion/react": "^11.11.1",
"@mantine/core": "^6.0.19",
"@mantine/form": "^6.0.19",
Expand All @@ -28,7 +28,7 @@
"react-router-dom": "^6.14.2"
},
"devDependencies": {
"@alephium/cli": "^0.21.0",
"@alephium/cli": "0.30.0-beta.1",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand All @@ -41,6 +41,10 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
"vite": "^4.4.5",
"vite-plugin-node-polyfills": "^0.21.0"
},
"resolutions": {
"clipboardy": "3.0.0"
}
}
37 changes: 35 additions & 2 deletions src/components/Token/TokenInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
import { Box, Center, Stack, TextInput, rem } from '@mantine/core'
import { useCallback, useState } from 'react'
import { getTokenMetadata, useAlephium, useNetworkId } from '../../utils/utils'
import { getTokenMetadata, useAlephium, useExplorer, useNetworkId } from '../../utils/utils'
import {
FungibleTokenMetaData,
addressFromTokenId,
groupOfAddress,
hexToString,
prettifyTokenAmount,
codec,
ExplorerProvider,
Address,
} from '@alephium/web3'
import MyTable from '../Misc/MyTable'
import CopyText from '../Misc/CopyText'
import { Buffer } from 'buffer'

function isContractUpgradable(contract: codec.contract.Contract): boolean {
return contract.methods.some((method) =>
method.instrs.some((instr) => {
return instr.code === codec.MigrateSimple.code || instr.code === codec.MigrateWithFields.code
}))
}

async function isTokenAllowAdditionalIssuance(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
})
}

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

function TokenInfo() {
const [value, setValue] = useState('')
const [tokenInfo, setTokenInfo] = useState<TokenInfo>()
const nodeProvider = useAlephium()
const explorerProvider = useExplorer()
const [network] = useNetworkId()

const searchToken = useCallback(async (tokenId: string) => {
Expand All @@ -36,7 +62,12 @@ function TokenInfo() {
(token) => token.id === tokenId
) !== undefined
const tokenAddress = addressFromTokenId(tokenId)
setTokenInfo({ ...tokenMetadata, verified, tokenId, tokenAddress })
const group = groupOfAddress(tokenAddress)
const contractState = await nodeProvider.contracts.getContractsAddressState(tokenAddress, { group })
const contract = codec.contract.contractCodec.decodeContract(Buffer.from(contractState.bytecode, 'hex'))
const upgradable = isContractUpgradable(contract)
const allowAdditionalIssuance = await isTokenAllowAdditionalIssuance(explorerProvider, contract, tokenAddress)
setTokenInfo({ ...tokenMetadata, verified, tokenId, tokenAddress, upgradable, allowAdditionalIssuance })
} else {
setTokenInfo(undefined)
}
Expand Down Expand Up @@ -82,6 +113,8 @@ function TokenInfo() {
) : (
'undefined'
),
Upgradable: `${tokenInfo?.upgradable}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Token Contract Upgradable

'Allow Additional Issuance': `${tokenInfo?.allowAdditionalIssuance}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Issuance Allowed

}}
/>
</Box>
Expand Down
8 changes: 7 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vitejs.dev/config/
export default defineConfig({
base: '/alephium-toolkit/',
plugins: [react()],
plugins: [
react(),
nodePolyfills({
include: ['buffer'],
}),
],
})
Loading
Loading