Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-agarwal-coinbase committed Nov 21, 2024
1 parent c8bb9cc commit a42eb0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Fixed
- Fixed a bug where the asset ID was not being set correctly for Gwei and Wei

## [0.10.0] - 2024-10-31

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/coinbase/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Asset {
throw new ArgumentError(`Invalid asset ID: ${assetId}`);
}
}
return new Asset(model.network_id, model.asset_id, model.contract_address!, decimals);
return new Asset(model.network_id, assetId ?? model.asset_id, model.contract_address!, decimals);

Check failure on line 67 in src/coinbase/asset.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `model.network_id,·assetId·??·model.asset_id,·model.contract_address!,·decimals` with `⏎······model.network_id,⏎······assetId·??·model.asset_id,⏎······model.contract_address!,⏎······decimals,⏎····`
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/tests/asset_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ describe("Asset", () => {
});

describe("when the asset_id is gwei", () => {
it("should set the decimals to 9", () => {
it("should set the decimals to 9 and assetId to gwei", () => {
const model = {
asset_id: "eth",
network_id: Coinbase.networks.BaseSepolia,
contract_address: "0x",
decimals: 18,
};
expect(Asset.fromModel(model, Coinbase.assets.Gwei).decimals).toEqual(GWEI_DECIMALS);
const asset = Asset.fromModel(model, Coinbase.assets.Gwei);
expect(asset.decimals).toEqual(GWEI_DECIMALS);
expect(asset.getAssetId()).toEqual("gwei");
});
});
describe("when the asset_id is wei", () => {
it("should set the decimals to 0", () => {
it("should set the decimals to 0 and assetId to wei", () => {
const model = {
asset_id: "eth",
network_id: Coinbase.networks.BaseSepolia,
contract_address: "0x",
decimals: 18,
};
expect(Asset.fromModel(model, Coinbase.assets.Wei).decimals).toEqual(0);
const asset = Asset.fromModel(model, Coinbase.assets.Wei);
expect(asset.decimals).toEqual(0);
expect(asset.getAssetId()).toEqual("wei");
});
});
});
Expand Down

0 comments on commit a42eb0d

Please sign in to comment.