From 14ea6d50fe2b3d7fb57172e8d7be561e37f1f972 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Sat, 6 Apr 2024 00:59:07 +0200 Subject: [PATCH 1/2] Refactor isAccountEmpty --- src/oasis-nexus/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oasis-nexus/api.ts b/src/oasis-nexus/api.ts index c5e616564..1235413f4 100644 --- a/src/oasis-nexus/api.ts +++ b/src/oasis-nexus/api.ts @@ -113,9 +113,9 @@ declare module './generated/api' { export const isAccountEmpty = (account: RuntimeAccount) => { const { balances, evm_balances, stats } = account const { total_received, total_sent, num_txns } = stats - const result = - !balances?.length && !evm_balances?.length && total_received === '0' && total_sent === '0' && !num_txns - return result + const hasNoBalances = !balances?.length && !evm_balances?.length + const hasNoTransactions = total_received === '0' && total_sent === '0' && num_txns === 0 + return hasNoBalances && hasNoTransactions } export const isAccountNonEmpty = (account: RuntimeAccount) => !isAccountEmpty(account) From cc3f9ef6a9878e3f43709aa19b2c3b747aa7c8a7 Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Wed, 10 Apr 2024 04:02:20 +0200 Subject: [PATCH 2/2] Fix isAccountEmpty to handle accounts with balances = 0 --- .changelog/1372.bugfix.md | 1 + src/oasis-nexus/api.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .changelog/1372.bugfix.md diff --git a/.changelog/1372.bugfix.md b/.changelog/1372.bugfix.md new file mode 100644 index 000000000..2b4ca90e8 --- /dev/null +++ b/.changelog/1372.bugfix.md @@ -0,0 +1 @@ +Fix isAccountEmpty to handle accounts with balances = 0 diff --git a/src/oasis-nexus/api.ts b/src/oasis-nexus/api.ts index 1235413f4..a6e7ed5f1 100644 --- a/src/oasis-nexus/api.ts +++ b/src/oasis-nexus/api.ts @@ -113,7 +113,7 @@ declare module './generated/api' { export const isAccountEmpty = (account: RuntimeAccount) => { const { balances, evm_balances, stats } = account const { total_received, total_sent, num_txns } = stats - const hasNoBalances = !balances?.length && !evm_balances?.length + const hasNoBalances = [...balances, ...evm_balances].every(b => b.balance === '0' || b.balance === '0.0') const hasNoTransactions = total_received === '0' && total_sent === '0' && num_txns === 0 return hasNoBalances && hasNoTransactions }