Skip to content

Commit

Permalink
Handle missing props for paratime response object
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Jul 15, 2022
1 parent 9b125ff commit 350ed56
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ Object {

exports[`oasisscan parse transaction list 1`] = `
Array [
Object {
"amount": 200000000000,
"fee": undefined,
"from": "oasis1qqnk4au603zs94k0d0n7c0hkx8t4p6r87s60axru",
"hash": "25b84ca4582f6e3140c384ad60b98415d2c3079d1fc5f2221e45da7b13c70817",
"level": undefined,
"round": 997775,
"runtimeId": "000000000000000000000000000000000000000000000000e2eaa99fc008f87f",
"runtimeName": "Emerald",
"status": true,
"timestamp": 1649604086,
"to": "oasis1qzgc7dvlls36q47z5y6dvu6ylaa78rkrduqtxgdr",
"type": "consensus.Deposit",
},
Object {
"amount": 116900000000,
"fee": 2000,
Expand Down
21 changes: 21 additions & 0 deletions src/vendors/__tests__/oasisscan.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TransactionMethod } from 'app/state/transaction/types'
import { OperationsRowMethodEnum } from 'vendors/oasisscan/index'
import {
parseValidatorsList,
Expand Down Expand Up @@ -137,6 +138,26 @@ describe('oasisscan', () => {
test('parse transaction list', () => {
expect(
parseTransactionsList([
// Emerald ParaTime Object
{
add: undefined,
amount: '200',
fee: undefined,
from: 'oasis1qqnk4au603zs94k0d0n7c0hkx8t4p6r87s60axru',
height: undefined,
method: 'consensus.Deposit' as TransactionMethod,
round: 997775,
runtimeId: '000000000000000000000000000000000000000000000000e2eaa99fc008f87f',
runtimeName: 'Emerald',
shares: undefined,
status: true,
time: undefined,
timestamp: 1649604086,
to: 'oasis1qzgc7dvlls36q47z5y6dvu6ylaa78rkrduqtxgdr',
txHash: '25b84ca4582f6e3140c384ad60b98415d2c3079d1fc5f2221e45da7b13c70817',
type: 'consensus.Deposit',
},

// https://api.oasisscan.com/mainnet/chain/transactions?size=200&runtime=false&method=staking.Transfer&address=oasis1qz086axf5hreqpehv5hlgmtw7sfem79gz55v68wp
{
txHash: 'b831c4b2aa3188058717250cba279795d907e581bb4d7d40d9dc358d37a56254',
Expand Down
8 changes: 6 additions & 2 deletions src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,19 @@ export const transactionMethodMap: {
[ParaTimeCtxRowMethodEnum.ConsensusAccount]: TransactionType.ConsensusAccount,
}

type TransactionsListRow = Omit<OperationsRow, 'method'> & {
type TransactionsListRow = Omit<OperationsRow, 'add' | 'fee' | 'height' | 'method' | 'time'> & {
method: TransactionMethod
add: boolean | undefined
fee: string | undefined
height: number | undefined
time: number | undefined
}

export function parseTransactionsList(transactionsList: TransactionsListRow[]): Transaction[] {
return transactionsList.map(t => {
const parsed: Transaction = {
amount: t.amount == null ? undefined : parseStringValueToInt(t.amount),
fee: parseStringValueToInt(t.fee),
fee: t.fee ? parseStringValueToInt(t.fee) : undefined,
from: t.from,
hash: t.txHash,
level: t.height,
Expand Down

0 comments on commit 350ed56

Please sign in to comment.