Skip to content

Commit 4e1cd74

Browse files
authored
fix: global state is undefined when returned from algod (#65)
1 parent cfffc59 commit 4e1cd74

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

src/features/applications/components/application-global-state-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
}
99

1010
export function ApplicationGlobalStateTable({ application }: Props) {
11-
const entries = useMemo(() => Array.from(application.globalState.entries()), [application])
11+
const entries = useMemo(() => Array.from(application.globalState?.entries() ?? []), [application])
1212
return <DataTable columns={tableColumns} data={entries} />
1313
}
1414

src/features/applications/data/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export type ApplicationMetadataResult = {
66
name: string
77
} | null
88

9-
export type ApplicationResult = Omit<IndexerApplicationResult, 'created-at-round' | 'deleted-at-round'>
9+
export type ApplicationResult = Omit<IndexerApplicationResult, 'created-at-round' | 'deleted-at-round' | 'params'> & {
10+
params: Omit<IndexerApplicationResult['params'], 'global-state'> & {
11+
'global-state'?: IndexerApplicationResult['params']['global-state']
12+
}
13+
}

src/features/applications/mappers/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@ export const asApplication = (application: ApplicationResult, metadata: Applicat
3131
: undefined,
3232
approvalProgram: application.params['approval-program'],
3333
clearStateProgram: application.params['clear-state-program'],
34-
globalState: asGlobalStateValue(application),
34+
globalState: asGlobalStateValue(application.params['global-state']),
3535
json: asJson(application),
3636
}
3737
}
3838

39-
export const asGlobalStateValue = (application: ApplicationResult): Map<string, ApplicationGlobalStateValue> => {
40-
const arr = application.params['global-state']
41-
.map(({ key, value }) => {
42-
return [getKey(key), getGlobalStateValue(value)] as const
43-
})
44-
.sort((a, b) => a[0].localeCompare(b[0]))
45-
return new Map(arr)
39+
export const asGlobalStateValue = (globalState: ApplicationResult['params']['global-state']): Application['globalState'] => {
40+
if (!globalState) {
41+
return
42+
}
43+
44+
return new Map(
45+
globalState
46+
.map(({ key, value }) => {
47+
return [getKey(key), getGlobalStateValue(value)] as const
48+
})
49+
.sort((a, b) => a[0].localeCompare(b[0]))
50+
)
4651
}
4752

4853
const getKey = (key: string): string => {

src/features/applications/models/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type Application = {
1313
localStateSchema?: ApplicationStateSchema
1414
approvalProgram: string
1515
clearStateProgram: string
16-
globalState: Map<string, ApplicationGlobalStateValue>
16+
globalState?: Map<string, ApplicationGlobalStateValue>
1717
json: string
1818
}
1919

0 commit comments

Comments
 (0)