11import { flattenTransactionResult } from '@/features/transactions/utils/flatten-transaction-result'
22import { TransactionType } from 'algosdk'
3- import { Arc3MetadataResult , Arc69MetadataResult , AssetMetadataResult , AssetResult } from './types'
3+ import { Arc3MetadataResult , Arc62MetadataResult , Arc69MetadataResult , AssetMetadataResult , AssetResult } from './types'
44import { getArc19Url , isArc19Url } from '../utils/arc19'
55import { getArc3Url , isArc3Url } from '../utils/arc3'
66import { base64ToUtf8 } from '@/utils/base64-to-utf8'
@@ -14,6 +14,8 @@ import { TransactionResult } from '@/features/transactions/data/types'
1414import algosdk from 'algosdk'
1515import { uint8ArrayToBase64 } from '@/utils/uint8-array-to-base64'
1616import { indexerTransactionToTransactionResult } from '@/features/transactions/mappers/indexer-transaction-mappers'
17+ import { getArc62AppId } from '../utils/arc62'
18+ import { createAssetCirculatingSupplyAtom } from './circulating-supply'
1719
1820// Currently, we support ARC-3, 19 and 69. Their specs can be found here https://github.com/algorandfoundation/ARCs/tree/main/ARCs
1921// ARCs are community standard, therefore, there are edge cases
@@ -24,10 +26,12 @@ import { indexerTransactionToTransactionResult } from '@/features/transactions/m
2426// - ARC-19 doesn't specify the metadata format but generally people use the ARC-3 format
2527const createAssetMetadataResult = async (
2628 assetResult : AssetResult ,
29+ get : Getter ,
2730 latestAssetCreateOrReconfigureTransaction ?: TransactionResult
2831) : Promise < AssetMetadataResult > => {
2932 let arc69MetadataResult : Arc69MetadataResult | undefined = undefined
3033 let arc3MetadataResult : Arc3MetadataResult | undefined = undefined
34+ let arc62MetadataResult : Arc62MetadataResult | undefined = undefined
3135
3236 // Get ARC-69 metadata if applicable
3337 if ( latestAssetCreateOrReconfigureTransaction && latestAssetCreateOrReconfigureTransaction . note ) {
@@ -59,6 +63,17 @@ const createAssetMetadataResult = async (
5963 metadata_url : gatewayMetadataUrl ,
6064 metadata,
6165 }
66+
67+ const arc62AppId = getArc62AppId ( arc3MetadataResult )
68+
69+ if ( arc62AppId ) {
70+ const circulatingSupply = await get ( createAssetCirculatingSupplyAtom ( arc62AppId , assetResult . index ) )
71+ if ( circulatingSupply !== undefined ) {
72+ arc62MetadataResult = {
73+ circulatingSupply,
74+ }
75+ }
76+ }
6277 } catch ( error ) {
6378 if ( error instanceof SyntaxError ) {
6479 // If the metadata url points to an image or video, we construct the faux arc3 metadata, so we can still display the image.
@@ -88,10 +103,11 @@ const createAssetMetadataResult = async (
88103 }
89104 }
90105
91- if ( arc3MetadataResult || arc69MetadataResult ) {
106+ if ( arc3MetadataResult || arc69MetadataResult || arc62MetadataResult ) {
92107 return {
93108 arc3 : arc3MetadataResult ,
94109 arc69 : arc69MetadataResult ,
110+ arc62 : arc62MetadataResult ,
95111 }
96112 }
97113
@@ -110,7 +126,7 @@ const noteToArc69Metadata = (note: string | undefined) => {
110126 return undefined
111127}
112128
113- const getAssetMetadataResult = async ( _ : Getter , __ : Setter , assetResult : AssetResult ) => {
129+ const getAssetMetadataResult = async ( get : Getter , __ : Setter , assetResult : AssetResult ) => {
114130 if ( assetResult . index === 0n ) {
115131 return null
116132 }
@@ -152,7 +168,7 @@ const getAssetMetadataResult = async (_: Getter, __: Setter, assetResult: AssetR
152168 return null
153169 }
154170
155- return await createAssetMetadataResult ( assetResult , assetConfigTransactionResults [ 0 ] )
171+ return await createAssetMetadataResult ( assetResult , get , assetConfigTransactionResults [ 0 ] )
156172}
157173
158174export const [ assetMetadataResultsAtom , getAssetMetadataResultAtom ] = readOnlyAtomCache (
0 commit comments