-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show application name if it follows algokit standard
- Loading branch information
1 parent
3aafc0d
commit 7dc66b8
Showing
17 changed files
with
304 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ApplicationResult } from '@/features/accounts/data/types' | ||
import { atomsInAtom } from '@/features/common/data/atoms-in-atom' | ||
import { atom } from 'jotai' | ||
import { ApplicationMetadataResult } from './types' | ||
import { indexer } from '@/features/common/data' | ||
import { flattenTransactionResult } from '@/features/transactions/utils/flatten-transaction-result' | ||
import { TransactionResult } from '@algorandfoundation/algokit-utils/types/indexer' | ||
import { TransactionType } from 'algosdk' | ||
import { base64ToUtf8 } from '@/utils/base64-to-utf8' | ||
import { parseArc2 } from '@/features/transactions/mappers/arc-2' | ||
import { parseJson } from '@/utils/parse-json' | ||
|
||
const createApplicationMetadataResultAtom = (applicationResult: ApplicationResult) => { | ||
return atom<Promise<ApplicationMetadataResult> | ApplicationMetadataResult>(async (_get) => { | ||
// We only need to fetch the first page to find the application creation transaction | ||
const transactionResults = await indexer | ||
.searchForTransactions() | ||
.applicationID(applicationResult.id) | ||
.limit(3) | ||
.do() | ||
.then((res) => res.transactions as TransactionResult[]) | ||
|
||
const creationTransaction = transactionResults | ||
.flatMap((txn) => flattenTransactionResult(txn)) | ||
.find((txn) => txn['tx-type'] === TransactionType.appl && txn['created-application-index'] === applicationResult.id) | ||
if (!creationTransaction) return null | ||
|
||
const text = base64ToUtf8(creationTransaction.note ?? '') | ||
|
||
const maybeArc2 = parseArc2(text) | ||
if (maybeArc2 && maybeArc2.format === 'j') { | ||
const arc2Data = parseJson(maybeArc2.data) | ||
if (arc2Data && 'name' in arc2Data) { | ||
return { name: arc2Data.name } | ||
} | ||
} | ||
|
||
return null | ||
}) | ||
} | ||
|
||
export const [applicationMetadataResultsAtom, getApplicationMetadataResultAtom] = atomsInAtom( | ||
createApplicationMetadataResultAtom, | ||
(applicationResult) => applicationResult.id | ||
) |
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,12 @@ | ||
import { JotaiStore } from '@/features/common/data/types' | ||
import { ApplicationId } from './types' | ||
import { atom } from 'jotai' | ||
import { getApplicationResultAtom } from './application-result' | ||
import { asApplicationSummary } from '../mappers' | ||
|
||
export const createApplicationSummaryAtom = (store: JotaiStore, applicationId: ApplicationId) => { | ||
return atom(async (get) => { | ||
const applicationResult = await get(getApplicationResultAtom(store, applicationId)) | ||
return asApplicationSummary(applicationResult) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export type ApplicationId = number | ||
|
||
export type ApplicationMetadataResult = { | ||
name: string | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Arc2TransactionNote } from '@algorandfoundation/algokit-utils/types/transaction' | ||
|
||
// Based on the ARC-2 spec https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md#specification | ||
const arc2Regex = /^([a-zA-Z0-9][a-zA-Z0-9_/@.-]{4,31}):([mjbu]{1})(.*)$/ | ||
|
||
export function parseArc2(maybeArc2: string) { | ||
const result = maybeArc2.match(arc2Regex) | ||
if (result && result.length === 4) { | ||
return { | ||
dAppName: result[1], | ||
format: result[2] as 'm' | 'b' | 'u' | 'j', | ||
data: result[3], | ||
} satisfies Arc2TransactionNote | ||
} | ||
} |
Oops, something went wrong.