@kimafinance/kima-transaction-widget 1.5.9 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +75 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -28
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2232,15 +2232,11 @@ var bigIntChangeDecimals = (inputs) => {
|
|
|
2232
2232
|
const valBigInt = BigInt(value);
|
|
2233
2233
|
if (decimals === newDecimals) return { value: valBigInt, decimals };
|
|
2234
2234
|
if (decimals > newDecimals) {
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
decimals: newDecimals
|
|
2238
|
-
};
|
|
2235
|
+
const diff2 = decimals - newDecimals;
|
|
2236
|
+
return { value: valBigInt / 10n ** BigInt(diff2), decimals: newDecimals };
|
|
2239
2237
|
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
decimals: newDecimals
|
|
2243
|
-
};
|
|
2238
|
+
const diff = newDecimals - decimals;
|
|
2239
|
+
return { value: valBigInt * 10n ** BigInt(diff), decimals: newDecimals };
|
|
2244
2240
|
};
|
|
2245
2241
|
var formatBigInt = (inputs) => {
|
|
2246
2242
|
return formatterFloat.format(bigIntToNumber(inputs));
|
|
@@ -6213,6 +6209,24 @@ var ConfirmDetails = ({
|
|
|
6213
6209
|
() => sumBigAmts([sourceFee, targetFee, swapFee ?? { value: 0n, decimals: 0 }]),
|
|
6214
6210
|
[sourceFee, targetFee, swapFee]
|
|
6215
6211
|
);
|
|
6212
|
+
const originChargeAmount = (0, import_react47.useMemo)(() => {
|
|
6213
|
+
if (["CC", "BANK"].includes(originNetwork.shortName)) {
|
|
6214
|
+
const submit = txValues.submitAmount;
|
|
6215
|
+
const feeInSubmitDec = bigIntChangeDecimals({
|
|
6216
|
+
...totalFee,
|
|
6217
|
+
newDecimals: submit.decimals
|
|
6218
|
+
});
|
|
6219
|
+
const val = feeDeduct ? submit.value : submit.value + feeInSubmitDec.value;
|
|
6220
|
+
return { value: val, decimals: submit.decimals };
|
|
6221
|
+
}
|
|
6222
|
+
return txValues.allowanceAmount;
|
|
6223
|
+
}, [
|
|
6224
|
+
originNetwork.shortName,
|
|
6225
|
+
txValues.submitAmount,
|
|
6226
|
+
txValues.allowanceAmount,
|
|
6227
|
+
totalFee,
|
|
6228
|
+
feeDeduct
|
|
6229
|
+
]);
|
|
6216
6230
|
(0, import_react47.useEffect)(() => {
|
|
6217
6231
|
width === 0 && updateWidth(window.innerWidth);
|
|
6218
6232
|
}, [width, updateWidth]);
|
|
@@ -6250,7 +6264,7 @@ var ConfirmDetails = ({
|
|
|
6250
6264
|
dAppOption === "none" /* None */ && /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)("div", { className: "amount-details", children: [
|
|
6251
6265
|
/* @__PURE__ */ (0, import_jsx_runtime66.jsx)("span", { children: "Amount to Transfer" }),
|
|
6252
6266
|
/* @__PURE__ */ (0, import_jsx_runtime66.jsx)("div", { className: "coin-details", children: /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)("p", { children: [
|
|
6253
|
-
formatBigInt(
|
|
6267
|
+
formatBigInt(originChargeAmount),
|
|
6254
6268
|
" ",
|
|
6255
6269
|
sourceCurrency
|
|
6256
6270
|
] }) })
|
|
@@ -6940,7 +6954,7 @@ var TransactionWidget = ({ theme }) => {
|
|
|
6940
6954
|
const amount = (0, import_react_redux41.useSelector)(selectAmount);
|
|
6941
6955
|
const txId = (0, import_react_redux41.useSelector)(selectTxId);
|
|
6942
6956
|
const dAppOption = (0, import_react_redux41.useSelector)(selectDappOption);
|
|
6943
|
-
const { transactionValues } = (0, import_react_redux41.useSelector)(selectServiceFee);
|
|
6957
|
+
const { transactionValues, totalFee } = (0, import_react_redux41.useSelector)(selectServiceFee);
|
|
6944
6958
|
const txValues = feeDeduct ? transactionValues.feeFromTarget : transactionValues.feeFromOrigin;
|
|
6945
6959
|
const transactionOption = (0, import_react_redux41.useSelector)(selectTransactionOption);
|
|
6946
6960
|
const sourceChain = (0, import_react_redux41.useSelector)(selectSourceChain);
|
|
@@ -7112,6 +7126,15 @@ var TransactionWidget = ({ theme }) => {
|
|
|
7112
7126
|
}
|
|
7113
7127
|
return data?.status?.toUpperCase?.() === "Completed" /* COMPLETED */ ? widgetIsSwap ? "Swapped " : "Transferred " : widgetIsSwap ? "Swapping " : "Transfering ";
|
|
7114
7128
|
}, [mode, data?.status, isEmptyStatus, widgetIsSwap]);
|
|
7129
|
+
const originChargeAmount = (0, import_react53.useMemo)(() => {
|
|
7130
|
+
const submit = txValues.submitAmount;
|
|
7131
|
+
const feeInSubmitDec = bigIntChangeDecimals({
|
|
7132
|
+
...totalFee,
|
|
7133
|
+
newDecimals: submit.decimals
|
|
7134
|
+
});
|
|
7135
|
+
const val = feeDeduct ? submit.value : submit.value + feeInSubmitDec.value;
|
|
7136
|
+
return { value: val, decimals: submit.decimals };
|
|
7137
|
+
}, [txValues.submitAmount, totalFee, feeDeduct]);
|
|
7115
7138
|
const { leftAmt, rightAmt, leftSym, rightSym } = (0, import_react53.useMemo)(() => {
|
|
7116
7139
|
if (mode === "status" /* status */) {
|
|
7117
7140
|
if (widgetIsSwap) {
|
|
@@ -7132,8 +7155,9 @@ var TransactionWidget = ({ theme }) => {
|
|
|
7132
7155
|
rightSym: data?.targetSymbol ?? ""
|
|
7133
7156
|
};
|
|
7134
7157
|
}
|
|
7135
|
-
|
|
7136
|
-
let
|
|
7158
|
+
const isFiatSrc = (transactionSourceChain?.shortName ?? "") === "CC" || (transactionSourceChain?.shortName ?? "") === "BANK";
|
|
7159
|
+
let left = Number(amount) !== 0 ? isFiatSrc ? bigIntToNumber(originChargeAmount).toFixed(2) : formatBigInt(txValues.allowanceAmount) : "";
|
|
7160
|
+
let right = Number(amount) !== 0 ? isFiatSrc ? bigIntToNumber(txValues.submitAmount).toFixed(2) : formatBigInt(txValues.submitAmount) : "";
|
|
7137
7161
|
let leftSymbol = sourceSymbol;
|
|
7138
7162
|
let rightSymbol = targetSymbol;
|
|
7139
7163
|
if (widgetIsSwap && data && data?.amount != null && data?.amount !== "") {
|
|
@@ -7159,7 +7183,8 @@ var TransactionWidget = ({ theme }) => {
|
|
|
7159
7183
|
txValues.allowanceAmount,
|
|
7160
7184
|
txValues.submitAmount,
|
|
7161
7185
|
sourceSymbol,
|
|
7162
|
-
targetSymbol
|
|
7186
|
+
targetSymbol,
|
|
7187
|
+
originChargeAmount
|
|
7163
7188
|
]);
|
|
7164
7189
|
const resetForm = () => {
|
|
7165
7190
|
try {
|
|
@@ -7494,15 +7519,29 @@ var getFees = async (amount, originChain, originAddress, originSymbol, targetCha
|
|
|
7494
7519
|
dex: result.swapInfo.dex,
|
|
7495
7520
|
slippage: result.swapInfo.slippage
|
|
7496
7521
|
} : void 0;
|
|
7522
|
+
const sourceFee = toBigintAmount(result.feeOriginGasBigInt);
|
|
7523
|
+
const targetFee = toBigintAmount(result.feeTargetGasBigInt);
|
|
7524
|
+
const kimaFee = toBigintAmount(result.feeKimaProcessingBigInt);
|
|
7525
|
+
const parts = [
|
|
7526
|
+
sourceFee,
|
|
7527
|
+
targetFee,
|
|
7528
|
+
kimaFee,
|
|
7529
|
+
swapFee?.decimals ? swapFee : { value: 0n, decimals: 0 }
|
|
7530
|
+
].filter((p) => p.decimals !== 0 || p.value !== 0n);
|
|
7531
|
+
const maxDec = parts.reduce((m, a) => Math.max(m, a.decimals), 0);
|
|
7532
|
+
const scaleUp2 = (v, from, to) => to <= from ? v : v * 10n ** BigInt(to - from);
|
|
7533
|
+
const totalScaled = parts.reduce(
|
|
7534
|
+
(acc, a) => acc + scaleUp2(a.value, a.decimals, maxDec),
|
|
7535
|
+
0n
|
|
7536
|
+
);
|
|
7497
7537
|
const output = {
|
|
7498
7538
|
feeId: result.feeId,
|
|
7499
7539
|
peggedTo: result.peggedTo,
|
|
7500
7540
|
expiration: result.expiration,
|
|
7501
|
-
sourceFee
|
|
7502
|
-
targetFee
|
|
7503
|
-
kimaFee
|
|
7504
|
-
totalFee:
|
|
7505
|
-
// NEW
|
|
7541
|
+
sourceFee,
|
|
7542
|
+
targetFee,
|
|
7543
|
+
kimaFee,
|
|
7544
|
+
totalFee: { value: totalScaled, decimals: maxDec },
|
|
7506
7545
|
swapFee,
|
|
7507
7546
|
swapInfo,
|
|
7508
7547
|
transactionValues: {
|
|
@@ -7527,7 +7566,7 @@ var getFees = async (amount, originChain, originAddress, originSymbol, targetCha
|
|
|
7527
7566
|
};
|
|
7528
7567
|
logger_default.debug("[getFees] response", {
|
|
7529
7568
|
feeId: output.feeId,
|
|
7530
|
-
|
|
7569
|
+
totalFee: `${output.totalFee.value} @ ${output.totalFee.decimals}dp`,
|
|
7531
7570
|
hasTargetSide: !!fromTarget,
|
|
7532
7571
|
hasSwapInfo: !!swapInfo
|
|
7533
7572
|
});
|
|
@@ -7828,7 +7867,8 @@ var useValidateTransaction = (inputs) => {
|
|
|
7828
7867
|
message: "Testnet transfers for USD stablecoins are capped to $100 per transaction"
|
|
7829
7868
|
};
|
|
7830
7869
|
}
|
|
7831
|
-
|
|
7870
|
+
const isFiatSrc = sourceChain === "BANK" || sourceChain === "CC";
|
|
7871
|
+
if (totalFee <= 0n && !isFiatSrc) {
|
|
7832
7872
|
return {
|
|
7833
7873
|
error: "ValidationError" /* Error */,
|
|
7834
7874
|
message: "Fee calculation error"
|
|
@@ -8585,7 +8625,7 @@ var FiatWidget = ({ submitCallback }) => {
|
|
|
8585
8625
|
const networkOption = (0, import_react_redux48.useSelector)(selectNetworkOption);
|
|
8586
8626
|
const sourceCurrency = (0, import_react_redux48.useSelector)(selectSourceCurrency);
|
|
8587
8627
|
const sourceChain = (0, import_react_redux48.useSelector)(selectSourceChain);
|
|
8588
|
-
const { transactionValues } = (0, import_react_redux48.useSelector)(selectServiceFee);
|
|
8628
|
+
const { transactionValues, totalFee } = (0, import_react_redux48.useSelector)(selectServiceFee);
|
|
8589
8629
|
const ccTransactionIdSeedRef = (0, import_react57.useRef)((0, import_uuid.v4)());
|
|
8590
8630
|
const ccTransactionSubmittedRef = (0, import_react57.useRef)(false);
|
|
8591
8631
|
const { data: envOptions, isLoading: isEnvLoading } = useGetEnvOptions({
|
|
@@ -8602,9 +8642,18 @@ var FiatWidget = ({ submitCallback }) => {
|
|
|
8602
8642
|
dispatch(setCCTransactionId(data?.transactionId));
|
|
8603
8643
|
}, [dispatch, data, isTransactionIdLoading]);
|
|
8604
8644
|
const txValues = feeDeduct ? transactionValues.feeFromTarget : transactionValues.feeFromOrigin;
|
|
8605
|
-
const
|
|
8606
|
-
|
|
8607
|
-
|
|
8645
|
+
const chargeAmountBig = (0, import_react57.useMemo)(() => {
|
|
8646
|
+
const submit = txValues.submitAmount;
|
|
8647
|
+
const feeInSubmitDec = bigIntChangeDecimals({
|
|
8648
|
+
...totalFee,
|
|
8649
|
+
newDecimals: submit.decimals
|
|
8650
|
+
});
|
|
8651
|
+
const val = feeDeduct ? submit.value : submit.value + feeInSubmitDec.value;
|
|
8652
|
+
return { value: val, decimals: submit.decimals };
|
|
8653
|
+
}, [txValues.submitAmount, totalFee, feeDeduct]);
|
|
8654
|
+
const chargeAmount = (0, import_react57.useMemo)(
|
|
8655
|
+
() => formatBigInt(chargeAmountBig),
|
|
8656
|
+
[chargeAmountBig]
|
|
8608
8657
|
);
|
|
8609
8658
|
const [isLoading, setIsLoading] = (0, import_react57.useState)(true);
|
|
8610
8659
|
const baseUrl = (0, import_react57.useMemo)(
|
|
@@ -8617,9 +8666,7 @@ var FiatWidget = ({ submitCallback }) => {
|
|
|
8617
8666
|
);
|
|
8618
8667
|
(0, import_react57.useEffect)(() => {
|
|
8619
8668
|
const handleMessage = (event) => {
|
|
8620
|
-
if (event.origin !== baseUrl)
|
|
8621
|
-
return;
|
|
8622
|
-
}
|
|
8669
|
+
if (event.origin !== baseUrl) return;
|
|
8623
8670
|
logger_default.info("postMessage: new message: ", event);
|
|
8624
8671
|
if (event.data.type === "isCompleted") {
|
|
8625
8672
|
logger_default.info("cc widget isCompleted", ccTransactionSubmittedRef.current);
|
|
@@ -8654,7 +8701,7 @@ var FiatWidget = ({ submitCallback }) => {
|
|
|
8654
8701
|
{
|
|
8655
8702
|
width: isLoading || isTransactionIdLoading || ccTransactionStatus === "success" || error ? 0 : "100%",
|
|
8656
8703
|
height: isLoading || isTransactionIdLoading || ccTransactionStatus === "success" || error ? 0 : "100%",
|
|
8657
|
-
src: `${baseUrl}/widgets/kyc?partner=${partnerId}&amount=${
|
|
8704
|
+
src: `${baseUrl}/widgets/kyc?partner=${partnerId}&amount=${chargeAmount}¤cy=${sourceCurrency}&trx_uuid=${data?.transactionId}&scenario=${scenario}&postmessage=true`,
|
|
8658
8705
|
loading: "lazy",
|
|
8659
8706
|
title: "Credit Card Widget",
|
|
8660
8707
|
allow: "camera; clipboard-write",
|