From 39c5bb75e3ebe01c565b1b76bb6e23d2996f5419 Mon Sep 17 00:00:00 2001 From: Thibaut Boustany Date: Wed, 3 Jul 2019 17:19:08 +0200 Subject: [PATCH] Env variable for hiding empty token accounts --- src/env.js | 2 ++ src/families/ethereum/libcore-buildTokenAccounts.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/env.js b/src/env.js index 3d647e29f3..2e7df20c5a 100644 --- a/src/env.js +++ b/src/env.js @@ -33,6 +33,7 @@ const envParsers = { EXPERIMENTAL_USB: boolParser, EXPLORER: stringParser, FORCE_PROVIDER: intParser, + HIDE_EMPTY_TOKEN_ACCOUNTS: boolParser, LEDGER_REST_API_BASE: stringParser, LIBCORE_PASSWORD: stringParser, MANAGER_API_BASE: stringParser, @@ -59,6 +60,7 @@ const defaults: $ObjMap = { EXPERIMENTAL_ROI_CALCULATION: false, EXPLORER: "https://explorers.api.live.ledger.com", FORCE_PROVIDER: 1, + HIDE_EMPTY_TOKEN_ACCOUNTS: false, LEDGER_REST_API_BASE: "https://explorers.api.live.ledger.com", LIBCORE_PASSWORD: "", MANAGER_API_BASE: "https://manager.api.live.ledger.com/api", diff --git a/src/families/ethereum/libcore-buildTokenAccounts.js b/src/families/ethereum/libcore-buildTokenAccounts.js index ed1b8cb78d..24aad87c44 100644 --- a/src/families/ethereum/libcore-buildTokenAccounts.js +++ b/src/families/ethereum/libcore-buildTokenAccounts.js @@ -10,6 +10,7 @@ import { findTokenByAddress, listTokensForCryptoCurrency } from "../../currencies"; +import { getEnv } from "../../env"; async function buildERC20TokenAccount({ parentAccountId, @@ -20,6 +21,11 @@ async function buildERC20TokenAccount({ const balance = await libcoreBigIntToBigNumber( await coreTokenAccount.getBalance() ); + + if (getEnv("HIDE_EMPTY_TOKEN_ACCOUNTS") && balance.isZero()) { + return null; + } + const coreOperations = await coreTokenAccount.getOperations(); const id = parentAccountId + "+" + token.contractAddress; @@ -85,7 +91,7 @@ async function ethereumBuildTokenAccounts({ token, coreTokenAccount: coreTA }); - tokenAccounts.push(tokenAccount); + if (tokenAccount) tokenAccounts.push(tokenAccount); } }