Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #294 from MortalKastor/hide-empty-token-accounts
Browse files Browse the repository at this point in the history
Ability to hide token accounts with balance 0
  • Loading branch information
gre authored Jul 3, 2019
2 parents b96e71f + 39c5bb7 commit ac3acec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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,
Expand All @@ -57,6 +58,7 @@ const defaults: $ObjMap<EnvParsers, ExtractEnvValue> = {
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",
Expand Down
8 changes: 7 additions & 1 deletion src/families/ethereum/libcore-buildTokenAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
findTokenByAddress,
listTokensForCryptoCurrency
} from "../../currencies";
import { getEnv } from "../../env";

async function buildERC20TokenAccount({
parentAccountId,
Expand All @@ -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;

Expand Down Expand Up @@ -85,7 +91,7 @@ async function ethereumBuildTokenAccounts({
token,
coreTokenAccount: coreTA
});
tokenAccounts.push(tokenAccount);
if (tokenAccount) tokenAccounts.push(tokenAccount);
}
}

Expand Down

0 comments on commit ac3acec

Please sign in to comment.