|
1 | 1 | import { ApplicationId } from './types' |
2 | 2 | import { useMemo } from 'react' |
3 | 3 | import { atom, useAtomValue } from 'jotai' |
4 | | -import { Application, ApplicationBox, BoxDescriptor } from '../models' |
| 4 | +import { Application, BoxDescriptor } from '../models' |
5 | 5 | import { Buffer } from 'buffer' |
6 | 6 | import { loadable } from 'jotai/utils' |
7 | 7 | import { createLoadableViewModelPageAtom } from '@/features/common/data/lazy-load-pagination' |
8 | 8 | import { DEFAULT_FETCH_SIZE } from '@/features/common/constants' |
9 | 9 | import { indexer } from '@/features/common/data/algo-client' |
10 | 10 | import { Arc56Contract } from '@algorandfoundation/algokit-utils/types/app-arc56' |
11 | 11 | import { asBoxDescriptor } from '../mappers' |
12 | | -import { base64ToUtf8IfValid } from '@/utils/base64-to-utf8' |
13 | | -import { base64ToBytes } from '@/utils/base64-to-bytes' |
14 | 12 | import { asDecodedAbiStorageValue } from '@/features/abi-methods/mappers' |
15 | | -import { uint8ArrayToUtf8 } from '@/utils/uint8-array-to-utf8' |
| 13 | +import { uint8ArrayToBase64 } from '@/utils/uint8-array-to-base64' |
16 | 14 |
|
17 | 15 | const getApplicationBoxNames = async (applicationId: ApplicationId, appSpec?: Arc56Contract, nextPageToken?: string) => { |
18 | 16 | const results = await indexer |
@@ -45,15 +43,11 @@ export const useApplicationBox = (application: Application, boxDescriptor: BoxDe |
45 | 43 | return useMemo(() => { |
46 | 44 | return atom(async () => { |
47 | 45 | const result = await getApplicationBox(application.id, boxDescriptor.base64Name) |
48 | | - const box = { |
49 | | - name: uint8ArrayToUtf8(result.name), |
50 | | - value: uint8ArrayToUtf8(result.value), |
51 | | - } as ApplicationBox |
52 | 46 |
|
53 | 47 | if (application.appSpec && 'valueType' in boxDescriptor) { |
54 | | - return asDecodedAbiStorageValue(application.appSpec, boxDescriptor.valueType, base64ToBytes(box.value)) |
| 48 | + return asDecodedAbiStorageValue(application.appSpec, boxDescriptor.valueType, result.value) |
55 | 49 | } else { |
56 | | - return base64ToUtf8IfValid(box.value) |
| 50 | + return uint8ArrayToBase64(result.value) |
57 | 51 | } |
58 | 52 | }) |
59 | 53 | }, [application, boxDescriptor]) |
|
0 commit comments