Skip to content

Commit ab0d044

Browse files
committed
do not discard decimals of bitcoin virtual tx size
1 parent c59109c commit ab0d044

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

apps/extension/src/hooks/bitcoin/use-tx-configs-query-string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const useBitcoinTxConfigsQueryString = (configs: {
3939

4040
const initialTxSize = searchParams.get("initialTxSize");
4141
if (initialTxSize) {
42-
configs.txSizeConfig.setValue(Number.parseInt(initialTxSize));
42+
configs.txSizeConfig.setValue(Number.parseFloat(initialTxSize));
4343
}
4444

4545
const initialFeeRateType = searchParams.get("initialFeeRateType");

packages/hooks-bitcoin/src/tx/fee.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ export class FeeConfig extends TxChainSetter implements IFeeConfig {
8888
return undefined;
8989
}
9090

91-
return new CoinPretty(
92-
this.amountConfig.currency,
91+
if (this.txSizeConfig.txSize <= 0) {
92+
return new CoinPretty(this.amountConfig.currency, new Dec(0));
93+
}
94+
95+
const feeDec = new Dec(
9396
this.txSizeConfig.txSize * this.feeRateConfig.feeRate + this.remainder
94-
);
97+
).roundUpDec();
98+
99+
return new CoinPretty(this.amountConfig.currency, feeDec);
95100
}
96101

97102
return new CoinPretty(this.amountConfig.currency, this._value);

packages/hooks-bitcoin/src/tx/psbt-simulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class PsbtSimulatorState {
8080
@action
8181
setInitialTxSize(value: number | string) {
8282
if (typeof value === "string") {
83-
value = parseInt(value);
83+
value = Number.parseFloat(value);
8484
}
8585

8686
this._initialTxSize = value;

packages/hooks-bitcoin/src/tx/tx-size.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class TxSizeConfig extends TxChainSetter implements ITxSizeConfig {
4848
return 0;
4949
}
5050

51-
const num = Number.parseInt(this._value);
51+
const num = Number.parseFloat(this._value);
5252
if (Number.isNaN(num)) {
5353
if (this._disallowZeroTxSize) {
5454
return undefined;
@@ -67,7 +67,7 @@ export class TxSizeConfig extends TxChainSetter implements ITxSizeConfig {
6767
};
6868
}
6969

70-
const num = Number.parseInt(this._value);
70+
const num = Number.parseFloat(this._value);
7171
if (Number.isNaN(num)) {
7272
return {
7373
error: new Error("Tx size is not valid number"),

0 commit comments

Comments
 (0)