Skip to content

Commit

Permalink
frontend/account: fix CanSend and Buy call to action
Browse files Browse the repository at this point in the history
Since recently, BTC amounts are returned with trailing zeroes, so the
`'0'` string comparison stopped working to check if there is a
balance.

Similar to `hasAvailable`, the backend should deliver the information.
  • Loading branch information
benma committed Oct 26, 2022
1 parent 55e2b7e commit 0fe0d16
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions backend/coins/btc/handlers/handlers.go
Expand Up @@ -326,9 +326,10 @@ func (handlers *Handlers) getAccountBalance(_ *http.Request) (interface{}, error
return nil, err
}
return map[string]interface{}{
"available": handlers.formatAmountAsJSON(balance.Available(), false),
"incoming": handlers.formatAmountAsJSON(balance.Incoming(), false),
"hasIncoming": balance.Incoming().BigInt().Sign() > 0,
"hasAvailable": balance.Available().BigInt().Sign() > 0,
"available": handlers.formatAmountAsJSON(balance.Available(), false),
"hasIncoming": balance.Incoming().BigInt().Sign() > 0,
"incoming": handlers.formatAmountAsJSON(balance.Incoming(), false),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions frontends/web/src/api/account.ts
Expand Up @@ -142,6 +142,7 @@ export interface IAmount {
}

export interface IBalance {
hasAvailable: boolean;
available: IAmount;
hasIncoming: boolean;
incoming: IAmount;
Expand Down
4 changes: 2 additions & 2 deletions frontends/web/src/routes/account/account.tsx
Expand Up @@ -170,7 +170,7 @@ export function Account({
return null;
}

const canSend = balance && balance.available.amount !== '0';
const canSend = balance && balance.hasAvailable;

const initializingSpinnerText =
(syncedAddressesCount !== undefined && syncedAddressesCount > 1) ? (
Expand All @@ -191,7 +191,7 @@ export function Account({

const showBuyButton = moonpayBuySupported
&& balance
&& balance.available.amount === '0'
&& !balance.hasAvailable
&& !balance.hasIncoming
&& transactions && transactions.length === 0;

Expand Down
2 changes: 1 addition & 1 deletion frontends/web/src/routes/account/info/buyCTA.tsx
Expand Up @@ -34,7 +34,7 @@ export const AddBuyOnEmptyBalances: FunctionComponent<{balances?: Balances}> = (
return null;
}
const balanceList = Object.entries(balances);
if (balanceList.some(entry => entry[1].available.amount !== '0')) {
if (balanceList.some(entry => entry[1].hasAvailable)) {
return null;
}
if (balanceList.map(entry => entry[1].available.unit).every(isBitcoinCoin)) {
Expand Down

0 comments on commit 0fe0d16

Please sign in to comment.