@multiversx/sdk-dapp-liquidity 1.1.0-alpha.17 → 1.1.0-alpha.19
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/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/reactjs/components/BridgeForm/BridgeForm.js +95 -57
- package/reactjs/components/BridgeForm/BridgeForm.mjs +95 -57
- package/reactjs/hooks/index.js +1 -1
- package/reactjs/hooks/index.mjs +1 -1
- package/reactjs/hooks/useBalances.js +4 -2
- package/reactjs/hooks/useBalances.mjs +4 -2
- package/reactjs/hooks/useSignTransaction.d.ts +13 -0
- package/reactjs/hooks/useSignTransaction.js +19 -6
- package/reactjs/hooks/useSignTransaction.mjs +19 -6
- package/reactjs/index.js +1 -1
- package/reactjs/index.mjs +1 -1
- package/reactjs/queries/useGetEvmTokensBalances.query.js +1 -1
- package/reactjs/queries/useGetEvmTokensBalances.query.mjs +1 -1
- package/types/transaction.d.ts +9 -0
- package/types/utxo.d.ts +11 -0
- package/types/utxo.js +2 -0
- package/types/utxo.mjs +1 -0
- package/{useBalances-CvRCOieR.mjs → useBalances-B7J7g6dD.mjs} +22 -29
- package/{useBalances-Ds5d90Cc.js → useBalances-D7Fze-E_.js} +22 -29
package/index.js
CHANGED
|
@@ -53,7 +53,7 @@ const reactjs_hooks_validation_useSecondAmountSchema = require("./reactjs/hooks/
|
|
|
53
53
|
const reactjs_hooks_validation_useTestHasEnoughFunds = require("./reactjs/hooks/validation/useTestHasEnoughFunds.js");
|
|
54
54
|
const reactjs_hooks_validation_useTestIsConnected = require("./reactjs/hooks/validation/useTestIsConnected.js");
|
|
55
55
|
const reactjs_hooks_useAccount = require("./reactjs/hooks/useAccount.js");
|
|
56
|
-
const reactjs_hooks_useBalances = require("./useBalances-
|
|
56
|
+
const reactjs_hooks_useBalances = require("./useBalances-D7Fze-E_.js");
|
|
57
57
|
const reactjs_hooks_useBridgeFormik = require("./reactjs/hooks/useBridgeFormik.js");
|
|
58
58
|
const reactjs_hooks_useDebounce = require("./reactjs/hooks/useDebounce.js");
|
|
59
59
|
const reactjs_hooks_useFetchBridgeData = require("./reactjs/hooks/useFetchBridgeData.js");
|
package/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ import { useSecondAmountSchema } from "./reactjs/hooks/validation/useSecondAmoun
|
|
|
50
50
|
import { useTestHasEnoughFunds } from "./reactjs/hooks/validation/useTestHasEnoughFunds.mjs";
|
|
51
51
|
import { useTestIsConnected } from "./reactjs/hooks/validation/useTestIsConnected.mjs";
|
|
52
52
|
import { useAccount } from "./reactjs/hooks/useAccount.mjs";
|
|
53
|
-
import { u } from "./useBalances-
|
|
53
|
+
import { u } from "./useBalances-B7J7g6dD.mjs";
|
|
54
54
|
import { BridgeFormikValuesEnum, useBridgeFormik } from "./reactjs/hooks/useBridgeFormik.mjs";
|
|
55
55
|
import { useDebounce } from "./reactjs/hooks/useDebounce.mjs";
|
|
56
56
|
import { useFetchBridgeData } from "./reactjs/hooks/useFetchBridgeData.mjs";
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ const reactjs_components_Connect_MvxAccountDisplay = require("../Connect/MvxAcco
|
|
|
44
44
|
const reactjs_components_TokenSelector_TokenSelector = require("../TokenSelector/TokenSelector.js");
|
|
45
45
|
const viem = require("viem");
|
|
46
46
|
const actions = require("viem/actions");
|
|
47
|
-
const reactjs_hooks_useBalances = require("../../../useBalances-
|
|
47
|
+
const reactjs_hooks_useBalances = require("../../../useBalances-D7Fze-E_.js");
|
|
48
48
|
function deepEqual(a, b) {
|
|
49
49
|
if (a === b)
|
|
50
50
|
return true;
|
|
@@ -134,6 +134,7 @@ const BridgeForm = ({
|
|
|
134
134
|
}) => {
|
|
135
135
|
var _a, _b, _c, _d, _e, _f;
|
|
136
136
|
const ref = React.useRef(null);
|
|
137
|
+
const initializedInitialTokensRef = React.useRef(false);
|
|
137
138
|
const [isTokenSelectorVisible, setIsTokenSelectorVisible] = React.useState(false);
|
|
138
139
|
const [pendingSigning, setPendingSigning] = React.useState(false);
|
|
139
140
|
const [siginingTransactionsCount, setSigningTransactionsCount] = React.useState(0);
|
|
@@ -164,7 +165,7 @@ const BridgeForm = ({
|
|
|
164
165
|
(chain) => chain.chainId.toString() === mvxChainId.toString()
|
|
165
166
|
);
|
|
166
167
|
}, [chainId, chains]);
|
|
167
|
-
const { evm, solana } = reactjs_hooks_useSignTransaction.useSignTransaction();
|
|
168
|
+
const { evm, solana, bitcoin } = reactjs_hooks_useSignTransaction.useSignTransaction();
|
|
168
169
|
const sendTransactions = reactjs_hooks_useSendTransactions.useSendTransactions();
|
|
169
170
|
const {
|
|
170
171
|
mutate: getRate,
|
|
@@ -189,30 +190,33 @@ const BridgeForm = ({
|
|
|
189
190
|
})) ?? [],
|
|
190
191
|
[evmTokensWithBalances]
|
|
191
192
|
);
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const foundTokens = [];
|
|
197
|
-
for (const availableToken of firstToken.availableTokens) {
|
|
198
|
-
const foundToken = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
199
|
-
(mvxToken) => mvxToken.address === availableToken.address
|
|
200
|
-
);
|
|
201
|
-
if (foundToken) {
|
|
202
|
-
foundTokens.push(foundToken);
|
|
193
|
+
const getAvailableTokens = React.useCallback(
|
|
194
|
+
(option) => {
|
|
195
|
+
if (!(option == null ? void 0 : option.availableTokens)) {
|
|
196
|
+
return [];
|
|
203
197
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
const foundTokens = [];
|
|
199
|
+
for (const availableToken of option.availableTokens) {
|
|
200
|
+
const foundToken = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
201
|
+
(mvxToken) => mvxToken.address === availableToken.address
|
|
202
|
+
);
|
|
203
|
+
if (foundToken) {
|
|
204
|
+
foundTokens.push(foundToken);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return foundTokens;
|
|
208
|
+
},
|
|
209
|
+
[mvxTokensWithBalances]
|
|
210
|
+
);
|
|
207
211
|
const toOptions = React.useMemo(
|
|
208
|
-
() => (availableTokens &&
|
|
212
|
+
() => ((firstToken == null ? void 0 : firstToken.availableTokens) && getAvailableTokens(firstToken).map((token) => {
|
|
209
213
|
return {
|
|
210
214
|
...token,
|
|
211
215
|
identifier: token.address,
|
|
212
216
|
ticker: token.symbol
|
|
213
217
|
};
|
|
214
218
|
})) ?? [],
|
|
215
|
-
[availableTokens]
|
|
219
|
+
[firstToken == null ? void 0 : firstToken.availableTokens]
|
|
216
220
|
);
|
|
217
221
|
const selectedChainOption = React.useMemo(
|
|
218
222
|
() => (chains == null ? void 0 : chains.find(
|
|
@@ -220,9 +224,11 @@ const BridgeForm = ({
|
|
|
220
224
|
)) ?? (chains == null ? void 0 : chains[0]),
|
|
221
225
|
[activeChain == null ? void 0 : activeChain.id, chains]
|
|
222
226
|
);
|
|
223
|
-
const
|
|
224
|
-
() =>
|
|
225
|
-
|
|
227
|
+
const getDefaultReceivingToken = React.useCallback(
|
|
228
|
+
(values) => values.find((x) => x.symbol.toLowerCase().includes("usdc")) ?? (mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
229
|
+
(x) => x.symbol.toLowerCase().includes("usdc")
|
|
230
|
+
)),
|
|
231
|
+
[mvxTokensWithBalances]
|
|
226
232
|
);
|
|
227
233
|
const hasAmounts = firstAmount !== "" && secondAmount !== "";
|
|
228
234
|
const fetchRateDebounced = React.useCallback(
|
|
@@ -285,7 +291,7 @@ const BridgeForm = ({
|
|
|
285
291
|
);
|
|
286
292
|
const updateUrlParams = React.useCallback(
|
|
287
293
|
({ firstTokenId, secondTokenId }) => {
|
|
288
|
-
if (isTokensLoading
|
|
294
|
+
if (isTokensLoading) {
|
|
289
295
|
return;
|
|
290
296
|
}
|
|
291
297
|
const currentUrl = reactjs_utils_getCompletePathname.getCompletePathname();
|
|
@@ -302,8 +308,14 @@ const BridgeForm = ({
|
|
|
302
308
|
}
|
|
303
309
|
onNavigate == null ? void 0 : onNavigate(newUrl, { replace: true });
|
|
304
310
|
},
|
|
305
|
-
[
|
|
311
|
+
[callbackRoute, isTokensLoading, onNavigate]
|
|
306
312
|
);
|
|
313
|
+
console.log("BridgeForm", {
|
|
314
|
+
firstToken,
|
|
315
|
+
secondToken,
|
|
316
|
+
fromOptions,
|
|
317
|
+
toOptions
|
|
318
|
+
});
|
|
307
319
|
const onChangeFirstSelect = React.useCallback(
|
|
308
320
|
(option) => {
|
|
309
321
|
if (!option) {
|
|
@@ -311,9 +323,13 @@ const BridgeForm = ({
|
|
|
311
323
|
}
|
|
312
324
|
setFirstToken(() => option);
|
|
313
325
|
updateUrlParams({ firstTokenId: option == null ? void 0 : option.address });
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
326
|
+
const availableTokens = getAvailableTokens(option);
|
|
327
|
+
const secondOption = availableTokens.find(
|
|
328
|
+
(x) => {
|
|
329
|
+
var _a2;
|
|
330
|
+
return x.symbol.toLowerCase() === ((_a2 = availableTokens == null ? void 0 : availableTokens[0]) == null ? void 0 : _a2.symbol.toLowerCase());
|
|
331
|
+
}
|
|
332
|
+
) ?? getDefaultReceivingToken(availableTokens);
|
|
317
333
|
if (!secondOption) {
|
|
318
334
|
return;
|
|
319
335
|
}
|
|
@@ -342,7 +358,7 @@ const BridgeForm = ({
|
|
|
342
358
|
);
|
|
343
359
|
const setInitialSelectedTokens = () => {
|
|
344
360
|
var _a2, _b2, _c2, _d2;
|
|
345
|
-
if (isTokensLoading) {
|
|
361
|
+
if (isTokensLoading || initializedInitialTokensRef.current) {
|
|
346
362
|
return;
|
|
347
363
|
}
|
|
348
364
|
const initialTokens = reactjs_utils_getInitialTokens.getInitialTokens();
|
|
@@ -353,31 +369,37 @@ const BridgeForm = ({
|
|
|
353
369
|
var _a3;
|
|
354
370
|
return option.chainId.toString() === ((_a3 = activeChain == null ? void 0 : activeChain.id) == null ? void 0 : _a3.toString());
|
|
355
371
|
}
|
|
356
|
-
);
|
|
357
|
-
const
|
|
372
|
+
) ?? (fromOptions == null ? void 0 : fromOptions[0]);
|
|
373
|
+
const availableTokens = getAvailableTokens(firstOption);
|
|
374
|
+
const secondOption = (availableTokens == null ? void 0 : availableTokens.find(
|
|
358
375
|
({ address }) => {
|
|
359
376
|
var _a3;
|
|
360
377
|
return address.toLowerCase() === ((_a3 = (firstOption == null ? void 0 : firstOption.symbol) ?? (initialTokens == null ? void 0 : initialTokens.secondTokenId)) == null ? void 0 : _a3.toLowerCase());
|
|
361
378
|
}
|
|
362
|
-
)) ??
|
|
379
|
+
)) ?? availableTokens.find(
|
|
363
380
|
(x) => x.symbol.toLowerCase() === (firstOption == null ? void 0 : firstOption.symbol.toLowerCase())
|
|
364
|
-
) ??
|
|
381
|
+
) ?? getDefaultReceivingToken(availableTokens);
|
|
365
382
|
const hasOptionsSelected = Boolean(firstToken) && Boolean(secondToken) && ((_a2 = firstToken == null ? void 0 : firstToken.address) == null ? void 0 : _a2.toLowerCase()) === ((_b2 = firstOption == null ? void 0 : firstOption.address) == null ? void 0 : _b2.toLowerCase()) && ((_c2 = secondToken == null ? void 0 : secondToken.address) == null ? void 0 : _c2.toLowerCase()) === ((_d2 = secondOption == null ? void 0 : secondOption.address) == null ? void 0 : _d2.toLowerCase());
|
|
366
383
|
if (hasOptionsSelected) {
|
|
367
384
|
return;
|
|
368
385
|
}
|
|
386
|
+
let initializedFirstToken = false;
|
|
369
387
|
if (firstOption) {
|
|
370
388
|
setFirstToken(firstOption);
|
|
371
389
|
updateUrlParams({
|
|
372
390
|
firstTokenId: firstOption == null ? void 0 : firstOption.address
|
|
373
391
|
});
|
|
392
|
+
initializedFirstToken = true;
|
|
374
393
|
}
|
|
394
|
+
let initializedSecondToken = false;
|
|
375
395
|
if (secondOption) {
|
|
376
396
|
setSecondToken(secondOption);
|
|
377
397
|
updateUrlParams({
|
|
378
398
|
secondTokenId: secondOption == null ? void 0 : secondOption.address
|
|
379
399
|
});
|
|
400
|
+
initializedSecondToken = true;
|
|
380
401
|
}
|
|
402
|
+
initializedInitialTokensRef.current = initializedFirstToken && initializedSecondToken;
|
|
381
403
|
};
|
|
382
404
|
const onSubmit = React.useCallback(
|
|
383
405
|
async ({
|
|
@@ -391,14 +413,42 @@ const BridgeForm = ({
|
|
|
391
413
|
let txIndex = -1;
|
|
392
414
|
for (const transaction of transactions) {
|
|
393
415
|
++txIndex;
|
|
394
|
-
let txHash;
|
|
395
416
|
try {
|
|
396
417
|
switch (selectedChainOption == null ? void 0 : selectedChainOption.chainType) {
|
|
418
|
+
case types_chainType.ChainType.evm:
|
|
419
|
+
const hash = await evm.signTransaction({
|
|
420
|
+
...transaction,
|
|
421
|
+
value: BigInt(transaction.value),
|
|
422
|
+
gas: BigInt(transaction.gasLimit),
|
|
423
|
+
account: bridgeAddress
|
|
424
|
+
});
|
|
425
|
+
if (!hash) {
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
signedTransactions.push({
|
|
429
|
+
...transaction,
|
|
430
|
+
txHash: hash
|
|
431
|
+
});
|
|
432
|
+
if (txIndex === transactions.length - 1 || !hash) {
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
const transactionReceipt = await waitForTransactionReceipt(
|
|
436
|
+
config,
|
|
437
|
+
{
|
|
438
|
+
confirmations: 1,
|
|
439
|
+
hash
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
console.info({
|
|
443
|
+
transactionReceipt,
|
|
444
|
+
hash
|
|
445
|
+
});
|
|
446
|
+
break;
|
|
397
447
|
case types_chainType.ChainType.sol:
|
|
398
448
|
if (!transaction.instructions || !transaction.feePayer) {
|
|
399
449
|
break;
|
|
400
450
|
}
|
|
401
|
-
txHash = await solana.signTransaction({
|
|
451
|
+
const txHash = await solana.signTransaction({
|
|
402
452
|
feePayer: transaction.feePayer,
|
|
403
453
|
instructions: transaction.instructions
|
|
404
454
|
});
|
|
@@ -410,16 +460,20 @@ const BridgeForm = ({
|
|
|
410
460
|
txHash
|
|
411
461
|
});
|
|
412
462
|
break;
|
|
413
|
-
case types_chainType.ChainType.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
463
|
+
case types_chainType.ChainType.btc:
|
|
464
|
+
if (!transaction.bitcoinParams) {
|
|
465
|
+
console.error("No bitcoin params");
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
console.log({
|
|
469
|
+
transaction
|
|
419
470
|
});
|
|
471
|
+
const psbt = await bitcoin.signTransaction(
|
|
472
|
+
transaction.bitcoinParams
|
|
473
|
+
);
|
|
420
474
|
signedTransactions.push({
|
|
421
475
|
...transaction,
|
|
422
|
-
txHash
|
|
476
|
+
txHash: psbt
|
|
423
477
|
});
|
|
424
478
|
break;
|
|
425
479
|
default:
|
|
@@ -430,17 +484,6 @@ const BridgeForm = ({
|
|
|
430
484
|
setSigningTransactionsCount(
|
|
431
485
|
() => transactions.length - 1 - txIndex
|
|
432
486
|
);
|
|
433
|
-
if (txIndex === transactions.length - 1 || !txHash || (selectedChainOption == null ? void 0 : selectedChainOption.chainType) !== types_chainType.ChainType.evm) {
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
const transactionReceipt = await waitForTransactionReceipt(config, {
|
|
437
|
-
confirmations: 1,
|
|
438
|
-
hash: txHash
|
|
439
|
-
});
|
|
440
|
-
console.info({
|
|
441
|
-
transactionReceipt,
|
|
442
|
-
hash: txHash
|
|
443
|
-
});
|
|
444
487
|
} catch (e) {
|
|
445
488
|
reactToastify.toast.dismiss();
|
|
446
489
|
reactToastify.toast.error("Transaction aborted");
|
|
@@ -531,12 +574,7 @@ const BridgeForm = ({
|
|
|
531
574
|
setSecondAmount("0");
|
|
532
575
|
}
|
|
533
576
|
}, [rateValidationError]);
|
|
534
|
-
React.useEffect(setInitialSelectedTokens, [
|
|
535
|
-
isTokensLoading,
|
|
536
|
-
fromOptions,
|
|
537
|
-
toOptions,
|
|
538
|
-
chainId
|
|
539
|
-
]);
|
|
577
|
+
React.useEffect(setInitialSelectedTokens, [isTokensLoading, fromOptions]);
|
|
540
578
|
React.useEffect(() => {
|
|
541
579
|
const selectedTokenOption = evmTokensWithBalances == null ? void 0 : evmTokensWithBalances.find(
|
|
542
580
|
(x) => x.address === (firstToken == null ? void 0 : firstToken.address)
|
|
@@ -41,7 +41,7 @@ import { MvxAccountDisplay } from "../Connect/MvxAccountDisplay.mjs";
|
|
|
41
41
|
import { TokenSelector } from "../TokenSelector/TokenSelector.mjs";
|
|
42
42
|
import { hexToString } from "viem";
|
|
43
43
|
import { waitForTransactionReceipt as waitForTransactionReceipt$1, getTransaction, call } from "viem/actions";
|
|
44
|
-
import { g as getAction } from "../../../useBalances-
|
|
44
|
+
import { g as getAction } from "../../../useBalances-B7J7g6dD.mjs";
|
|
45
45
|
function deepEqual(a, b) {
|
|
46
46
|
if (a === b)
|
|
47
47
|
return true;
|
|
@@ -131,6 +131,7 @@ const BridgeForm = ({
|
|
|
131
131
|
}) => {
|
|
132
132
|
var _a, _b, _c, _d, _e, _f;
|
|
133
133
|
const ref = useRef(null);
|
|
134
|
+
const initializedInitialTokensRef = useRef(false);
|
|
134
135
|
const [isTokenSelectorVisible, setIsTokenSelectorVisible] = useState(false);
|
|
135
136
|
const [pendingSigning, setPendingSigning] = useState(false);
|
|
136
137
|
const [siginingTransactionsCount, setSigningTransactionsCount] = useState(0);
|
|
@@ -161,7 +162,7 @@ const BridgeForm = ({
|
|
|
161
162
|
(chain) => chain.chainId.toString() === mvxChainId.toString()
|
|
162
163
|
);
|
|
163
164
|
}, [chainId, chains]);
|
|
164
|
-
const { evm, solana } = useSignTransaction();
|
|
165
|
+
const { evm, solana, bitcoin } = useSignTransaction();
|
|
165
166
|
const sendTransactions = useSendTransactions();
|
|
166
167
|
const {
|
|
167
168
|
mutate: getRate,
|
|
@@ -186,30 +187,33 @@ const BridgeForm = ({
|
|
|
186
187
|
})) ?? [],
|
|
187
188
|
[evmTokensWithBalances]
|
|
188
189
|
);
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const foundTokens = [];
|
|
194
|
-
for (const availableToken of firstToken.availableTokens) {
|
|
195
|
-
const foundToken = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
196
|
-
(mvxToken) => mvxToken.address === availableToken.address
|
|
197
|
-
);
|
|
198
|
-
if (foundToken) {
|
|
199
|
-
foundTokens.push(foundToken);
|
|
190
|
+
const getAvailableTokens = useCallback(
|
|
191
|
+
(option) => {
|
|
192
|
+
if (!(option == null ? void 0 : option.availableTokens)) {
|
|
193
|
+
return [];
|
|
200
194
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
195
|
+
const foundTokens = [];
|
|
196
|
+
for (const availableToken of option.availableTokens) {
|
|
197
|
+
const foundToken = mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
198
|
+
(mvxToken) => mvxToken.address === availableToken.address
|
|
199
|
+
);
|
|
200
|
+
if (foundToken) {
|
|
201
|
+
foundTokens.push(foundToken);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return foundTokens;
|
|
205
|
+
},
|
|
206
|
+
[mvxTokensWithBalances]
|
|
207
|
+
);
|
|
204
208
|
const toOptions = useMemo(
|
|
205
|
-
() => (availableTokens &&
|
|
209
|
+
() => ((firstToken == null ? void 0 : firstToken.availableTokens) && getAvailableTokens(firstToken).map((token) => {
|
|
206
210
|
return {
|
|
207
211
|
...token,
|
|
208
212
|
identifier: token.address,
|
|
209
213
|
ticker: token.symbol
|
|
210
214
|
};
|
|
211
215
|
})) ?? [],
|
|
212
|
-
[availableTokens]
|
|
216
|
+
[firstToken == null ? void 0 : firstToken.availableTokens]
|
|
213
217
|
);
|
|
214
218
|
const selectedChainOption = useMemo(
|
|
215
219
|
() => (chains == null ? void 0 : chains.find(
|
|
@@ -217,9 +221,11 @@ const BridgeForm = ({
|
|
|
217
221
|
)) ?? (chains == null ? void 0 : chains[0]),
|
|
218
222
|
[activeChain == null ? void 0 : activeChain.id, chains]
|
|
219
223
|
);
|
|
220
|
-
const
|
|
221
|
-
() =>
|
|
222
|
-
|
|
224
|
+
const getDefaultReceivingToken = useCallback(
|
|
225
|
+
(values) => values.find((x) => x.symbol.toLowerCase().includes("usdc")) ?? (mvxTokensWithBalances == null ? void 0 : mvxTokensWithBalances.find(
|
|
226
|
+
(x) => x.symbol.toLowerCase().includes("usdc")
|
|
227
|
+
)),
|
|
228
|
+
[mvxTokensWithBalances]
|
|
223
229
|
);
|
|
224
230
|
const hasAmounts = firstAmount !== "" && secondAmount !== "";
|
|
225
231
|
const fetchRateDebounced = useCallback(
|
|
@@ -282,7 +288,7 @@ const BridgeForm = ({
|
|
|
282
288
|
);
|
|
283
289
|
const updateUrlParams = useCallback(
|
|
284
290
|
({ firstTokenId, secondTokenId }) => {
|
|
285
|
-
if (isTokensLoading
|
|
291
|
+
if (isTokensLoading) {
|
|
286
292
|
return;
|
|
287
293
|
}
|
|
288
294
|
const currentUrl = getCompletePathname();
|
|
@@ -299,8 +305,14 @@ const BridgeForm = ({
|
|
|
299
305
|
}
|
|
300
306
|
onNavigate == null ? void 0 : onNavigate(newUrl, { replace: true });
|
|
301
307
|
},
|
|
302
|
-
[
|
|
308
|
+
[callbackRoute, isTokensLoading, onNavigate]
|
|
303
309
|
);
|
|
310
|
+
console.log("BridgeForm", {
|
|
311
|
+
firstToken,
|
|
312
|
+
secondToken,
|
|
313
|
+
fromOptions,
|
|
314
|
+
toOptions
|
|
315
|
+
});
|
|
304
316
|
const onChangeFirstSelect = useCallback(
|
|
305
317
|
(option) => {
|
|
306
318
|
if (!option) {
|
|
@@ -308,9 +320,13 @@ const BridgeForm = ({
|
|
|
308
320
|
}
|
|
309
321
|
setFirstToken(() => option);
|
|
310
322
|
updateUrlParams({ firstTokenId: option == null ? void 0 : option.address });
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
323
|
+
const availableTokens = getAvailableTokens(option);
|
|
324
|
+
const secondOption = availableTokens.find(
|
|
325
|
+
(x) => {
|
|
326
|
+
var _a2;
|
|
327
|
+
return x.symbol.toLowerCase() === ((_a2 = availableTokens == null ? void 0 : availableTokens[0]) == null ? void 0 : _a2.symbol.toLowerCase());
|
|
328
|
+
}
|
|
329
|
+
) ?? getDefaultReceivingToken(availableTokens);
|
|
314
330
|
if (!secondOption) {
|
|
315
331
|
return;
|
|
316
332
|
}
|
|
@@ -339,7 +355,7 @@ const BridgeForm = ({
|
|
|
339
355
|
);
|
|
340
356
|
const setInitialSelectedTokens = () => {
|
|
341
357
|
var _a2, _b2, _c2, _d2;
|
|
342
|
-
if (isTokensLoading) {
|
|
358
|
+
if (isTokensLoading || initializedInitialTokensRef.current) {
|
|
343
359
|
return;
|
|
344
360
|
}
|
|
345
361
|
const initialTokens = getInitialTokens();
|
|
@@ -350,31 +366,37 @@ const BridgeForm = ({
|
|
|
350
366
|
var _a3;
|
|
351
367
|
return option.chainId.toString() === ((_a3 = activeChain == null ? void 0 : activeChain.id) == null ? void 0 : _a3.toString());
|
|
352
368
|
}
|
|
353
|
-
);
|
|
354
|
-
const
|
|
369
|
+
) ?? (fromOptions == null ? void 0 : fromOptions[0]);
|
|
370
|
+
const availableTokens = getAvailableTokens(firstOption);
|
|
371
|
+
const secondOption = (availableTokens == null ? void 0 : availableTokens.find(
|
|
355
372
|
({ address }) => {
|
|
356
373
|
var _a3;
|
|
357
374
|
return address.toLowerCase() === ((_a3 = (firstOption == null ? void 0 : firstOption.symbol) ?? (initialTokens == null ? void 0 : initialTokens.secondTokenId)) == null ? void 0 : _a3.toLowerCase());
|
|
358
375
|
}
|
|
359
|
-
)) ??
|
|
376
|
+
)) ?? availableTokens.find(
|
|
360
377
|
(x) => x.symbol.toLowerCase() === (firstOption == null ? void 0 : firstOption.symbol.toLowerCase())
|
|
361
|
-
) ??
|
|
378
|
+
) ?? getDefaultReceivingToken(availableTokens);
|
|
362
379
|
const hasOptionsSelected = Boolean(firstToken) && Boolean(secondToken) && ((_a2 = firstToken == null ? void 0 : firstToken.address) == null ? void 0 : _a2.toLowerCase()) === ((_b2 = firstOption == null ? void 0 : firstOption.address) == null ? void 0 : _b2.toLowerCase()) && ((_c2 = secondToken == null ? void 0 : secondToken.address) == null ? void 0 : _c2.toLowerCase()) === ((_d2 = secondOption == null ? void 0 : secondOption.address) == null ? void 0 : _d2.toLowerCase());
|
|
363
380
|
if (hasOptionsSelected) {
|
|
364
381
|
return;
|
|
365
382
|
}
|
|
383
|
+
let initializedFirstToken = false;
|
|
366
384
|
if (firstOption) {
|
|
367
385
|
setFirstToken(firstOption);
|
|
368
386
|
updateUrlParams({
|
|
369
387
|
firstTokenId: firstOption == null ? void 0 : firstOption.address
|
|
370
388
|
});
|
|
389
|
+
initializedFirstToken = true;
|
|
371
390
|
}
|
|
391
|
+
let initializedSecondToken = false;
|
|
372
392
|
if (secondOption) {
|
|
373
393
|
setSecondToken(secondOption);
|
|
374
394
|
updateUrlParams({
|
|
375
395
|
secondTokenId: secondOption == null ? void 0 : secondOption.address
|
|
376
396
|
});
|
|
397
|
+
initializedSecondToken = true;
|
|
377
398
|
}
|
|
399
|
+
initializedInitialTokensRef.current = initializedFirstToken && initializedSecondToken;
|
|
378
400
|
};
|
|
379
401
|
const onSubmit = useCallback(
|
|
380
402
|
async ({
|
|
@@ -388,14 +410,42 @@ const BridgeForm = ({
|
|
|
388
410
|
let txIndex = -1;
|
|
389
411
|
for (const transaction of transactions) {
|
|
390
412
|
++txIndex;
|
|
391
|
-
let txHash;
|
|
392
413
|
try {
|
|
393
414
|
switch (selectedChainOption == null ? void 0 : selectedChainOption.chainType) {
|
|
415
|
+
case ChainType.evm:
|
|
416
|
+
const hash = await evm.signTransaction({
|
|
417
|
+
...transaction,
|
|
418
|
+
value: BigInt(transaction.value),
|
|
419
|
+
gas: BigInt(transaction.gasLimit),
|
|
420
|
+
account: bridgeAddress
|
|
421
|
+
});
|
|
422
|
+
if (!hash) {
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
signedTransactions.push({
|
|
426
|
+
...transaction,
|
|
427
|
+
txHash: hash
|
|
428
|
+
});
|
|
429
|
+
if (txIndex === transactions.length - 1 || !hash) {
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
const transactionReceipt = await waitForTransactionReceipt(
|
|
433
|
+
config,
|
|
434
|
+
{
|
|
435
|
+
confirmations: 1,
|
|
436
|
+
hash
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
console.info({
|
|
440
|
+
transactionReceipt,
|
|
441
|
+
hash
|
|
442
|
+
});
|
|
443
|
+
break;
|
|
394
444
|
case ChainType.sol:
|
|
395
445
|
if (!transaction.instructions || !transaction.feePayer) {
|
|
396
446
|
break;
|
|
397
447
|
}
|
|
398
|
-
txHash = await solana.signTransaction({
|
|
448
|
+
const txHash = await solana.signTransaction({
|
|
399
449
|
feePayer: transaction.feePayer,
|
|
400
450
|
instructions: transaction.instructions
|
|
401
451
|
});
|
|
@@ -407,16 +457,20 @@ const BridgeForm = ({
|
|
|
407
457
|
txHash
|
|
408
458
|
});
|
|
409
459
|
break;
|
|
410
|
-
case ChainType.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
460
|
+
case ChainType.btc:
|
|
461
|
+
if (!transaction.bitcoinParams) {
|
|
462
|
+
console.error("No bitcoin params");
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
console.log({
|
|
466
|
+
transaction
|
|
416
467
|
});
|
|
468
|
+
const psbt = await bitcoin.signTransaction(
|
|
469
|
+
transaction.bitcoinParams
|
|
470
|
+
);
|
|
417
471
|
signedTransactions.push({
|
|
418
472
|
...transaction,
|
|
419
|
-
txHash
|
|
473
|
+
txHash: psbt
|
|
420
474
|
});
|
|
421
475
|
break;
|
|
422
476
|
default:
|
|
@@ -427,17 +481,6 @@ const BridgeForm = ({
|
|
|
427
481
|
setSigningTransactionsCount(
|
|
428
482
|
() => transactions.length - 1 - txIndex
|
|
429
483
|
);
|
|
430
|
-
if (txIndex === transactions.length - 1 || !txHash || (selectedChainOption == null ? void 0 : selectedChainOption.chainType) !== ChainType.evm) {
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
const transactionReceipt = await waitForTransactionReceipt(config, {
|
|
434
|
-
confirmations: 1,
|
|
435
|
-
hash: txHash
|
|
436
|
-
});
|
|
437
|
-
console.info({
|
|
438
|
-
transactionReceipt,
|
|
439
|
-
hash: txHash
|
|
440
|
-
});
|
|
441
484
|
} catch (e) {
|
|
442
485
|
toast.dismiss();
|
|
443
486
|
toast.error("Transaction aborted");
|
|
@@ -528,12 +571,7 @@ const BridgeForm = ({
|
|
|
528
571
|
setSecondAmount("0");
|
|
529
572
|
}
|
|
530
573
|
}, [rateValidationError]);
|
|
531
|
-
useEffect(setInitialSelectedTokens, [
|
|
532
|
-
isTokensLoading,
|
|
533
|
-
fromOptions,
|
|
534
|
-
toOptions,
|
|
535
|
-
chainId
|
|
536
|
-
]);
|
|
574
|
+
useEffect(setInitialSelectedTokens, [isTokensLoading, fromOptions]);
|
|
537
575
|
useEffect(() => {
|
|
538
576
|
const selectedTokenOption = evmTokensWithBalances == null ? void 0 : evmTokensWithBalances.find(
|
|
539
577
|
(x) => x.address === (firstToken == null ? void 0 : firstToken.address)
|
package/reactjs/hooks/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const reactjs_hooks_validation_useSecondAmountSchema = require("./validation/use
|
|
|
6
6
|
const reactjs_hooks_validation_useTestHasEnoughFunds = require("./validation/useTestHasEnoughFunds.js");
|
|
7
7
|
const reactjs_hooks_validation_useTestIsConnected = require("./validation/useTestIsConnected.js");
|
|
8
8
|
const reactjs_hooks_useAccount = require("./useAccount.js");
|
|
9
|
-
const reactjs_hooks_useBalances = require("../../useBalances-
|
|
9
|
+
const reactjs_hooks_useBalances = require("../../useBalances-D7Fze-E_.js");
|
|
10
10
|
const reactjs_hooks_useBridgeFormik = require("./useBridgeFormik.js");
|
|
11
11
|
const reactjs_hooks_useDebounce = require("./useDebounce.js");
|
|
12
12
|
const reactjs_hooks_useFetchBridgeData = require("./useFetchBridgeData.js");
|
package/reactjs/hooks/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { useSecondAmountSchema } from "./validation/useSecondAmountSchema.mjs";
|
|
|
3
3
|
import { useTestHasEnoughFunds } from "./validation/useTestHasEnoughFunds.mjs";
|
|
4
4
|
import { useTestIsConnected } from "./validation/useTestIsConnected.mjs";
|
|
5
5
|
import { useAccount } from "./useAccount.mjs";
|
|
6
|
-
import { u } from "../../useBalances-
|
|
6
|
+
import { u } from "../../useBalances-B7J7g6dD.mjs";
|
|
7
7
|
import { BridgeFormikValuesEnum, useBridgeFormik } from "./useBridgeFormik.mjs";
|
|
8
8
|
import { useDebounce } from "./useDebounce.mjs";
|
|
9
9
|
import { useFetchBridgeData } from "./useFetchBridgeData.mjs";
|
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
require("@reown/appkit/react");
|
|
5
5
|
require("@solana/web3.js");
|
|
6
|
+
require("axios");
|
|
6
7
|
require("react");
|
|
8
|
+
require("../../helpers/getApiURL.js");
|
|
7
9
|
require("./useGetChainId.js");
|
|
10
|
+
require("../../types/chainType.js");
|
|
8
11
|
require("../context/useWeb3App.js");
|
|
9
12
|
require("@tanstack/react-query");
|
|
10
|
-
require("axios");
|
|
11
13
|
require("../queries/useGetChains.query.js");
|
|
12
14
|
require("yup");
|
|
13
15
|
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
14
16
|
require("../../bignumber-B8vjg9qn.js");
|
|
15
17
|
require("wagmi");
|
|
16
|
-
const reactjs_hooks_useBalances = require("../../useBalances-
|
|
18
|
+
const reactjs_hooks_useBalances = require("../../useBalances-D7Fze-E_.js");
|
|
17
19
|
require("formik");
|
|
18
20
|
require("../constants/index.js");
|
|
19
21
|
require("@reown/appkit-adapter-solana/react");
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import "@reown/appkit/react";
|
|
2
2
|
import "@solana/web3.js";
|
|
3
|
+
import "axios";
|
|
3
4
|
import "react";
|
|
5
|
+
import "../../helpers/getApiURL.mjs";
|
|
4
6
|
import "./useGetChainId.mjs";
|
|
7
|
+
import "../../types/chainType.mjs";
|
|
5
8
|
import "../context/useWeb3App.mjs";
|
|
6
9
|
import "@tanstack/react-query";
|
|
7
|
-
import "axios";
|
|
8
10
|
import "../queries/useGetChains.query.mjs";
|
|
9
11
|
import "yup";
|
|
10
12
|
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
11
13
|
import "../../bignumber-CKZkoo0g.mjs";
|
|
12
14
|
import "wagmi";
|
|
13
|
-
import { u } from "../../useBalances-
|
|
15
|
+
import { u } from "../../useBalances-B7J7g6dD.mjs";
|
|
14
16
|
import "formik";
|
|
15
17
|
import "../constants/index.mjs";
|
|
16
18
|
import "@reown/appkit-adapter-solana/react";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ServerTransactionInstruction } from '../../types';
|
|
2
2
|
import { Provider } from '@reown/appkit-adapter-solana/react';
|
|
3
|
+
import { BitcoinConnector } from '@reown/appkit-adapter-bitcoin';
|
|
3
4
|
|
|
4
5
|
export declare const useSignTransaction: () => {
|
|
5
6
|
evm: {
|
|
@@ -79,4 +80,16 @@ export declare const useSignTransaction: () => {
|
|
|
79
80
|
connection: import('@solana/web3.js').Connection | undefined;
|
|
80
81
|
walletProvider: Provider;
|
|
81
82
|
};
|
|
83
|
+
bitcoin: {
|
|
84
|
+
signTransaction: (params: {
|
|
85
|
+
psbt: string;
|
|
86
|
+
signInputs: {
|
|
87
|
+
address: string;
|
|
88
|
+
index: number;
|
|
89
|
+
sighashTypes: number[];
|
|
90
|
+
}[];
|
|
91
|
+
broadcast: boolean;
|
|
92
|
+
}) => Promise<string>;
|
|
93
|
+
walletProvider: BitcoinConnector;
|
|
94
|
+
};
|
|
82
95
|
};
|
|
@@ -12,11 +12,12 @@ const useSignTransaction = () => {
|
|
|
12
12
|
...rest
|
|
13
13
|
} = wagmi.useSendTransaction();
|
|
14
14
|
const { connection } = react.useAppKitConnection();
|
|
15
|
-
const { walletProvider } = react$1.useAppKitProvider("solana");
|
|
16
|
-
|
|
15
|
+
const { walletProvider: solWalletProvider } = react$1.useAppKitProvider("solana");
|
|
16
|
+
const { walletProvider: btcWalletProvider } = react$1.useAppKitProvider("bip122");
|
|
17
|
+
const signTransactionSolanaTransaction = async ({
|
|
17
18
|
feePayer,
|
|
18
19
|
instructions
|
|
19
|
-
}) {
|
|
20
|
+
}) => {
|
|
20
21
|
for (const instruction of instructions) {
|
|
21
22
|
const instructionData = Buffer.from(instruction.data);
|
|
22
23
|
const sender = new web3_js.PublicKey(instruction.keys[0].pubkey);
|
|
@@ -34,9 +35,17 @@ const useSignTransaction = () => {
|
|
|
34
35
|
if (connection) {
|
|
35
36
|
transaction.recentBlockhash = (await connection.getLatestBlockhash("confirmed")).blockhash;
|
|
36
37
|
}
|
|
37
|
-
return await
|
|
38
|
+
return await solWalletProvider.signAndSendTransaction(transaction);
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
};
|
|
41
|
+
const signPSBT = async (params) => {
|
|
42
|
+
if (!btcWalletProvider) {
|
|
43
|
+
throw Error("user is disconnected");
|
|
44
|
+
}
|
|
45
|
+
params.signInputs = [];
|
|
46
|
+
const signature = await btcWalletProvider.signPSBT(params);
|
|
47
|
+
return signature.psbt;
|
|
48
|
+
};
|
|
40
49
|
return {
|
|
41
50
|
evm: {
|
|
42
51
|
hash,
|
|
@@ -46,7 +55,11 @@ const useSignTransaction = () => {
|
|
|
46
55
|
solana: {
|
|
47
56
|
signTransaction: signTransactionSolanaTransaction,
|
|
48
57
|
connection,
|
|
49
|
-
walletProvider
|
|
58
|
+
walletProvider: solWalletProvider
|
|
59
|
+
},
|
|
60
|
+
bitcoin: {
|
|
61
|
+
signTransaction: signPSBT,
|
|
62
|
+
walletProvider: btcWalletProvider
|
|
50
63
|
}
|
|
51
64
|
};
|
|
52
65
|
};
|
|
@@ -9,11 +9,12 @@ const useSignTransaction = () => {
|
|
|
9
9
|
...rest
|
|
10
10
|
} = useSendTransaction();
|
|
11
11
|
const { connection } = useAppKitConnection();
|
|
12
|
-
const { walletProvider } = useAppKitProvider("solana");
|
|
13
|
-
|
|
12
|
+
const { walletProvider: solWalletProvider } = useAppKitProvider("solana");
|
|
13
|
+
const { walletProvider: btcWalletProvider } = useAppKitProvider("bip122");
|
|
14
|
+
const signTransactionSolanaTransaction = async ({
|
|
14
15
|
feePayer,
|
|
15
16
|
instructions
|
|
16
|
-
}) {
|
|
17
|
+
}) => {
|
|
17
18
|
for (const instruction of instructions) {
|
|
18
19
|
const instructionData = Buffer.from(instruction.data);
|
|
19
20
|
const sender = new PublicKey(instruction.keys[0].pubkey);
|
|
@@ -31,9 +32,17 @@ const useSignTransaction = () => {
|
|
|
31
32
|
if (connection) {
|
|
32
33
|
transaction.recentBlockhash = (await connection.getLatestBlockhash("confirmed")).blockhash;
|
|
33
34
|
}
|
|
34
|
-
return await
|
|
35
|
+
return await solWalletProvider.signAndSendTransaction(transaction);
|
|
35
36
|
}
|
|
36
|
-
}
|
|
37
|
+
};
|
|
38
|
+
const signPSBT = async (params) => {
|
|
39
|
+
if (!btcWalletProvider) {
|
|
40
|
+
throw Error("user is disconnected");
|
|
41
|
+
}
|
|
42
|
+
params.signInputs = [];
|
|
43
|
+
const signature = await btcWalletProvider.signPSBT(params);
|
|
44
|
+
return signature.psbt;
|
|
45
|
+
};
|
|
37
46
|
return {
|
|
38
47
|
evm: {
|
|
39
48
|
hash,
|
|
@@ -43,7 +52,11 @@ const useSignTransaction = () => {
|
|
|
43
52
|
solana: {
|
|
44
53
|
signTransaction: signTransactionSolanaTransaction,
|
|
45
54
|
connection,
|
|
46
|
-
walletProvider
|
|
55
|
+
walletProvider: solWalletProvider
|
|
56
|
+
},
|
|
57
|
+
bitcoin: {
|
|
58
|
+
signTransaction: signPSBT,
|
|
59
|
+
walletProvider: btcWalletProvider
|
|
47
60
|
}
|
|
48
61
|
};
|
|
49
62
|
};
|
package/reactjs/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const reactjs_hooks_validation_useSecondAmountSchema = require("./hooks/validati
|
|
|
36
36
|
const reactjs_hooks_validation_useTestHasEnoughFunds = require("./hooks/validation/useTestHasEnoughFunds.js");
|
|
37
37
|
const reactjs_hooks_validation_useTestIsConnected = require("./hooks/validation/useTestIsConnected.js");
|
|
38
38
|
const reactjs_hooks_useAccount = require("./hooks/useAccount.js");
|
|
39
|
-
const reactjs_hooks_useBalances = require("../useBalances-
|
|
39
|
+
const reactjs_hooks_useBalances = require("../useBalances-D7Fze-E_.js");
|
|
40
40
|
const reactjs_hooks_useBridgeFormik = require("./hooks/useBridgeFormik.js");
|
|
41
41
|
const reactjs_hooks_useDebounce = require("./hooks/useDebounce.js");
|
|
42
42
|
const reactjs_hooks_useFetchBridgeData = require("./hooks/useFetchBridgeData.js");
|
package/reactjs/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ import { useSecondAmountSchema } from "./hooks/validation/useSecondAmountSchema.
|
|
|
33
33
|
import { useTestHasEnoughFunds } from "./hooks/validation/useTestHasEnoughFunds.mjs";
|
|
34
34
|
import { useTestIsConnected } from "./hooks/validation/useTestIsConnected.mjs";
|
|
35
35
|
import { useAccount } from "./hooks/useAccount.mjs";
|
|
36
|
-
import { u } from "../useBalances-
|
|
36
|
+
import { u } from "../useBalances-B7J7g6dD.mjs";
|
|
37
37
|
import { BridgeFormikValuesEnum, useBridgeFormik } from "./hooks/useBridgeFormik.mjs";
|
|
38
38
|
import { useDebounce } from "./hooks/useDebounce.mjs";
|
|
39
39
|
import { useFetchBridgeData } from "./hooks/useFetchBridgeData.mjs";
|
|
@@ -9,7 +9,7 @@ require("react");
|
|
|
9
9
|
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
10
10
|
require("../../bignumber-B8vjg9qn.js");
|
|
11
11
|
require("wagmi");
|
|
12
|
-
const reactjs_hooks_useBalances = require("../../useBalances-
|
|
12
|
+
const reactjs_hooks_useBalances = require("../../useBalances-D7Fze-E_.js");
|
|
13
13
|
require("formik");
|
|
14
14
|
require("axios");
|
|
15
15
|
require("../context/Web3AppProvider.js");
|
|
@@ -6,7 +6,7 @@ import "react";
|
|
|
6
6
|
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
7
7
|
import "../../bignumber-CKZkoo0g.mjs";
|
|
8
8
|
import "wagmi";
|
|
9
|
-
import { u as useBalances } from "../../useBalances-
|
|
9
|
+
import { u as useBalances } from "../../useBalances-B7J7g6dD.mjs";
|
|
10
10
|
import "formik";
|
|
11
11
|
import "axios";
|
|
12
12
|
import "../context/Web3AppProvider.mjs";
|
package/types/transaction.d.ts
CHANGED
|
@@ -26,6 +26,15 @@ export type ServerTransaction = {
|
|
|
26
26
|
signatures?: string[];
|
|
27
27
|
feePayer?: string;
|
|
28
28
|
instructions?: ServerTransactionInstruction[];
|
|
29
|
+
bitcoinParams?: {
|
|
30
|
+
psbt: string;
|
|
31
|
+
signInputs: {
|
|
32
|
+
address: string;
|
|
33
|
+
index: number;
|
|
34
|
+
sighashTypes: number[];
|
|
35
|
+
}[];
|
|
36
|
+
broadcast: boolean;
|
|
37
|
+
};
|
|
29
38
|
};
|
|
30
39
|
export type TransactionType = TransactionBase & {
|
|
31
40
|
account: `0x${string}`;
|
package/types/utxo.d.ts
ADDED
package/types/utxo.js
ADDED
package/types/utxo.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { useAppKitAccount } from "@reown/appkit/react";
|
|
2
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import axios from "axios";
|
|
3
4
|
import { useMemo, useCallback } from "react";
|
|
5
|
+
import { getApiURL } from "./helpers/getApiURL.mjs";
|
|
4
6
|
import { useGetChainId } from "./reactjs/hooks/useGetChainId.mjs";
|
|
7
|
+
import { ChainType } from "./types/chainType.mjs";
|
|
5
8
|
import { useWeb3App } from "./reactjs/context/useWeb3App.mjs";
|
|
6
9
|
import "@tanstack/react-query";
|
|
7
|
-
import "axios";
|
|
8
10
|
import { useGetChainsQuery } from "./reactjs/queries/useGetChains.query.mjs";
|
|
9
11
|
import "yup";
|
|
10
12
|
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
@@ -180,26 +182,16 @@ const useBalances = () => {
|
|
|
180
182
|
const connection = new Connection(rpcUrl);
|
|
181
183
|
const publicKey = new PublicKey(addr);
|
|
182
184
|
const balance = await connection.getBalance(publicKey);
|
|
183
|
-
return
|
|
184
|
-
value: BigInt(balance.toString()),
|
|
185
|
-
decimals: 9,
|
|
186
|
-
formatted: (balance / 1e9).toString(),
|
|
187
|
-
symbol: "SOL"
|
|
188
|
-
};
|
|
185
|
+
return BigInt(balance.toString());
|
|
189
186
|
};
|
|
190
|
-
const getBtcBalance = async (
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
value: BigInt(balance.toString()),
|
|
199
|
-
decimals: 8,
|
|
200
|
-
formatted: (balance / 1e8).toString(),
|
|
201
|
-
symbol: "BTC"
|
|
202
|
-
};
|
|
187
|
+
const getBtcBalance = async () => {
|
|
188
|
+
const url = `${getApiURL()}/user/balance/${address}`;
|
|
189
|
+
try {
|
|
190
|
+
const { data } = await axios.get(url);
|
|
191
|
+
return BigInt(data.balance);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error(`Error fetching BTC balance: ${error}`);
|
|
194
|
+
}
|
|
203
195
|
};
|
|
204
196
|
const fetchBalances = useCallback(
|
|
205
197
|
async ({ tokens }) => {
|
|
@@ -212,29 +204,30 @@ const useBalances = () => {
|
|
|
212
204
|
};
|
|
213
205
|
}
|
|
214
206
|
try {
|
|
215
|
-
let balance;
|
|
207
|
+
let balance = BigInt(0);
|
|
216
208
|
switch (activeChain == null ? void 0 : activeChain.chainType) {
|
|
217
|
-
case
|
|
218
|
-
balance = await getBalance(config, {
|
|
209
|
+
case ChainType.evm:
|
|
210
|
+
balance = (await getBalance(config, {
|
|
219
211
|
address,
|
|
220
212
|
chainId: Number(chainId),
|
|
221
213
|
// omit passing the token for fetching the native currency balance
|
|
222
214
|
token: token.isNative ? void 0 : token.address
|
|
223
|
-
});
|
|
215
|
+
})).value;
|
|
224
216
|
break;
|
|
225
|
-
case
|
|
217
|
+
case ChainType.sol:
|
|
226
218
|
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
227
219
|
throw new Error(`RPC URL not found for chain ID: ${chainId}`);
|
|
228
220
|
}
|
|
229
221
|
balance = await getSolBalance(activeChain == null ? void 0 : activeChain.rpc, address);
|
|
230
222
|
break;
|
|
231
|
-
case
|
|
223
|
+
case ChainType.btc:
|
|
232
224
|
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
233
225
|
throw new Error(`RPC URL not found for chain ID: ${chainId}`);
|
|
234
226
|
}
|
|
235
|
-
balance = await getBtcBalance(
|
|
227
|
+
balance = await getBtcBalance();
|
|
228
|
+
break;
|
|
229
|
+
case ChainType.mvx:
|
|
236
230
|
break;
|
|
237
|
-
case "mvx":
|
|
238
231
|
default:
|
|
239
232
|
throw new Error(
|
|
240
233
|
`Unsupported chain type: ${activeChain == null ? void 0 : activeChain.chainType}`
|
|
@@ -242,7 +235,7 @@ const useBalances = () => {
|
|
|
242
235
|
}
|
|
243
236
|
return {
|
|
244
237
|
tokenId: token.address,
|
|
245
|
-
balance: balance.
|
|
238
|
+
balance: balance == null ? void 0 : balance.toString()
|
|
246
239
|
};
|
|
247
240
|
} catch (error) {
|
|
248
241
|
console.warn("Error fetching balance for: ", token.address, error);
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const react = require("@reown/appkit/react");
|
|
4
4
|
const web3_js = require("@solana/web3.js");
|
|
5
|
+
const axios = require("axios");
|
|
5
6
|
const React = require("react");
|
|
7
|
+
const helpers_getApiURL = require("./helpers/getApiURL.js");
|
|
6
8
|
const reactjs_hooks_useGetChainId = require("./reactjs/hooks/useGetChainId.js");
|
|
9
|
+
const types_chainType = require("./types/chainType.js");
|
|
7
10
|
const reactjs_context_useWeb3App = require("./reactjs/context/useWeb3App.js");
|
|
8
11
|
require("@tanstack/react-query");
|
|
9
|
-
require("axios");
|
|
10
12
|
const reactjs_queries_useGetChains_query = require("./reactjs/queries/useGetChains.query.js");
|
|
11
13
|
require("yup");
|
|
12
14
|
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
@@ -182,26 +184,16 @@ const useBalances = () => {
|
|
|
182
184
|
const connection = new web3_js.Connection(rpcUrl);
|
|
183
185
|
const publicKey = new web3_js.PublicKey(addr);
|
|
184
186
|
const balance = await connection.getBalance(publicKey);
|
|
185
|
-
return
|
|
186
|
-
value: BigInt(balance.toString()),
|
|
187
|
-
decimals: 9,
|
|
188
|
-
formatted: (balance / 1e9).toString(),
|
|
189
|
-
symbol: "SOL"
|
|
190
|
-
};
|
|
187
|
+
return BigInt(balance.toString());
|
|
191
188
|
};
|
|
192
|
-
const getBtcBalance = async (
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
value: BigInt(balance.toString()),
|
|
201
|
-
decimals: 8,
|
|
202
|
-
formatted: (balance / 1e8).toString(),
|
|
203
|
-
symbol: "BTC"
|
|
204
|
-
};
|
|
189
|
+
const getBtcBalance = async () => {
|
|
190
|
+
const url = `${helpers_getApiURL.getApiURL()}/user/balance/${address}`;
|
|
191
|
+
try {
|
|
192
|
+
const { data } = await axios.get(url);
|
|
193
|
+
return BigInt(data.balance);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new Error(`Error fetching BTC balance: ${error}`);
|
|
196
|
+
}
|
|
205
197
|
};
|
|
206
198
|
const fetchBalances = React.useCallback(
|
|
207
199
|
async ({ tokens }) => {
|
|
@@ -214,29 +206,30 @@ const useBalances = () => {
|
|
|
214
206
|
};
|
|
215
207
|
}
|
|
216
208
|
try {
|
|
217
|
-
let balance;
|
|
209
|
+
let balance = BigInt(0);
|
|
218
210
|
switch (activeChain == null ? void 0 : activeChain.chainType) {
|
|
219
|
-
case
|
|
220
|
-
balance = await getBalance(config, {
|
|
211
|
+
case types_chainType.ChainType.evm:
|
|
212
|
+
balance = (await getBalance(config, {
|
|
221
213
|
address,
|
|
222
214
|
chainId: Number(chainId),
|
|
223
215
|
// omit passing the token for fetching the native currency balance
|
|
224
216
|
token: token.isNative ? void 0 : token.address
|
|
225
|
-
});
|
|
217
|
+
})).value;
|
|
226
218
|
break;
|
|
227
|
-
case
|
|
219
|
+
case types_chainType.ChainType.sol:
|
|
228
220
|
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
229
221
|
throw new Error(`RPC URL not found for chain ID: ${chainId}`);
|
|
230
222
|
}
|
|
231
223
|
balance = await getSolBalance(activeChain == null ? void 0 : activeChain.rpc, address);
|
|
232
224
|
break;
|
|
233
|
-
case
|
|
225
|
+
case types_chainType.ChainType.btc:
|
|
234
226
|
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
235
227
|
throw new Error(`RPC URL not found for chain ID: ${chainId}`);
|
|
236
228
|
}
|
|
237
|
-
balance = await getBtcBalance(
|
|
229
|
+
balance = await getBtcBalance();
|
|
230
|
+
break;
|
|
231
|
+
case types_chainType.ChainType.mvx:
|
|
238
232
|
break;
|
|
239
|
-
case "mvx":
|
|
240
233
|
default:
|
|
241
234
|
throw new Error(
|
|
242
235
|
`Unsupported chain type: ${activeChain == null ? void 0 : activeChain.chainType}`
|
|
@@ -244,7 +237,7 @@ const useBalances = () => {
|
|
|
244
237
|
}
|
|
245
238
|
return {
|
|
246
239
|
tokenId: token.address,
|
|
247
|
-
balance: balance.
|
|
240
|
+
balance: balance == null ? void 0 : balance.toString()
|
|
248
241
|
};
|
|
249
242
|
} catch (error) {
|
|
250
243
|
console.warn("Error fetching balance for: ", token.address, error);
|