Skip to content

Commit 285162e

Browse files
committed
fix: to send values as string big int to the api
1 parent 8c02369 commit 285162e

File tree

11 files changed

+126
-123
lines changed

11 files changed

+126
-123
lines changed

src/common/components/status/StatusSummary.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ import {
6868
mdiBitcoin, mdiArrowRight, mdiArrowLeft, mdiOpenInNew, mdiContentCopy,
6969
} from '@mdi/js';
7070
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
71-
import {
72-
TxStatus, TxStatusType,
73-
SatoshiBig,
74-
WeiBig,
75-
} from '@/common/types';
71+
import { TxStatus, TxStatusType } from '@/common/types';
7672
import {
7773
getBtcAddressExplorerUrl,
7874
getBtcTxExplorerUrl,
@@ -111,8 +107,7 @@ export default defineComponent({
111107
112108
const btcSide = computed(() => {
113109
if (props.type === TxStatusType.PEGOUT || props.type === TxStatusType.FLYOVER_PEGOUT) {
114-
const fee = props.details.fee === BigInt(0)
115-
? props.details.estimatedFee : props.details.fee;
110+
const fee = props.details.fee === 0 ? props.details.estimatedFee : props.details.fee;
116111
return [
117112
{
118113
title: 'You receive',
@@ -147,9 +142,7 @@ export default defineComponent({
147142
{
148143
title: props.details && props.type === TxStatusType.FLYOVER_PEGIN
149144
? 'Fee (includes provider and network fees)' : 'Fee',
150-
value: props.type === TxStatusType.FLYOVER_PEGIN
151-
? new SatoshiBig(props.details.fee, 'satoshi').toBTCString()
152-
: props.details.fee,
145+
value: props.details.fee,
153146
ticker: true,
154147
},
155148
{
@@ -167,7 +160,7 @@ export default defineComponent({
167160
168161
const rskSide = computed(() => {
169162
if (props.type === TxStatusType.PEGOUT || props.type === TxStatusType.FLYOVER_PEGOUT) {
170-
const gasFee = props.details.gas?.gt(0) ? props.details.gas.toRBTCTrimmedString() : '-';
163+
const gasFee = props.details.gas ? props.details.gas : '-';
171164
return [
172165
{
173166
title: 'You send',
@@ -178,7 +171,7 @@ export default defineComponent({
178171
title: props.type === TxStatusType.FLYOVER_PEGOUT
179172
? 'Fee (includes provider and network fees)' : 'Fee',
180173
value: status.value.type === TxStatusType.FLYOVER_PEGOUT
181-
? new WeiBig(props.details.fee, 'wei').toRBTCTrimmedString()
174+
? props.details.fee
182175
: gasFee,
183176
ticker: true,
184177
},

src/common/components/status/TxPegin.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
} from '@/common/types';
3737
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
3838
import * as constants from '@/common/store/constants';
39-
import { getTime, setStatusMessage } from '@/common/utils';
39+
import { getTime, setStatusMessage, toSatoshiBigIntString } from '@/common/utils';
4040
import {
4141
useAction, useGetter, useStateAttribute,
4242
} from '@/common/store/helper';
@@ -60,9 +60,9 @@ export default defineComponent({
6060
setup(props, context) {
6161
const currentFee = ref(new SatoshiBig('0', 'btc'));
6262
const currentRefundAddress = ref('');
63-
const btcConfirmationsRequired = ref(0);
63+
const btcConfirmationsRequired = ref('0');
6464
const btcConfirmationsPercentage = ref(0);
65-
const btcConfirmations = ref(0);
65+
const btcConfirmations = ref('0');
6666
const rskConfirmationsPercentage = ref(0);
6767
const leftBtcTime = ref('');
6868
@@ -137,11 +137,13 @@ export default defineComponent({
137137
138138
const flyoverPeginSummary = computed((): NormalizedSummary => {
139139
const status = txDetails.value as FlyoverStatusModel;
140-
const total = new SatoshiBig(status.amount, 'satoshi')
141-
.plus(new SatoshiBig(status.fee, 'satoshi'));
140+
const amount = toSatoshiBigIntString(status.amount);
141+
const fee = toSatoshiBigIntString(status.fee);
142+
const total = new SatoshiBig(amount, 'satoshi')
143+
.plus(new SatoshiBig(fee, 'satoshi'));
142144
return {
143-
amountFromString: new SatoshiBig(status.amount, 'satoshi').toBTCTrimmedString(),
144-
amountReceivedString: new SatoshiBig(status.amount, 'satoshi').toBTCTrimmedString(),
145+
amountFromString: status.amount,
146+
amountReceivedString: status.amount,
145147
total: total.toBTCTrimmedString(),
146148
fee: status.fee,
147149
recipientAddress: status.recipientAddress,
@@ -158,16 +160,22 @@ export default defineComponent({
158160
const showConfirmations = computed(() => !props.isFlyover
159161
&& txDetails.value.status === PegStatus.WAITING_CONFIRMATIONS);
160162
163+
const btcConfirmationsRequiredNumber = computed(() => Number(btcConfirmationsRequired.value));
164+
165+
const btcConfirmationsNumber = computed(() => Number(btcConfirmations.value));
166+
161167
function refreshPercentage() {
162168
if ('btc' in txDetails.value) {
163169
const { btc } = txDetails.value;
164-
btcConfirmationsRequired.value = btc.requiredConfirmation;
165-
btcConfirmations.value = btc.confirmations ?? 0;
170+
btcConfirmationsRequired.value = btc.requiredConfirmation.toString();
171+
btcConfirmations.value = btc.confirmations.toString() ?? '0';
166172
btcConfirmations.value = btcConfirmations.value > btcConfirmationsRequired.value
167173
? btcConfirmationsRequired.value : btcConfirmations.value;
168-
leftBtcTime.value = getTime((btcConfirmationsRequired.value - btcConfirmations.value) * 10);
174+
leftBtcTime.value = getTime(
175+
(btcConfirmationsRequiredNumber.value - btcConfirmationsNumber.value) * 10,
176+
);
169177
btcConfirmationsPercentage.value = btcConfirmations.value <= btcConfirmationsRequired.value
170-
? (btcConfirmations.value * 100) / btcConfirmationsRequired.value : 100;
178+
? (btcConfirmationsNumber.value * 100) / btcConfirmationsRequiredNumber.value : 100;
171179
if (txDetails.value.status === constants.PegStatus.CONFIRMED) {
172180
rskConfirmationsPercentage.value = 100;
173181
} else {

src/common/components/status/TxPegout.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import StatusProgressBar from '@/common/components/status/StatusProgressBar.vue';
2525
import { useStateAttribute } from '@/common/store/helper';
2626
import StatusSummary from '@/common/components/status/StatusSummary.vue';
27+
import { bigNumberToSatoshiBigIntString, toWeiBigIntString } from '@/common/utils';
2728
2829
export default defineComponent({
2930
name: 'TxPegout',
@@ -61,32 +62,34 @@ export default defineComponent({
6162
6263
const txPegoutSummary = computed((): NormalizedSummary => {
6364
const status = txDetails.value as PegoutStatusDataModel;
64-
const valueRequested = new SatoshiBig(status.valueRequestedInSatoshis, 'satoshi').toBTCTrimmedString();
65-
const amountSent = new WeiBig(valueRequested, 'rbtc').plus(calculatedGasFee.value).toRBTCTrimmedString();
65+
const valueRequested = bigNumberToSatoshiBigIntString(status.valueRequestedInSatoshis);
66+
const amountSent = new WeiBig(valueRequested, 'rbtc')
67+
.plus(calculatedGasFee.value).toRBTCTrimmedString();
6668
const btcTxId = status.status === PegoutStatus.RELEASE_BTC ? status.btcTxId : '';
6769
return {
6870
amountFromString: amountSent,
6971
amountReceivedString: amountToBeReceived.value,
70-
gas: calculatedGasFee.value,
71-
fee: status.feeInSatoshisToBePaid ?? BigInt(0),
72+
gas: calculatedGasFee.value.toString(),
73+
fee: status.feeInSatoshisToBePaid ?? '0',
7274
recipientAddress: status.btcRecipientAddress,
7375
senderAddress: status.rskSenderAddress,
7476
txId: status.rskTxHash ? status.rskTxHash : props.txId,
75-
estimatedFee: pegOutEstimatedFee.value.toSatoshiBigIntUnsafe(),
77+
estimatedFee: pegOutEstimatedFee.value.toString(),
7678
status: status.status,
7779
btcTxId,
7880
};
7981
});
8082
8183
const flyoverPegoutSummary = computed((): NormalizedSummary => {
8284
const status = txDetails.value as FlyoverStatusModel;
83-
const amount = new WeiBig(status.amount, 'wei');
84-
const fee = new WeiBig(status.fee, 'wei');
85-
const total = amount.plus(fee);
85+
const amount = toWeiBigIntString(status.amount);
86+
const fee = toWeiBigIntString(status.fee);
87+
const total = new WeiBig(amount, 'wei')
88+
.plus(new WeiBig(fee, 'wei'));
8689
return {
8790
amountFromString: total.toRBTCTrimmedString(),
88-
amountReceivedString: amount.toRBTCTrimmedString(),
89-
fee: fee.toWeiBigIntUnsafe(),
91+
amountReceivedString: status.amount,
92+
fee: status.fee,
9093
recipientAddress: status.recipientAddress,
9194
senderAddress: status.senderAddress,
9295
txId: status.txHash,

src/common/services/ApiService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TxInfo,
1414
FlyoverCall,
1515
} from '@/common/types';
16-
import { areValidOutputs, isValidInput, toJsonWithoutBigInt } from '@/common/utils';
16+
import { areValidOutputs, isValidInput } from '@/common/utils';
1717
import { BridgeService } from '@/common/services/BridgeService';
1818
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
1919
import { ApiInformation } from '@/common/types/ApiInformation';
@@ -217,10 +217,9 @@ export default class ApiService {
217217
return new Promise<void>((resolve, reject) => {
218218
const { txHash, type } = txInfo;
219219
if (txHash == null || type == null) resolve();
220-
const txInfoWithoutBigInt = toJsonWithoutBigInt(txInfo);
221220
axios.post(
222221
`${ApiService.baseURL}/register`,
223-
txInfoWithoutBigInt,
222+
txInfo,
224223
{ headers: { 'Content-Type': 'application/json' } },
225224
)
226225
.then(() => resolve())

src/common/types/Common.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import SatoshiBig from '@/common/types/SatoshiBig';
22
import { Utxo } from '@/common/types/pegInTx';
33
import { PegoutStatus, TxStatusType } from '@/common/types/store';
44
import { FlyoverCallFunction, FlyoverCallResult, PegStatus } from '@/common/store/constants';
5-
import WeiBig from './WeiBig';
65

76
export interface Tx {
87
coin: string;
@@ -115,12 +114,12 @@ export interface PsbtExtendedInput {
115114
export interface NormalizedSummary {
116115
amountFromString: string;
117116
amountReceivedString: string;
118-
fee?: bigint;
119-
estimatedFee?: bigint;
117+
fee?: string;
118+
estimatedFee?: string;
120119
recipientAddress: string;
121120
senderAddress?: string;
122121
txId?: string;
123-
gas?: WeiBig;
122+
gas?: string;
124123
refundAddress?: string;
125124
selectedAccount?: string;
126125
federationAddress?: string;

src/common/types/TxInfo.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export interface BaseQuoteDbModel {
2-
agreementTimestamp: number;
3-
gasFeeOnWei: bigint;
4-
nonce: bigint;
5-
penaltyFeeOnWei: bigint;
2+
agreementTimestamp: string;
3+
gasFeeOnWei: string;
4+
nonce: string;
5+
penaltyFeeOnWei: string;
66
btcRefundAddress: string;
77
lbcAddress: string;
88
lpBtcAddress: string;
@@ -11,41 +11,41 @@ export interface BaseQuoteDbModel {
1111
}
1212

1313
export interface PeginQuoteDbModel extends BaseQuoteDbModel {
14-
callFeeOnSatoshi: bigint;
14+
callFeeOnSatoshi: string;
1515
callOnRegister: boolean;
16-
confirmations: number;
16+
confirmations: string;
1717
contractAddr: string;
1818
data: string;
1919
fedBTCAddr: string;
20-
gasLimit: bigint;
21-
lpCallTime: number;
22-
productFeeAmountOnSatoshi: bigint;
23-
timeForDepositInSeconds: number;
24-
valueOnSatoshi: bigint;
20+
gasLimit: string;
21+
lpCallTime: string;
22+
productFeeAmountOnSatoshi: string;
23+
timeForDepositInSeconds: string;
24+
valueOnSatoshi: string;
2525
}
2626

2727
export interface PegoutQuoteDbModel extends BaseQuoteDbModel {
28-
callFeeOnWei: bigint;
28+
callFeeOnWei: string;
2929
depositAddr: string;
30-
depositConfirmations: number;
31-
depositDateLimit: number;
32-
expireBlocks: number;
33-
expireDate: number;
34-
productFeeAmountOnWei: bigint;
35-
transferConfirmations: number;
36-
transferTime: number;
37-
valueOnWei: bigint;
30+
depositConfirmations: string;
31+
depositDateLimit: string;
32+
expireBlocks: string;
33+
expireDate: string;
34+
productFeeAmountOnWei: string;
35+
transferConfirmations: string;
36+
transferTime: string;
37+
valueOnWei: string;
3838
}
3939

4040
export interface TxInfo {
4141
txHash: string;
4242
type: string;
43-
value: bigint;
43+
value: string;
4444
wallet: string;
4545
addressType?: string;
46-
fee?: bigint;
47-
rskGas?: bigint;
48-
btcEstimatedFee?: bigint;
46+
fee?: string;
47+
rskGas?: string;
48+
btcEstimatedFee?: string;
4949
provider?: string;
5050
details?: Record<string, unknown>;
5151
quote?: PeginQuoteDbModel | PegoutQuoteDbModel;

src/common/types/store.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export interface BtcPeginStatus {
2222
txId: string;
2323
creationDate: Date;
2424
federationAddress: string;
25-
amountTransferred: bigint;
25+
amountTransferred: string;
2626
refundAddress: string;
27-
confirmations: number;
28-
requiredConfirmation: number;
29-
fees: bigint;
27+
confirmations: string;
28+
requiredConfirmation: string;
29+
fees: string;
3030
senderAddress: string;
3131
}
3232

@@ -38,7 +38,7 @@ export enum RskStatus {
3838

3939
export interface RskPeginStatus {
4040
recipientAddress: string;
41-
confirmations: number;
41+
confirmations: string;
4242
createOn: Date;
4343
status: RskStatus;
4444
}
@@ -65,13 +65,13 @@ export interface PegoutStatusDataModel {
6565
rskTxHash: string;
6666
rskSenderAddress: string;
6767
btcRecipientAddress: string;
68-
valueRequestedInSatoshis: bigint;
69-
valueInSatoshisToBeReceived: number;
70-
feeInSatoshisToBePaid?: bigint;
68+
valueRequestedInSatoshis: string;
69+
valueInSatoshisToBeReceived: string;
70+
feeInSatoshisToBePaid?: string;
7171
status: PegoutStatus;
7272
btcRawTransaction: string;
73-
fees: bigint;
74-
estimatedFee: SatoshiBig;
73+
fees: string;
74+
estimatedFee: string;
7575
btcTxId: string;
7676
reason?: RejectedPegoutReasons;
7777
}
@@ -80,9 +80,9 @@ export interface FlyoverStatusModel {
8080
txHash: string;
8181
type: string;
8282
date: Date;
83-
amount: bigint;
84-
fee: bigint;
85-
blockToBeFinished: number;
83+
amount: string;
84+
fee: string;
85+
blockToBeFinished: string;
8686
status: string;
8787
senderAddress: string;
8888
recipientAddress: string;

src/common/utils/ethers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { providers } from 'ethers';
1+
import { providers, utils } from 'ethers';
22
import { TransactionRequest, TransactionResponse } from '@/common/types';
33

44
export const sendTransaction = (
@@ -19,3 +19,12 @@ export const sendTransaction = (
1919
wait: (confirmations?: number) => provider.waitForTransaction(hash, confirmations),
2020
}));
2121
};
22+
23+
export const toSatoshiBigIntString = (userFormatedValue: string) : string => utils
24+
.parseUnits(userFormatedValue, 8).toString();
25+
26+
export const toWeiBigIntString = (userFormatedValue: string) : string => utils
27+
.parseUnits(userFormatedValue, 18).toString();
28+
29+
export const bigNumberToSatoshiBigIntString = (bigIntString: string) : string => utils
30+
.formatUnits(BigInt(bigIntString), 8);

src/common/utils/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,3 @@ export function appendRecaptcha(siteKey: string): void {
413413
captchaDiv.setAttribute('data-size', 'invisible');
414414
document.body.appendChild(captchaDiv);
415415
}
416-
417-
export function toJsonWithoutBigInt(data: object): string {
418-
if (data !== undefined) {
419-
return JSON.stringify(data, (_, v) => (typeof v === 'bigint' ? `${v}n` : v))
420-
.replace(/"(-?\d+)n"/g, (_, a) => a);
421-
}
422-
return '';
423-
}

0 commit comments

Comments
 (0)