Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed Oct 16, 2020
2 parents 3bb2e3f + 9a1d856 commit 0fe0ee9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/ui/popup/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ChainsKeeper } from "../../../../background/chains/keeper";
import { useConfirm } from "../../../components/confirm";
import { useIntl } from "react-intl";
import { TokensView } from "./token";
import { Int } from "@chainapsis/cosmosjs/common/int";

export const MainPage: FunctionComponent = observer(() => {
const history = useHistory();
Expand Down Expand Up @@ -60,7 +61,10 @@ export const MainPage: FunctionComponent = observer(() => {
const stakeCurrency = chainStore.chainInfo.stakeCurrency;

const tokens = accountStore.assets.filter(asset => {
return asset.denom !== stakeCurrency.coinMinimalDenom;
return (
asset.denom !== stakeCurrency.coinMinimalDenom &&
asset.amount.gt(new Int(0))
);
});

const hasTokens = tokens.length > 0;
Expand Down
35 changes: 27 additions & 8 deletions src/ui/popup/stores/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ export class AccountStore {
? this.chainInfo.features.includes("stargate")
: false;

const balances: Coin[] = [];

if (!isStargate) {
const account = await task(
queryAccount(
Expand All @@ -259,7 +261,7 @@ export class AccountStore {
)
);

this.pushAssets(account.getCoins());
balances.push(...account.getCoins());
} else {
// In stargate, the assets doens't exist on account itself.
// It exists on the bank module. So, we should to fetch the balances from bank module.
Expand All @@ -284,16 +286,27 @@ export class AccountStore {
throw new Error(result.statusText);
}

const balances: Coin[] = [];
for (const asset of result.data.result) {
const balance = new Coin(asset.denom, asset.amount);
balances.push(balance);
}

this.pushAssets(balances);
}

this.lastAssetFetchingError = undefined;
if (balances.length > 0) {
this.pushAssets(balances);
} else {
// If account doesn't exist
// Remove all the native coin/tokens.
const assets = this.assets.slice();
for (const asset of assets) {
// Remember that the coin's actual denom should start with "type:contractAddress:" if it is for the token based on contract.
const split = asset.denom.split(/(\w+):(\w+):(\w+)/).filter(Boolean);
if (split.length !== 3) {
this.removeAsset(asset.denom);
}
}
}
// Save the assets to storage.
await task(
this.saveAssetsToStorage(
Expand Down Expand Up @@ -372,10 +385,15 @@ export class AccountStore {
this.lastAssetFetchingError = e;
} else {
// If account doesn't exist
for (const currency of this.chainInfo.currencies) {
// Remove all the native coin/tokens.
if (!("type" in currency)) {
this.removeAsset(currency.coinMinimalDenom);
// Remove all the native coin/tokens.
const assets = this.assets.slice();
for (const asset of assets) {
// Remember that the coin's actual denom should start with "type:contractAddress:" if it is for the token based on contract.
const split = asset.denom
.split(/(\w+):(\w+):(\w+)/)
.filter(Boolean);
if (split.length !== 3) {
this.removeAsset(asset.denom);
}
}
this.stakedAsset = undefined;
Expand Down Expand Up @@ -458,6 +476,7 @@ export class AccountStore {
Buffer.from(result.data.result.smart, "base64").toString()
);
const balance = obj.balance;
// Balance can be 0
const asset = new Coin(currency.coinMinimalDenom, new Int(balance));

this.pushAsset(asset);
Expand Down

0 comments on commit 0fe0ee9

Please sign in to comment.