Skip to content

Commit

Permalink
Fix ts issues around tx method mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Nov 4, 2024
1 parent 3bfccaa commit 9df3673
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/vendors/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,15 @@ export function parseDelegations(delegations: NexusDelegation[]): Delegation[] {
})
}

export const transactionMethodMap: {
function getTransactionType(method: string | undefined): TransactionType {
const type = transactionMethodMap[method as keyof typeof transactionMethodMap]
// Not handled mappings are rendered as unrecognizedTransaction
return type ?? (method as TransactionType)
}

export const transactionMethodMap: Partial<{
[k in ConsensusTxMethod]: TransactionType
} = {
}> = {
[ConsensusTxMethod.StakingTransfer]: TransactionType.StakingTransfer,
[ConsensusTxMethod.StakingAddEscrow]: TransactionType.StakingAddEscrow,
[ConsensusTxMethod.StakingReclaimEscrow]: TransactionType.StakingReclaimEscrow,
Expand Down Expand Up @@ -256,7 +262,7 @@ function parseTransactionsList(list: (NexusTransaction | ExtendedRuntimeTransact
status: t.success ? TransactionStatus.Successful : TransactionStatus.Failed,
timestamp: transactionDate.getTime(),
to: (t.body as { to?: string }).to ?? undefined,
type: transactionMethodMap[t.method] ?? t.method,
type: getTransactionType(t.method),
runtimeName: t.runtimeName,
runtimeId: t.runtimeId,
round: t.round,
Expand All @@ -281,7 +287,7 @@ function parseTransactionsList(list: (NexusTransaction | ExtendedRuntimeTransact
(t.body as { beneficiary?: StringifiedBigInt })?.beneficiary ||
(t.body as { account?: StringifiedBigInt })?.account ||
undefined,
type: transactionMethodMap[t.method] ?? t.method,
type: getTransactionType(t.method),
runtimeName: undefined,
runtimeId: undefined,
round: undefined,
Expand Down

0 comments on commit 9df3673

Please sign in to comment.