Skip to content

Commit

Permalink
Merge pull request #14 from alephium/fungible-token-details
Browse files Browse the repository at this point in the history
Display more fungible token details
  • Loading branch information
polarker authored Feb 28, 2024
2 parents c381e9a + cd90c73 commit fc52e6a
Show file tree
Hide file tree
Showing 4 changed files with 1,062 additions and 472 deletions.
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 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
additionalIssuanceAllowed: 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 additionalIssuanceAllowed = await isAdditionalTokenIssuanceAllowed(explorerProvider, contract, tokenAddress)
setTokenInfo({ ...tokenMetadata, verified, tokenId, tokenAddress, upgradable, additionalIssuanceAllowed })
} else {
setTokenInfo(undefined)
}
Expand Down Expand Up @@ -82,6 +113,8 @@ function TokenInfo() {
) : (
'undefined'
),
'Token Contract Upgradable': `${tokenInfo?.upgradable}`,
'Additional Issuance Allowed': `${tokenInfo?.additionalIssuanceAllowed}`
}}
/>
</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

0 comments on commit fc52e6a

Please sign in to comment.