Skip to content

Commit

Permalink
fix getBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed Jun 3, 2024
1 parent e599637 commit 7a351cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/coinbase/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,21 @@ export class Address {
* @returns {Decimal} The balance of the asset.
*/
async getBalance(assetId: string): Promise<Decimal> {
const normalizedAssetId = ((): string => {
switch (assetId) {
case Coinbase.assets.Gwei:
return Coinbase.assets.Eth;
case Coinbase.assets.Wei:
return Coinbase.assets.Eth;
default:
return assetId;
}
})();

const response = await Coinbase.apiClients.address!.getAddressBalance(
this.model.wallet_id,
this.model.address_id,
assetId,
normalizedAssetId,
);

if (!response.data) {
Expand Down
4 changes: 2 additions & 2 deletions src/coinbase/tests/address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("Address", () => {
expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledWith(
address.getWalletId(),
address.getId(),
assetId,
Coinbase.assets.Eth,
);
expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledTimes(1);
});
Expand All @@ -114,7 +114,7 @@ describe("Address", () => {
expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledWith(
address.getWalletId(),
address.getId(),
assetId,
Coinbase.assets.Eth,
);
expect(Coinbase.apiClients.address!.getAddressBalance).toHaveBeenCalledTimes(1);
});
Expand Down

0 comments on commit 7a351cc

Please sign in to comment.