Skip to content

Commit a087190

Browse files
committed
fix: to send values as string big int to the api
1 parent 2317111 commit a087190

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
@@ -35,7 +35,7 @@ import {
3535
} from '@/common/types';
3636
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
3737
import * as constants from '@/common/store/constants';
38-
import { getTime, setStatusMessage } from '@/common/utils';
38+
import { getTime, setStatusMessage, toSatoshiBigIntString } from '@/common/utils';
3939
import { useAction, useGetter, useStateAttribute } from '@/common/store/helper';
4040
import StatusProgressBar from '@/common/components/status/StatusProgressBar.vue';
4141
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
@@ -57,9 +57,9 @@ export default defineComponent({
5757
setup(props, context) {
5858
const currentFee = ref(new SatoshiBig('0', 'btc'));
5959
const currentRefundAddress = ref('');
60-
const btcConfirmationsRequired = ref(0);
60+
const btcConfirmationsRequired = ref('0');
6161
const btcConfirmationsPercentage = ref(0);
62-
const btcConfirmations = ref(0);
62+
const btcConfirmations = ref('0');
6363
const rskConfirmationsPercentage = ref(0);
6464
const leftBtcTime = ref('');
6565
@@ -133,11 +133,13 @@ export default defineComponent({
133133
134134
const flyoverPeginSummary = computed((): NormalizedSummary => {
135135
const status = txDetails.value as FlyoverStatusModel;
136-
const total = new SatoshiBig(status.amount, 'satoshi')
137-
.plus(new SatoshiBig(status.fee, 'satoshi'));
136+
const amount = toSatoshiBigIntString(status.amount);
137+
const fee = toSatoshiBigIntString(status.fee);
138+
const total = new SatoshiBig(amount, 'satoshi')
139+
.plus(new SatoshiBig(fee, 'satoshi'));
138140
return {
139-
amountFromString: new SatoshiBig(status.amount, 'satoshi').toBTCTrimmedString(),
140-
amountReceivedString: new SatoshiBig(status.amount, 'satoshi').toBTCTrimmedString(),
141+
amountFromString: status.amount,
142+
amountReceivedString: status.amount,
141143
total: total.toBTCTrimmedString(),
142144
fee: status.fee,
143145
recipientAddress: status.recipientAddress,
@@ -153,16 +155,22 @@ export default defineComponent({
153155
const showConfirmations = computed(() => !props.isFlyover
154156
&& txDetails.value.status === PegStatus.WAITING_CONFIRMATIONS);
155157
158+
const btcConfirmationsRequiredNumber = computed(() => Number(btcConfirmationsRequired.value));
159+
160+
const btcConfirmationsNumber = computed(() => Number(btcConfirmations.value));
161+
156162
function refreshPercentage() {
157163
if ('btc' in txDetails.value) {
158164
const { btc } = txDetails.value;
159-
btcConfirmationsRequired.value = btc.requiredConfirmation;
160-
btcConfirmations.value = btc.confirmations ?? 0;
165+
btcConfirmationsRequired.value = btc.requiredConfirmation.toString();
166+
btcConfirmations.value = btc.confirmations.toString() ?? '0';
161167
btcConfirmations.value = btcConfirmations.value > btcConfirmationsRequired.value
162168
? btcConfirmationsRequired.value : btcConfirmations.value;
163-
leftBtcTime.value = getTime((btcConfirmationsRequired.value - btcConfirmations.value) * 10);
169+
leftBtcTime.value = getTime(
170+
(btcConfirmationsRequiredNumber.value - btcConfirmationsNumber.value) * 10,
171+
);
164172
btcConfirmationsPercentage.value = btcConfirmations.value <= btcConfirmationsRequired.value
165-
? (btcConfirmations.value * 100) / btcConfirmationsRequired.value : 100;
173+
? (btcConfirmationsNumber.value * 100) / btcConfirmationsRequiredNumber.value : 100;
166174
if (txDetails.value.status === constants.PegStatus.CONFIRMED) {
167175
rskConfirmationsPercentage.value = 100;
168176
} else {

src/common/components/status/TxPegout.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import StatusProgressBar from '@/common/components/status/StatusProgressBar.vue';
2424
import { useStateAttribute } from '@/common/store/helper';
2525
import StatusSummary from '@/common/components/status/StatusSummary.vue';
26+
import { bigNumberToSatoshiBigIntString, toWeiBigIntString } from '@/common/utils';
2627
2728
export default defineComponent({
2829
name: 'TxPegout',
@@ -59,32 +60,34 @@ export default defineComponent({
5960
6061
const txPegoutSummary = computed((): NormalizedSummary => {
6162
const status = txDetails.value as PegoutStatusDataModel;
62-
const valueRequested = new SatoshiBig(status.valueRequestedInSatoshis, 'satoshi').toBTCTrimmedString();
63-
const amountSent = new WeiBig(valueRequested, 'rbtc').plus(calculatedGasFee.value).toRBTCTrimmedString();
63+
const valueRequested = bigNumberToSatoshiBigIntString(status.valueRequestedInSatoshis);
64+
const amountSent = new WeiBig(valueRequested, 'rbtc')
65+
.plus(calculatedGasFee.value).toRBTCTrimmedString();
6466
const btcTxId = status.status === PegoutStatus.RELEASE_BTC ? status.btcTxId : '';
6567
return {
6668
amountFromString: amountSent,
6769
amountReceivedString: amountToBeReceived.value,
68-
gas: calculatedGasFee.value,
69-
fee: status.feeInSatoshisToBePaid ?? BigInt(0),
70+
gas: calculatedGasFee.value.toString(),
71+
fee: status.feeInSatoshisToBePaid ?? '0',
7072
recipientAddress: status.btcRecipientAddress,
7173
senderAddress: status.rskSenderAddress,
7274
txId: status.rskTxHash ? status.rskTxHash : props.txId,
73-
estimatedFee: pegOutEstimatedFee.value.toSatoshiBigIntUnsafe(),
75+
estimatedFee: pegOutEstimatedFee.value.toString(),
7476
status: status.status,
7577
btcTxId,
7678
};
7779
});
7880
7981
const flyoverPegoutSummary = computed((): NormalizedSummary => {
8082
const status = txDetails.value as FlyoverStatusModel;
81-
const amount = new WeiBig(status.amount, 'wei');
82-
const fee = new WeiBig(status.fee, 'wei');
83-
const total = amount.plus(fee);
83+
const amount = toWeiBigIntString(status.amount);
84+
const fee = toWeiBigIntString(status.fee);
85+
const total = new WeiBig(amount, 'wei')
86+
.plus(new WeiBig(fee, 'wei'));
8487
return {
8588
amountFromString: total.toRBTCTrimmedString(),
86-
amountReceivedString: amount.toRBTCTrimmedString(),
87-
fee: fee.toWeiBigIntUnsafe(),
89+
amountReceivedString: status.amount,
90+
fee: status.fee,
8891
recipientAddress: status.recipientAddress,
8992
senderAddress: status.senderAddress,
9093
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)