Skip to content

Commit

Permalink
chore: remove unnecessary warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Jul 25, 2024
1 parent b26795b commit 82c229b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
10 changes: 0 additions & 10 deletions packages/asset/src/AssetAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export class AssetAmount<T extends IAssetAmountMetadata = IAssetAmountMetadata>
static readonly DEFAULT_FUNGIBLE_TOKEN_DECIMALS = 0;
static INVALID_METADATA =
"Cannot perform exchange calculation on an AssetAmount with no metadata.";
static INVALID_DECIMAL_WARNING =
"Cannot perform addition or subtraction on AssetAmounts with different decimals.";

readonly metadata: T;
readonly id: string;
Expand Down Expand Up @@ -94,19 +92,11 @@ export class AssetAmount<T extends IAssetAmountMetadata = IAssetAmountMetadata>
}

add = (rhs: AssetAmount): AssetAmount<T> => {
if (this.decimals !== rhs.decimals) {
// eslint-disable-next-line no-console
console.warn(AssetAmount.INVALID_DECIMAL_WARNING);
}
return this.withAmount(this.amount + rhs.amount);
};
plus = this.add;

subtract = (rhs: AssetAmount): AssetAmount<T> => {
if (this.decimals !== rhs.decimals) {
// eslint-disable-next-line no-console
console.warn(AssetAmount.INVALID_DECIMAL_WARNING);
}
return this.withAmount(this.amount - rhs.amount);
};
minus = this.subtract;
Expand Down
16 changes: 1 addition & 15 deletions packages/asset/src/__tests__/AssetAmount.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, it, expect, spyOn } from "bun:test";
import { beforeEach, describe, it, expect } from "bun:test";
import { AssetAmount, IAssetAmountMetadata } from "../AssetAmount.js";
import { AssetRatio } from "../AssetRatio.js";

Expand Down Expand Up @@ -101,13 +101,6 @@ describe("AssetAmount", () => {
new AssetAmount(1000000, sixDecimals).add(new AssetAmount(5000000, 6))
.amount,
).toEqual(6000000n);

const spyConsole = spyOn(global.console, "warn");
new AssetAmount(1000000, 0).add(new AssetAmount(5000000, 6));
expect(spyConsole).toHaveBeenCalledWith(
AssetAmount.INVALID_DECIMAL_WARNING,
);
spyConsole.mockReset();
});

it("should subtract values correctly", () => {
Expand All @@ -130,13 +123,6 @@ describe("AssetAmount", () => {
new AssetAmount(5000000, 6),
).amount,
).toEqual(5000000n);

const spyConsole = spyOn(global.console, "warn");
new AssetAmount(10000000, 0).subtract(new AssetAmount(5000000, 6));
expect(spyConsole).toHaveBeenCalledWith(
AssetAmount.INVALID_DECIMAL_WARNING,
);
spyConsole.mockReset();
});
});

Expand Down

0 comments on commit 82c229b

Please sign in to comment.