Skip to content

Commit

Permalink
fix: set existing freezes/locks to 0 when they fail to decode
Browse files Browse the repository at this point in the history
  • Loading branch information
alecdwm committed Jul 4, 2024
1 parent c622e38 commit 37734d9
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions packages/balances/src/modules/SubstrateNativeModule/QueryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,14 @@ async function buildQueries(
change,
`Failed to decode lock on chain ${chainId}`
)
if (!decoded) return balanceJson

locksQueryLocks = decoded.map?.((lock) => ({
type: "locked",
source: "substrate-native-locks",
label: getLockedType(lock?.id?.asText?.()),
amount: (lock?.amount ?? 0n).toString(),
}))
locksQueryLocks =
decoded?.map?.((lock) => ({
type: "locked",
source: "substrate-native-locks",
label: getLockedType(lock?.id?.asText?.()),
amount: (lock?.amount ?? 0n).toString(),
})) ?? []

// locked values should be replaced entirely, not merged or appended
const nonLockValues = balanceJson.values.filter(
Expand Down Expand Up @@ -437,14 +437,13 @@ async function buildQueries(
`Failed to decode freeze on chain ${chainId}`
)

if (!decoded) return balanceJson

freezesQueryLocks = decoded?.map?.((lock) => ({
type: "locked",
source: "substrate-native-freezes",
label: getLockedType(lock?.id?.type?.toLowerCase?.()),
amount: lock?.amount?.toString?.() ?? "0",
}))
freezesQueryLocks =
decoded?.map?.((lock) => ({
type: "locked",
source: "substrate-native-freezes",
label: getLockedType(lock?.id?.type?.toLowerCase?.()),
amount: lock?.amount?.toString?.() ?? "0",
})) ?? []

// freezes values should be replaced entirely, not merged or appended
const nonFreezesValues = balanceJson.values.filter(
Expand Down

0 comments on commit 37734d9

Please sign in to comment.