From 669ed92e9b1ebba8b23201145d6fec26bbbb023d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Korba=C5=A1?= Date: Fri, 11 Oct 2024 22:40:00 +0200 Subject: [PATCH] js-v1: fix handling of `null` stake when parsing account info (#8) --- web3js-1.0/src/rpc.ts | 8 ++++++-- web3js-1.0/src/stake.ts | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/web3js-1.0/src/rpc.ts b/web3js-1.0/src/rpc.ts index 0824759..e62e9ac 100644 --- a/web3js-1.0/src/rpc.ts +++ b/web3js-1.0/src/rpc.ts @@ -33,12 +33,16 @@ export async function getStakeActivation( })(), ]); - const { effective, activating, deactivating } = + const { effective, activating, deactivating } = stakeAccount.stake ? getStakeActivatingAndDeactivating( stakeAccount.stake.delegation, BigInt(epochInfo.epoch), stakeHistory - ); + ) : { + effective: BigInt(0), + activating: BigInt(0), + deactivating: BigInt(0), + }; let status; if (deactivating > 0) { diff --git a/web3js-1.0/src/stake.ts b/web3js-1.0/src/stake.ts index 54cbe7c..f620489 100644 --- a/web3js-1.0/src/stake.ts +++ b/web3js-1.0/src/stake.ts @@ -31,7 +31,7 @@ export type StakeAccount = { stake: { delegation: Delegation, creditsObserved: bigint - } + } | null } export const getStakeHistory = function (parsedData: RpcResponseAndContext | null>): StakeHistoryEntry[] { @@ -77,7 +77,7 @@ export const getStakeAccount = function (parsedData: RpcResponseAndContext