@rash2x/bridge-widget 0.5.1 → 0.5.6
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/README.md +73 -2
- package/dist/evaa-bridge.cjs +1 -1
- package/dist/evaa-bridge.mjs +1 -1
- package/dist/{index-C0llk2Pm.cjs → index-BXUBhn_o.cjs} +528 -121
- package/dist/index-BXUBhn_o.cjs.map +1 -0
- package/dist/{index-CwCBOFR2.js → index-Bj6AJLyW.js} +2 -2
- package/dist/{index-CwCBOFR2.js.map → index-Bj6AJLyW.js.map} +1 -1
- package/dist/{index-DedRamsD.cjs → index-CebGXD16.cjs} +2 -2
- package/dist/{index-DedRamsD.cjs.map → index-CebGXD16.cjs.map} +1 -1
- package/dist/{index-NQh101e3.js → index-w-PXiL0q.js} +528 -121
- package/dist/index-w-PXiL0q.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/dist/index-C0llk2Pm.cjs.map +0 -1
- package/dist/index-NQh101e3.js.map +0 -1
|
@@ -23,16 +23,19 @@ const lucideReact = require("lucide-react");
|
|
|
23
23
|
const framerMotion = require("framer-motion");
|
|
24
24
|
const accordion = require("@/components/ui/accordion");
|
|
25
25
|
const tooltip = require("@/components/ui/tooltip");
|
|
26
|
+
const alert = require("@/components/ui/alert");
|
|
26
27
|
const sonner = require("sonner");
|
|
27
28
|
const reactDialog = require("@radix-ui/react-dialog");
|
|
28
29
|
const viem = require("viem");
|
|
29
30
|
const tronwalletAdapters = require("@tronweb3/tronwallet-adapters");
|
|
31
|
+
const tronweb = require("tronweb");
|
|
30
32
|
const card = require("@/components/ui/card");
|
|
31
33
|
const badge = require("@/components/ui/badge");
|
|
32
34
|
const common$1 = { "connecting": "Connecting…", "initializing": "Initializing...", "loading": "Loading...", "paste": "paste", "close": "Close", "zeroPlaceholder": "0", "nativeToken": "Native Token" };
|
|
33
35
|
const wallets$1 = { "addTonWallet": "Add TON wallet", "addEvmWallet": "Add EVM wallet", "connectTonWallet": "Connect TON wallet", "connectEvmWallet": "Connect EVM wallet", "initializingMetamask": "Initializing MetaMask SDK...", "initializingTronlink": "Initializing TronLink...", "failedToConnectTon": "Failed to connect to TON wallet", "failedToDisconnect": "Failed to disconnect", "metamaskConnectionError": "MetaMask connection error", "failedToConnectMetamask": "Failed to connect to MetaMask", "failedToDisconnectMetamask": "Failed to disconnect from MetaMask", "selectWallet": "Select Wallet", "tonWallets": "TON", "evmWallets": "EVM", "tronWallets": "TRON", "tonconnect": "TonConnect", "metaMask": "WalletConnect", "walletConnect": "WalletConnect", "tronLink": "TronLink", "addTronWallet": "Add Tron wallet", "comingSoon": "Coming Soon", "connected": "CONNECTED", "disconnect": "Disconnect", "chooseWallet": "Choose wallet", "oneWalletPerEnv": "You can only connect one wallet per environment.", "connect": "Connect", "connectTronWallet": "Connect Tron wallet", "connectWallet": "Connect wallet" };
|
|
34
36
|
const bridge$1 = { "max": "Max", "sourceNetwork": "Source network", "destinationNetwork": "Destination network", "selectToken": "Select token", "selectNetwork": "Select network", "selectSourceNetwork": "Select source network", "selectDestinationNetwork": "Select destination network", "searchToken": "Search token", "myTokens": "My tokens", "allTokens": "All tokens", "search": "Search", "select": "Select", "willChangeSourceChain": "Will change source network", "willChangeSourceNetworkAndToken": "Will change source token", "noBalancesFound": "No balances found.", "noResults": "No results", "tokenNotFound": "We couldn't find a token with that name or symbol. Please try again.", "chainNotFound": "We couldn't find a chain with that name. Please try again.", "sendToAnotherAddress": "Send to another address", "youWillReceive": "You will receive", "anotherAddressPlaceholder": "Address", "addressDoesntMatch": "Address doesn't match the {{network}} network", "checkBeforeTransfer": "Check correctness before transfer" };
|
|
35
37
|
const transaction$1 = { "enterAmount": "Enter amount", "transfer": "Transfer", "getQuote": "Get quote", "failed": "Transaction Failed", "confirm": "Confirm transaction", "signTransaction": "Sign in transaction in wallet", "quoting": "Quoting...", "inProgress": "Processing...", "checkingBalance": "Checking balance...", "insufficientBalance": "Insufficient balance", "amountTooSmall": "Min {{min}}", "amountTooLarge": "Max {{max}}", "success": "Success", "successTitle": "Success", "done": "Done", "hashCopied": "Hash copied to clipboard", "bridged": "Bridged", "transferTitle": "Transfer", "hash": "Hash", "finalFee": "Final Fee", "route": "Route", "estTime": "Est. Time", "slippage": "Slippage", "minimumReceived": "Minimum received", "totalFee": "Total Fee", "noRouteFound": "No route found", "notEnoughGas": "Not enough gas", "noRouteFoundForSettings": "No route found for current settings.", "tryAdjustSettings": "Try disabling Gas on Destination, or adjust amount/networks.", "quoteError": "Quote error" };
|
|
38
|
+
const telegram$1 = { "openWebVersion": "Open EVAA Web to Bridge", "restrictionMessage": "You can bridge between the chosen networks on EVAA web version" };
|
|
36
39
|
const app$1 = { "stargateWidgetName": "Stargate Bridge Widget", "liveWidget": "Live Widget", "getStarted": "Get Started" };
|
|
37
40
|
const settings$1 = { "title": "Settings", "gasOnDestination": "Gas on destination", "slippageTolerance": "Slippage tolerance", "routePriority": "Route Priority", "highSlippageWarning": "High slippage warning", "gasPresets": { "auto": "Auto", "none": "None", "medium": "Medium", "max": "Max" }, "routePresets": { "fastest": "Fastest", "cheapest": "Cheapest", "recommended": "Recommended" } };
|
|
38
41
|
const errors$1 = { "WALLET_NOT_CONNECTED": "{{chainKey}} wallet not connected", "WALLET_CONNECTION_FAILED": "Failed to connect {{chainKey}} wallet", "WALLET_NOT_FOUND": "No {{chainKey}} wallet found. Please install a wallet extension.", "INVALID_ADDRESS": "Invalid {{chainKey}} address format", "INVALID_STEPS": "Invalid transaction steps for {{chainKey}}", "INVALID_TRANSACTION_DATA": "Invalid transaction data for {{chainKey}}", "TRANSACTION_REJECTED": "Transaction rejected by user", "TRANSACTION_FAILED": "Transaction failed", "TRANSACTION_TIMEOUT": "Transaction confirmation timeout", "TRANSACTION_REVERTED": "Transaction reverted on-chain", "INSUFFICIENT_GAS": "Insufficient {{chainKey}} gas", "PROVIDER_NOT_AVAILABLE": "{{chainKey}} provider not available", "NETWORK_REQUEST_FAILED": "Network request failed", "TRANSACTION_FAILED_TO_COMPLETE": "Transaction failed to complete", "COMPLETION_TRACKING_FAILED": "Completion tracking failed", "UNKNOWN_ERROR": "An unknown error occurred" };
|
|
@@ -41,6 +44,7 @@ const en$3 = {
|
|
|
41
44
|
wallets: wallets$1,
|
|
42
45
|
bridge: bridge$1,
|
|
43
46
|
transaction: transaction$1,
|
|
47
|
+
telegram: telegram$1,
|
|
44
48
|
app: app$1,
|
|
45
49
|
settings: settings$1,
|
|
46
50
|
errors: errors$1
|
|
@@ -49,6 +53,7 @@ const common = { "connecting": "Подключение…", "initializing": "И
|
|
|
49
53
|
const wallets = { "addTonWallet": "Добавить TON кошелёк", "addEvmWallet": "Добавить EVM кошелёк", "connectTonWallet": "Подключить TON кошелёк", "connectEvmWallet": "Подключить EVM кошелёк", "initializingMetamask": "Инициализация MetaMask SDK...", "initializingTronlink": "Инициализация TronLink...", "failedToConnectTon": "Не удалось подключиться к TON кошельку", "failedToDisconnect": "Не удалось отключиться", "metamaskConnectionError": "Ошибка подключения MetaMask", "failedToConnectMetamask": "Не удалось подключиться к MetaMask", "failedToDisconnectMetamask": "Не удалось отключиться от MetaMask", "selectWallet": "Выберите кошелёк", "tonWallets": "TON", "evmWallets": "EVM", "tronWallets": "TRON", "tonconnect": "TonConnect", "metaMask": "WalletConnect", "walletConnect": "WalletConnect", "tronLink": "TronLink", "addTronWallet": "Добавить Tron кошелёк", "comingSoon": "Скоро", "connected": "ПОДКЛЮЧЕНО", "disconnect": "Отключить", "chooseWallet": "Выберите кошелёк", "oneWalletPerEnv": "Можно подключить только один кошелёк на окружение.", "connect": "Подключить", "connectTronWallet": "Подключить Tron кошелёк", "connectWallet": "Подключить кошелёк" };
|
|
50
54
|
const bridge = { "max": "Макс", "sourceNetwork": "Исходная сеть", "destinationNetwork": "Целевая сеть", "selectToken": "Выбрать токен", "selectNetwork": "Выбрать сеть", "selectSourceNetwork": "Выбрать исходную сеть", "selectDestinationNetwork": "Выбрать целевую сеть", "searchToken": "Поиск токена", "myTokens": "Мои токены", "allTokens": "Все токены", "search": "Поиск", "select": "Выбрать", "willChangeSourceChain": "Сменит исходную сеть", "willChangeSourceNetworkAndToken": "Сменит исходный токен", "noBalancesFound": "Балансы не найдены.", "noResults": "Нет результатов", "tokenNotFound": "Мы не смогли найти токен с таким названием или символом. Пожалуйста, попробуйте снова.", "chainNotFound": "Мы не смогли найти сеть с таким названием. Пожалуйста, попробуйте снова.", "sendToAnotherAddress": "Отправить на другой адрес", "youWillReceive": "Вы получите", "anotherAddressPlaceholder": "Адрес", "addressDoesntMatch": "Адрес не соответствует сети {{network}}", "checkBeforeTransfer": "Проверьте корректность перед переводом" };
|
|
51
55
|
const transaction = { "enterAmount": "Введите сумму", "transfer": "Перевести", "getQuote": "Получить котировку", "quoting": "Расчет котировки...", "failed": "Ошибка транзакции", "confirm": "Подтвердите транзакцию", "signTransaction": "Подпишите транзакцию в кошельке", "inProgress": "Выполнение...", "checkingBalance": "Проверка баланса...", "insufficientBalance": "Недостаточно средств", "amountTooSmall": "Минимум {{min}}", "amountTooLarge": "Максимум {{max}}", "success": "Успех", "successTitle": "Успех", "done": "Готово", "hashCopied": "Хэш скопирован в буфер обмена", "bridged": "Переведено", "transferTitle": "Перевод", "hash": "Хэш", "finalFee": "Итоговая комиссия", "route": "Маршрут", "estTime": "Время", "slippage": "Проскальзывание", "minimumReceived": "Минимум к получению", "totalFee": "Общая комиссия", "noRouteFound": "Маршрут не найден", "notEnoughGas": "Недостаточно газа", "noRouteFoundForSettings": "Маршрут не найден для текущих настроек.", "tryAdjustSettings": "Попробуйте отключить Gas on Destination или измените сумму/сети.", "quoteError": "Ошибка котировки" };
|
|
56
|
+
const telegram = { "openWebVersion": "Открыть EVAA веб для трансфера", "restrictionMessage": "Трансфер между выбранными сетями доступен только в веб-версии EVAA" };
|
|
52
57
|
const app = { "stargateWidgetName": "Виджет Stargate Bridge", "liveWidget": "Живой виджет", "getStarted": "Начало работы" };
|
|
53
58
|
const settings = { "title": "Настройки", "gasOnDestination": "Газ на назначении", "slippageTolerance": "Толерантность к проскальзыванию", "routePriority": "Приоритет маршрута", "highSlippageWarning": "Высокое проскальзывание", "gasPresets": { "auto": "Авто", "none": "Нет", "medium": "Средний", "max": "Макс" }, "routePresets": { "fastest": "Быстрейший", "cheapest": "Дешевейший", "recommended": "Рекомендуемый" } };
|
|
54
59
|
const errors = { "WALLET_NOT_CONNECTED": "{{chainKey}} кошелёк не подключен", "WALLET_CONNECTION_FAILED": "Не удалось подключить {{chainKey}} кошелёк", "WALLET_NOT_FOUND": "{{chainKey}} кошелёк не найден. Пожалуйста, установите расширение кошелька.", "INVALID_ADDRESS": "Неверный формат {{chainKey}} адреса", "INVALID_STEPS": "Недопустимые шаги транзакции для {{chainKey}}", "INVALID_TRANSACTION_DATA": "Недопустимые данные транзакции для {{chainKey}}", "TRANSACTION_REJECTED": "Транзакция отклонена пользователем", "TRANSACTION_FAILED": "Транзакция не удалась", "TRANSACTION_TIMEOUT": "Время ожидания подтверждения транзакции истекло", "TRANSACTION_REVERTED": "Транзакция отменена в блокчейне", "INSUFFICIENT_GAS": "Недостаточно {{chainKey}} газа", "PROVIDER_NOT_AVAILABLE": "{{chainKey}} провайдер недоступен", "NETWORK_REQUEST_FAILED": "Сетевой запрос не удался", "TRANSACTION_FAILED_TO_COMPLETE": "Транзакция не завершилась", "COMPLETION_TRACKING_FAILED": "Отслеживание завершения не удалось", "UNKNOWN_ERROR": "Произошла неизвестная ошибка" };
|
|
@@ -57,6 +62,7 @@ const ru$1 = {
|
|
|
57
62
|
wallets,
|
|
58
63
|
bridge,
|
|
59
64
|
transaction,
|
|
65
|
+
telegram,
|
|
60
66
|
app,
|
|
61
67
|
settings,
|
|
62
68
|
errors
|
|
@@ -481,11 +487,40 @@ function fromLD(ld, decimals) {
|
|
|
481
487
|
const frac = Number(bi2 % base3) / Number(base3);
|
|
482
488
|
return Number(int) + frac;
|
|
483
489
|
}
|
|
490
|
+
const useTronWalletConnectStore = zustand.create(
|
|
491
|
+
(set2) => ({
|
|
492
|
+
address: null,
|
|
493
|
+
isConnected: false,
|
|
494
|
+
isConnecting: false,
|
|
495
|
+
connect: null,
|
|
496
|
+
disconnect: null,
|
|
497
|
+
signTransaction: null,
|
|
498
|
+
setAddress: (address) => set2({
|
|
499
|
+
address,
|
|
500
|
+
isConnected: !!address
|
|
501
|
+
}),
|
|
502
|
+
setIsConnecting: (connecting) => set2({ isConnecting: connecting }),
|
|
503
|
+
setActions: (actions) => set2({
|
|
504
|
+
connect: actions.connect,
|
|
505
|
+
disconnect: actions.disconnect,
|
|
506
|
+
signTransaction: actions.signTransaction
|
|
507
|
+
}),
|
|
508
|
+
reset: () => set2({
|
|
509
|
+
address: null,
|
|
510
|
+
isConnected: false,
|
|
511
|
+
isConnecting: false
|
|
512
|
+
})
|
|
513
|
+
})
|
|
514
|
+
);
|
|
484
515
|
function useAddresses() {
|
|
485
516
|
const { fromChain, toChain } = useChainsStore();
|
|
486
517
|
const { address: evmAddress } = wagmi.useAccount();
|
|
487
518
|
const tonAddress = uiReact.useTonAddress();
|
|
488
|
-
const { address:
|
|
519
|
+
const { address: tronLinkAddress } = tronwalletAdapterReactHooks.useWallet();
|
|
520
|
+
const tronWalletConnectAddress = useTronWalletConnectStore(
|
|
521
|
+
(state2) => state2.address
|
|
522
|
+
);
|
|
523
|
+
const tronAddress = tronLinkAddress || tronWalletConnectAddress || void 0;
|
|
489
524
|
const srcAddress = react.useMemo(() => {
|
|
490
525
|
if (!fromChain?.chainKey) return void 0;
|
|
491
526
|
const chainKey = fromChain.chainKey.toLowerCase();
|
|
@@ -822,7 +857,14 @@ const isEvmAddress = (addr) => {
|
|
|
822
857
|
return /^0x[0-9a-fA-F]{40}$/.test(addr ?? "");
|
|
823
858
|
};
|
|
824
859
|
const isTronAddress = (addr) => {
|
|
825
|
-
|
|
860
|
+
if (!addr) return false;
|
|
861
|
+
const trimmed = addr.trim();
|
|
862
|
+
if (/^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(trimmed)) {
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
const normalized = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed.startsWith("41") ? trimmed : "";
|
|
866
|
+
if (!normalized) return false;
|
|
867
|
+
return /^41[0-9a-fA-F]{40}$/.test(normalized);
|
|
826
868
|
};
|
|
827
869
|
const isTonAddress = (addr) => {
|
|
828
870
|
if (!addr) return false;
|
|
@@ -2331,6 +2373,7 @@ const TokenInput = react.forwardRef(
|
|
|
2331
2373
|
({
|
|
2332
2374
|
value,
|
|
2333
2375
|
onAmountChange,
|
|
2376
|
+
onAmountBlur,
|
|
2334
2377
|
showSkeleton = false,
|
|
2335
2378
|
className,
|
|
2336
2379
|
max,
|
|
@@ -2354,6 +2397,7 @@ const TokenInput = react.forwardRef(
|
|
|
2354
2397
|
if (showSkeleton && readOnly) {
|
|
2355
2398
|
return /* @__PURE__ */ jsxRuntime.jsx(skeleton.Skeleton, { className: utils$1.cn("h-8 my-2 w-1/3 bg-secondary rounded-md", className) });
|
|
2356
2399
|
}
|
|
2400
|
+
const { onBlur: restOnBlur, ...restWithoutOnBlur } = rest;
|
|
2357
2401
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2358
2402
|
input.Input,
|
|
2359
2403
|
{
|
|
@@ -2370,7 +2414,11 @@ const TokenInput = react.forwardRef(
|
|
|
2370
2414
|
className
|
|
2371
2415
|
),
|
|
2372
2416
|
max,
|
|
2373
|
-
...
|
|
2417
|
+
...restWithoutOnBlur,
|
|
2418
|
+
onBlur: (e2) => {
|
|
2419
|
+
restOnBlur?.(e2);
|
|
2420
|
+
onAmountBlur?.();
|
|
2421
|
+
}
|
|
2374
2422
|
}
|
|
2375
2423
|
) });
|
|
2376
2424
|
}
|
|
@@ -2740,7 +2788,8 @@ const SwapSection = ({
|
|
|
2740
2788
|
disableNetworkSelect,
|
|
2741
2789
|
isSource,
|
|
2742
2790
|
onSelect,
|
|
2743
|
-
onAmountChange
|
|
2791
|
+
onAmountChange,
|
|
2792
|
+
onAmountBlur
|
|
2744
2793
|
}) => {
|
|
2745
2794
|
const { isOpen, onClose, onOpen } = useModal();
|
|
2746
2795
|
const { assetMatrix, selectedAssetSymbol } = useTokensStore();
|
|
@@ -2811,6 +2860,7 @@ const SwapSection = ({
|
|
|
2811
2860
|
(v3) => onAmountChange?.(v3),
|
|
2812
2861
|
[onAmountChange]
|
|
2813
2862
|
),
|
|
2863
|
+
onAmountBlur,
|
|
2814
2864
|
readOnly: !!readOnlyAmount,
|
|
2815
2865
|
showSkeleton: status === "loading",
|
|
2816
2866
|
className: "p-0",
|
|
@@ -3392,12 +3442,9 @@ class TransactionRevertedError extends ChainStrategyError {
|
|
|
3392
3442
|
}
|
|
3393
3443
|
}
|
|
3394
3444
|
class ProviderNotAvailableError extends ChainStrategyError {
|
|
3395
|
-
constructor(chainKey) {
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
"PROVIDER_NOT_AVAILABLE",
|
|
3399
|
-
chainKey
|
|
3400
|
-
);
|
|
3445
|
+
constructor(chainKey, reason) {
|
|
3446
|
+
const message = reason ? `${chainKey.toUpperCase()} provider not available: ${reason}` : `${chainKey.toUpperCase()} provider not available`;
|
|
3447
|
+
super(message, "PROVIDER_NOT_AVAILABLE", chainKey);
|
|
3401
3448
|
this.name = "ProviderNotAvailableError";
|
|
3402
3449
|
}
|
|
3403
3450
|
}
|
|
@@ -3716,6 +3763,22 @@ function useSilentValidations(amountString) {
|
|
|
3716
3763
|
]);
|
|
3717
3764
|
return validationResult;
|
|
3718
3765
|
}
|
|
3766
|
+
function useTelegramRestriction() {
|
|
3767
|
+
const { fromChain, toChain } = useChainsStore();
|
|
3768
|
+
const restriction = react.useMemo(() => {
|
|
3769
|
+
const isTelegramEnv = typeof window !== "undefined" && /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
3770
|
+
typeof window.TelegramWebviewProxy?.postEvent === "function";
|
|
3771
|
+
if (!isTelegramEnv) {
|
|
3772
|
+
return { isRestricted: false, isTelegramEnv: false };
|
|
3773
|
+
}
|
|
3774
|
+
const hasTonInvolved = fromChain?.chainKey?.toLowerCase() === "ton" || toChain?.chainKey?.toLowerCase() === "ton";
|
|
3775
|
+
return {
|
|
3776
|
+
isRestricted: !hasTonInvolved,
|
|
3777
|
+
isTelegramEnv: true
|
|
3778
|
+
};
|
|
3779
|
+
}, [fromChain?.chainKey, toChain?.chainKey]);
|
|
3780
|
+
return restriction;
|
|
3781
|
+
}
|
|
3719
3782
|
const MainButton = () => {
|
|
3720
3783
|
const { t: t2 } = useBridgeTranslation();
|
|
3721
3784
|
const { chainRegistry } = useChainStrategies();
|
|
@@ -3732,6 +3795,7 @@ const MainButton = () => {
|
|
|
3732
3795
|
);
|
|
3733
3796
|
const { hasAmountTooLarge, maximumAmountFormatted } = useAmountLimits(amountNum);
|
|
3734
3797
|
const { isValidForTransfer } = useSilentValidations(inputAmount || "");
|
|
3798
|
+
const { isRestricted: isTelegramRestricted } = useTelegramRestriction();
|
|
3735
3799
|
const srcChainKey = quote?.srcChainKey ?? fromChain?.chainKey;
|
|
3736
3800
|
const dstChainKey = quote?.dstChainKey ?? toChain?.chainKey;
|
|
3737
3801
|
const srcConnectedOk = srcChainKey && chainRegistry.isWalletConnected(srcChainKey);
|
|
@@ -3744,6 +3808,8 @@ const MainButton = () => {
|
|
|
3744
3808
|
const canTransfer = !missingSrc && !missingDst && amountNum > 0 && !!srcChainKey && !!dstChainKey;
|
|
3745
3809
|
const label = react.useMemo(() => {
|
|
3746
3810
|
switch (true) {
|
|
3811
|
+
case isTelegramRestricted:
|
|
3812
|
+
return t2("telegram.openWebVersion");
|
|
3747
3813
|
case status === "loading":
|
|
3748
3814
|
return t2("transaction.quoting");
|
|
3749
3815
|
case isTxProcessing:
|
|
@@ -3775,6 +3841,7 @@ const MainButton = () => {
|
|
|
3775
3841
|
}
|
|
3776
3842
|
}, [
|
|
3777
3843
|
t2,
|
|
3844
|
+
isTelegramRestricted,
|
|
3778
3845
|
status,
|
|
3779
3846
|
isTxProcessing,
|
|
3780
3847
|
isBusy,
|
|
@@ -3794,6 +3861,12 @@ const MainButton = () => {
|
|
|
3794
3861
|
]);
|
|
3795
3862
|
const handleClick = async () => {
|
|
3796
3863
|
if (isBusy) return;
|
|
3864
|
+
if (isTelegramRestricted) {
|
|
3865
|
+
const searchParams = typeof window !== "undefined" ? window.location.search || "" : "";
|
|
3866
|
+
const targetUrl = `https://app.evaa.finance/bridge${searchParams}`;
|
|
3867
|
+
window.open(targetUrl, "_blank", "noopener,noreferrer");
|
|
3868
|
+
return;
|
|
3869
|
+
}
|
|
3797
3870
|
if (missingSrc) {
|
|
3798
3871
|
onOpen("src");
|
|
3799
3872
|
return;
|
|
@@ -3811,51 +3884,26 @@ const MainButton = () => {
|
|
|
3811
3884
|
return;
|
|
3812
3885
|
}
|
|
3813
3886
|
};
|
|
3814
|
-
const disabled = isBusy || status === "loading" || !missingSrc && !missingDst && (amountNum <= 0 || isBalanceLoading || hasInsufficientBalance || hasAmountTooLarge || !gas.hasEnoughGas || noRoute || !isValidForTransfer);
|
|
3815
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3887
|
+
const disabled = isBusy || status === "loading" || !isTelegramRestricted && !missingSrc && !missingDst && (amountNum <= 0 || isBalanceLoading || hasInsufficientBalance || hasAmountTooLarge || !gas.hasEnoughGas || noRoute || !isValidForTransfer);
|
|
3888
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-4 space-y-4", children: [
|
|
3889
|
+
isTelegramRestricted && /* @__PURE__ */ jsxRuntime.jsx(alert.Alert, { variant: "warning", className: "mt-2 text-sm font-medium text-center", children: /* @__PURE__ */ jsxRuntime.jsx(alert.AlertDescription, { children: t2("telegram.restrictionMessage") }) }),
|
|
3890
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3891
|
+
button.Button,
|
|
3892
|
+
{
|
|
3893
|
+
onClick: handleClick,
|
|
3894
|
+
disabled,
|
|
3895
|
+
size: "lg",
|
|
3896
|
+
className: "w-full",
|
|
3897
|
+
children: label
|
|
3898
|
+
}
|
|
3899
|
+
)
|
|
3900
|
+
] });
|
|
3825
3901
|
};
|
|
3826
|
-
const useTronWalletConnectStore = zustand.create(
|
|
3827
|
-
(set2) => ({
|
|
3828
|
-
// State
|
|
3829
|
-
address: null,
|
|
3830
|
-
isConnected: false,
|
|
3831
|
-
isConnecting: false,
|
|
3832
|
-
connect: null,
|
|
3833
|
-
disconnect: null,
|
|
3834
|
-
signTransaction: null,
|
|
3835
|
-
// Actions
|
|
3836
|
-
setAddress: (address) => set2({
|
|
3837
|
-
address,
|
|
3838
|
-
isConnected: !!address
|
|
3839
|
-
}),
|
|
3840
|
-
setIsConnecting: (connecting) => set2({ isConnecting: connecting }),
|
|
3841
|
-
setActions: (actions) => set2({
|
|
3842
|
-
connect: actions.connect,
|
|
3843
|
-
disconnect: actions.disconnect,
|
|
3844
|
-
signTransaction: actions.signTransaction
|
|
3845
|
-
}),
|
|
3846
|
-
reset: () => set2({
|
|
3847
|
-
address: null,
|
|
3848
|
-
isConnected: false,
|
|
3849
|
-
isConnecting: false
|
|
3850
|
-
})
|
|
3851
|
-
})
|
|
3852
|
-
);
|
|
3853
3902
|
const WalletModalButton = (props) => {
|
|
3854
3903
|
const { t: t2 } = reactI18next.useTranslation();
|
|
3855
3904
|
const { icon: IconComponent, name, onClose } = props;
|
|
3856
3905
|
const { chainRegistry } = useChainStrategies();
|
|
3857
3906
|
const { connect, isPending } = wagmi.useConnect();
|
|
3858
|
-
const { connect: connectTronWC } = useTronWalletConnectStore();
|
|
3859
3907
|
const [isConnecting, setIsConnecting] = react.useState(false);
|
|
3860
3908
|
if (props.variant === "connected") {
|
|
3861
3909
|
const { address, onDisconnect } = props;
|
|
@@ -3893,15 +3941,13 @@ const WalletModalButton = (props) => {
|
|
|
3893
3941
|
try {
|
|
3894
3942
|
if (connector) {
|
|
3895
3943
|
connect({ connector });
|
|
3896
|
-
} else if (walletId === "
|
|
3897
|
-
|
|
3898
|
-
await connectTronWC();
|
|
3899
|
-
}
|
|
3900
|
-
} else {
|
|
3901
|
-
const strategy = chainRegistry.getStrategyByType(
|
|
3902
|
-
walletId === "ton" ? "ton" : "tron"
|
|
3903
|
-
);
|
|
3944
|
+
} else if (walletId === "ton") {
|
|
3945
|
+
const strategy = chainRegistry.getStrategyByType("ton");
|
|
3904
3946
|
await strategy?.connect();
|
|
3947
|
+
} else {
|
|
3948
|
+
const strategy = chainRegistry.getStrategyByType("tron");
|
|
3949
|
+
const provider = walletId === "tronwc" ? "walletconnect" : "tronlink";
|
|
3950
|
+
await strategy?.connect({ provider });
|
|
3905
3951
|
}
|
|
3906
3952
|
onClose?.();
|
|
3907
3953
|
} catch (error) {
|
|
@@ -3944,7 +3990,10 @@ const WalletSelectModal = () => {
|
|
|
3944
3990
|
const tonWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TON);
|
|
3945
3991
|
const metaMaskWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.EVM);
|
|
3946
3992
|
const tronWallet = chainRegistry.getStrategyByType(CHAIN_TYPES.TRON);
|
|
3947
|
-
const
|
|
3993
|
+
const tronConnections = tronWallet?.getAvailableConnections() ?? [];
|
|
3994
|
+
const isTronWalletConnectConnected = tronConnections.some(
|
|
3995
|
+
(conn) => conn.connected && conn.provider === "walletconnect"
|
|
3996
|
+
);
|
|
3948
3997
|
const walletConfigs = [
|
|
3949
3998
|
{
|
|
3950
3999
|
strategy: tonWallet,
|
|
@@ -3957,12 +4006,6 @@ const WalletSelectModal = () => {
|
|
|
3957
4006
|
walletId: "metamask",
|
|
3958
4007
|
name: t2("wallets.metaMask"),
|
|
3959
4008
|
icon: MetaMaskIcon
|
|
3960
|
-
},
|
|
3961
|
-
{
|
|
3962
|
-
strategy: tronWallet,
|
|
3963
|
-
walletId: "tronlink",
|
|
3964
|
-
name: t2("wallets.tronLink"),
|
|
3965
|
-
icon: TronLinkIcon
|
|
3966
4009
|
}
|
|
3967
4010
|
];
|
|
3968
4011
|
const connectedWallets = walletConfigs.reduce((acc, { strategy, walletId, name, icon }) => {
|
|
@@ -3978,21 +4021,25 @@ const WalletSelectModal = () => {
|
|
|
3978
4021
|
}
|
|
3979
4022
|
return acc;
|
|
3980
4023
|
}, []);
|
|
3981
|
-
|
|
4024
|
+
tronConnections.forEach((connection) => {
|
|
4025
|
+
if (!connection.connected || !connection.address) return;
|
|
4026
|
+
const isWalletConnect = connection.provider === "walletconnect";
|
|
3982
4027
|
connectedWallets.push({
|
|
3983
|
-
id: "tronwc",
|
|
3984
|
-
name: t2("wallets.walletConnect"),
|
|
3985
|
-
icon: WalletConnectIcon,
|
|
3986
|
-
address:
|
|
3987
|
-
onDisconnect: () =>
|
|
4028
|
+
id: isWalletConnect ? "tronwc" : "tronlink",
|
|
4029
|
+
name: isWalletConnect ? t2("wallets.walletConnect") : t2("wallets.tronLink"),
|
|
4030
|
+
icon: isWalletConnect ? WalletConnectIcon : TronLinkIcon,
|
|
4031
|
+
address: connection.address,
|
|
4032
|
+
onDisconnect: () => tronWallet?.disconnect({ provider: connection.provider })
|
|
3988
4033
|
});
|
|
3989
|
-
}
|
|
4034
|
+
});
|
|
3990
4035
|
const isWalletConnected = (walletId) => {
|
|
3991
4036
|
const isEvmConnector = connectors.some((c2) => c2.id === walletId);
|
|
3992
4037
|
if (isEvmConnector && metaMaskWallet?.isConnected()) {
|
|
3993
4038
|
return true;
|
|
3994
4039
|
}
|
|
3995
|
-
if (walletId === "tronwc"
|
|
4040
|
+
if ((walletId === "tronwc" || walletId === "tronlink") && tronConnections.some(
|
|
4041
|
+
(conn) => conn.connected && (walletId === "tronwc" ? conn.provider === "walletconnect" : conn.provider !== "walletconnect")
|
|
4042
|
+
)) {
|
|
3996
4043
|
return true;
|
|
3997
4044
|
}
|
|
3998
4045
|
return connectedWallets.some((w2) => w2.id === walletId);
|
|
@@ -4026,7 +4073,12 @@ const WalletSelectModal = () => {
|
|
|
4026
4073
|
icon: WalletConnectIcon,
|
|
4027
4074
|
enabled: true
|
|
4028
4075
|
}
|
|
4029
|
-
]
|
|
4076
|
+
].filter((wallet) => {
|
|
4077
|
+
if (wallet.id === "tronlink" && isTronWalletConnectConnected) {
|
|
4078
|
+
return false;
|
|
4079
|
+
}
|
|
4080
|
+
return true;
|
|
4081
|
+
});
|
|
4030
4082
|
const notConnected = (w2) => !isWalletConnected(w2.id);
|
|
4031
4083
|
const categories = [
|
|
4032
4084
|
{
|
|
@@ -4427,19 +4479,19 @@ class ChainStrategyRegistry {
|
|
|
4427
4479
|
if (!strategy) return t2("wallets.connectWallet");
|
|
4428
4480
|
return strategy.getConnectLabel(t2);
|
|
4429
4481
|
}
|
|
4430
|
-
async connectWallet(chainKey) {
|
|
4482
|
+
async connectWallet(chainKey, options) {
|
|
4431
4483
|
const strategy = this.getStrategy(chainKey);
|
|
4432
4484
|
if (!strategy) {
|
|
4433
4485
|
throw new Error(`No strategy available for chain: ${chainKey}`);
|
|
4434
4486
|
}
|
|
4435
|
-
await strategy.connect();
|
|
4487
|
+
await strategy.connect(options);
|
|
4436
4488
|
}
|
|
4437
|
-
async disconnectWallet(chainKey) {
|
|
4489
|
+
async disconnectWallet(chainKey, options) {
|
|
4438
4490
|
const strategy = this.getStrategy(chainKey);
|
|
4439
4491
|
if (!strategy) {
|
|
4440
4492
|
throw new Error(`No strategy available for chain: ${chainKey}`);
|
|
4441
4493
|
}
|
|
4442
|
-
await strategy.disconnect();
|
|
4494
|
+
await strategy.disconnect(options);
|
|
4443
4495
|
}
|
|
4444
4496
|
}
|
|
4445
4497
|
function isNativeAddress(addr) {
|
|
@@ -4777,6 +4829,16 @@ class EvmChainStrategy {
|
|
|
4777
4829
|
if (!address) return false;
|
|
4778
4830
|
return /^0x[0-9a-fA-F]{40}$/.test(address);
|
|
4779
4831
|
}
|
|
4832
|
+
getAvailableConnections() {
|
|
4833
|
+
return [
|
|
4834
|
+
{
|
|
4835
|
+
provider: "evm",
|
|
4836
|
+
address: this.config.evmAddress || null,
|
|
4837
|
+
connected: this.config.evmIsConnected,
|
|
4838
|
+
isConnecting: false
|
|
4839
|
+
}
|
|
4840
|
+
];
|
|
4841
|
+
}
|
|
4780
4842
|
validateSteps(steps) {
|
|
4781
4843
|
if (!steps || steps.length === 0) {
|
|
4782
4844
|
throw new InvalidStepsError("evm", "No transaction steps provided");
|
|
@@ -5167,6 +5229,16 @@ class TonChainStrategy {
|
|
|
5167
5229
|
if (!address) return false;
|
|
5168
5230
|
return true;
|
|
5169
5231
|
}
|
|
5232
|
+
getAvailableConnections() {
|
|
5233
|
+
return [
|
|
5234
|
+
{
|
|
5235
|
+
provider: "tonconnect",
|
|
5236
|
+
address: this.config.tonAddress || null,
|
|
5237
|
+
connected: !!this.config.tonAddress,
|
|
5238
|
+
isConnecting: false
|
|
5239
|
+
}
|
|
5240
|
+
];
|
|
5241
|
+
}
|
|
5170
5242
|
validateSteps(steps) {
|
|
5171
5243
|
if (!steps || steps.length === 0) {
|
|
5172
5244
|
throw new InvalidStepsError("ton", "No transaction steps provided");
|
|
@@ -5367,9 +5439,11 @@ class TonChainStrategy {
|
|
|
5367
5439
|
}
|
|
5368
5440
|
}
|
|
5369
5441
|
}
|
|
5442
|
+
const DEFAULT_TRON_NODE = "https://api.trongrid.io";
|
|
5370
5443
|
class TronChainStrategy {
|
|
5371
5444
|
constructor(config) {
|
|
5372
5445
|
__publicField(this, "config");
|
|
5446
|
+
__publicField(this, "fallbackClient");
|
|
5373
5447
|
this.config = config;
|
|
5374
5448
|
}
|
|
5375
5449
|
canHandle(chainKey) {
|
|
@@ -5381,7 +5455,19 @@ class TronChainStrategy {
|
|
|
5381
5455
|
getName() {
|
|
5382
5456
|
return "TRON Chain Strategy";
|
|
5383
5457
|
}
|
|
5384
|
-
async connect() {
|
|
5458
|
+
async connect(options) {
|
|
5459
|
+
const provider = this.resolveProvider(options?.provider);
|
|
5460
|
+
if (provider === "walletconnect") {
|
|
5461
|
+
const walletConnect = this.config.walletConnect;
|
|
5462
|
+
if (!walletConnect?.connect) {
|
|
5463
|
+
throw new ProviderNotAvailableError(
|
|
5464
|
+
"tron",
|
|
5465
|
+
"WalletConnect is not configured for TRON"
|
|
5466
|
+
);
|
|
5467
|
+
}
|
|
5468
|
+
await walletConnect.connect();
|
|
5469
|
+
return;
|
|
5470
|
+
}
|
|
5385
5471
|
if (!this.isTronLinkInstalled()) {
|
|
5386
5472
|
if (typeof window !== "undefined") {
|
|
5387
5473
|
window.open("https://www.tronlink.org/", "_blank");
|
|
@@ -5391,21 +5477,83 @@ class TronChainStrategy {
|
|
|
5391
5477
|
"TronLink wallet is not installed. Please install TronLink extension and try again."
|
|
5392
5478
|
);
|
|
5393
5479
|
}
|
|
5394
|
-
this.config.
|
|
5480
|
+
this.config.tronLink.select(tronwalletAdapters.TronLinkAdapterName);
|
|
5395
5481
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
5396
|
-
await this.config.
|
|
5482
|
+
await this.config.tronLink.connect();
|
|
5397
5483
|
}
|
|
5398
|
-
async disconnect() {
|
|
5399
|
-
|
|
5484
|
+
async disconnect(options) {
|
|
5485
|
+
const provider = options?.provider !== void 0 ? this.resolveProvider(options.provider) : this.getActiveConnector()?.provider ?? "tronlink";
|
|
5486
|
+
if (provider === "walletconnect") {
|
|
5487
|
+
const walletConnect = this.config.walletConnect;
|
|
5488
|
+
if (walletConnect?.disconnect) {
|
|
5489
|
+
await walletConnect.disconnect();
|
|
5490
|
+
}
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5493
|
+
await this.config.tronLink.disconnect();
|
|
5400
5494
|
}
|
|
5401
5495
|
isConnected() {
|
|
5402
|
-
return !!this.
|
|
5496
|
+
return !!this.getActiveConnector();
|
|
5403
5497
|
}
|
|
5404
5498
|
isConnecting() {
|
|
5405
|
-
return
|
|
5499
|
+
return !!this.config.walletConnect?.connecting;
|
|
5406
5500
|
}
|
|
5407
5501
|
getAccount() {
|
|
5408
|
-
return this.
|
|
5502
|
+
return this.getActiveConnector()?.address || null;
|
|
5503
|
+
}
|
|
5504
|
+
getAvailableConnections() {
|
|
5505
|
+
const connections = [
|
|
5506
|
+
this.getConnectorState("tronlink")
|
|
5507
|
+
];
|
|
5508
|
+
if (this.config.walletConnect) {
|
|
5509
|
+
connections.push(this.getConnectorState("walletconnect"));
|
|
5510
|
+
}
|
|
5511
|
+
return connections;
|
|
5512
|
+
}
|
|
5513
|
+
getActiveConnector() {
|
|
5514
|
+
const walletConnect = this.config.walletConnect && this.getConnectorState("walletconnect");
|
|
5515
|
+
if (walletConnect && walletConnect.connected && !!walletConnect.address) {
|
|
5516
|
+
return walletConnect;
|
|
5517
|
+
}
|
|
5518
|
+
const tronLink = this.getConnectorState("tronlink");
|
|
5519
|
+
if (tronLink.connected && !!tronLink.address) {
|
|
5520
|
+
return tronLink;
|
|
5521
|
+
}
|
|
5522
|
+
return null;
|
|
5523
|
+
}
|
|
5524
|
+
getConnectorState(provider) {
|
|
5525
|
+
if (provider === "walletconnect") {
|
|
5526
|
+
const walletConnect = this.config.walletConnect;
|
|
5527
|
+
return {
|
|
5528
|
+
provider: "walletconnect",
|
|
5529
|
+
address: walletConnect?.address ?? null,
|
|
5530
|
+
connected: !!walletConnect?.connected,
|
|
5531
|
+
isConnecting: !!walletConnect?.connecting,
|
|
5532
|
+
connect: walletConnect?.connect,
|
|
5533
|
+
disconnect: walletConnect?.disconnect,
|
|
5534
|
+
signTransaction: walletConnect?.signTransaction
|
|
5535
|
+
};
|
|
5536
|
+
}
|
|
5537
|
+
const tronLink = this.config.tronLink;
|
|
5538
|
+
return {
|
|
5539
|
+
provider: "tronlink",
|
|
5540
|
+
address: tronLink.address ?? null,
|
|
5541
|
+
connected: !!tronLink.connected,
|
|
5542
|
+
isConnecting: false,
|
|
5543
|
+
connect: tronLink.connect,
|
|
5544
|
+
disconnect: tronLink.disconnect,
|
|
5545
|
+
select: tronLink.select
|
|
5546
|
+
};
|
|
5547
|
+
}
|
|
5548
|
+
resolveProvider(provider) {
|
|
5549
|
+
if (!provider) {
|
|
5550
|
+
return "tronlink";
|
|
5551
|
+
}
|
|
5552
|
+
const normalized = typeof provider === "string" ? provider.toLowerCase() : provider;
|
|
5553
|
+
if (normalized === "walletconnect" || normalized === "tronwc") {
|
|
5554
|
+
return "walletconnect";
|
|
5555
|
+
}
|
|
5556
|
+
return "tronlink";
|
|
5409
5557
|
}
|
|
5410
5558
|
getError() {
|
|
5411
5559
|
return null;
|
|
@@ -5423,7 +5571,7 @@ class TronChainStrategy {
|
|
|
5423
5571
|
}
|
|
5424
5572
|
isAddressValid(address) {
|
|
5425
5573
|
if (!address) return false;
|
|
5426
|
-
return
|
|
5574
|
+
return isTronAddress(address);
|
|
5427
5575
|
}
|
|
5428
5576
|
validateSteps(steps) {
|
|
5429
5577
|
console.log("validateSteps");
|
|
@@ -5445,14 +5593,13 @@ class TronChainStrategy {
|
|
|
5445
5593
|
if (!tronWeb) {
|
|
5446
5594
|
throw new ProviderNotAvailableError("tron");
|
|
5447
5595
|
}
|
|
5448
|
-
|
|
5596
|
+
const connector = this.getActiveConnector();
|
|
5597
|
+
if (!connector?.connected || !connector.address) {
|
|
5449
5598
|
throw new WalletNotConnectedError("tron");
|
|
5450
5599
|
}
|
|
5451
5600
|
this.validateSteps(steps);
|
|
5452
|
-
const fromB58 =
|
|
5453
|
-
|
|
5454
|
-
throw new WalletNotConnectedError("tron");
|
|
5455
|
-
}
|
|
5601
|
+
const fromB58 = connector.address;
|
|
5602
|
+
this.ensureDefaultAddress(tronWeb, fromB58);
|
|
5456
5603
|
let lastTxId;
|
|
5457
5604
|
let isFirstHash = true;
|
|
5458
5605
|
for (const step of steps) {
|
|
@@ -5518,7 +5665,7 @@ class TronChainStrategy {
|
|
|
5518
5665
|
"Unsupported TRON parsed tx kind"
|
|
5519
5666
|
);
|
|
5520
5667
|
}
|
|
5521
|
-
const { txid } = await this.signAndBroadcast(tronWeb, unsigned);
|
|
5668
|
+
const { txid } = await this.signAndBroadcast(tronWeb, unsigned, connector);
|
|
5522
5669
|
lastTxId = txid;
|
|
5523
5670
|
if (isFirstHash) {
|
|
5524
5671
|
onFirstHash?.(txid);
|
|
@@ -5641,7 +5788,26 @@ class TronChainStrategy {
|
|
|
5641
5788
|
}
|
|
5642
5789
|
}
|
|
5643
5790
|
getClient() {
|
|
5644
|
-
|
|
5791
|
+
if (typeof window !== "undefined" && window.tronWeb) {
|
|
5792
|
+
return window.tronWeb;
|
|
5793
|
+
}
|
|
5794
|
+
if (!this.fallbackClient) {
|
|
5795
|
+
this.fallbackClient = this.createFallbackClient();
|
|
5796
|
+
}
|
|
5797
|
+
return this.fallbackClient;
|
|
5798
|
+
}
|
|
5799
|
+
createFallbackClient() {
|
|
5800
|
+
try {
|
|
5801
|
+
const tronWeb = new tronweb.TronWeb(
|
|
5802
|
+
DEFAULT_TRON_NODE,
|
|
5803
|
+
DEFAULT_TRON_NODE,
|
|
5804
|
+
DEFAULT_TRON_NODE
|
|
5805
|
+
);
|
|
5806
|
+
return tronWeb;
|
|
5807
|
+
} catch (error) {
|
|
5808
|
+
console.warn("Failed to create fallback TronWeb client", error);
|
|
5809
|
+
return void 0;
|
|
5810
|
+
}
|
|
5645
5811
|
}
|
|
5646
5812
|
/**
|
|
5647
5813
|
* Check if TronLink wallet is actually installed
|
|
@@ -5660,6 +5826,21 @@ class TronChainStrategy {
|
|
|
5660
5826
|
}
|
|
5661
5827
|
return true;
|
|
5662
5828
|
}
|
|
5829
|
+
ensureDefaultAddress(tronWeb, address) {
|
|
5830
|
+
if (!address) return;
|
|
5831
|
+
try {
|
|
5832
|
+
const hex = tronWeb.address.toHex(address);
|
|
5833
|
+
const current = tronWeb.defaultAddress || {};
|
|
5834
|
+
if (current.base58 !== address) {
|
|
5835
|
+
tronWeb.defaultAddress = {
|
|
5836
|
+
base58: address,
|
|
5837
|
+
hex
|
|
5838
|
+
};
|
|
5839
|
+
}
|
|
5840
|
+
} catch (error) {
|
|
5841
|
+
console.debug("Failed to set TronWeb default address:", error);
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5663
5844
|
hexToAscii(h4) {
|
|
5664
5845
|
if (!h4) return null;
|
|
5665
5846
|
const clean2 = h4.replace(/^0x/, "");
|
|
@@ -5933,9 +6114,20 @@ class TronChainStrategy {
|
|
|
5933
6114
|
}
|
|
5934
6115
|
return res.transaction;
|
|
5935
6116
|
}
|
|
5936
|
-
async signAndBroadcast(tronWeb, unsignedTx) {
|
|
5937
|
-
|
|
5938
|
-
|
|
6117
|
+
async signAndBroadcast(tronWeb, unsignedTx, connector) {
|
|
6118
|
+
let signedTx;
|
|
6119
|
+
if (connector.provider === "walletconnect") {
|
|
6120
|
+
if (!connector.signTransaction) {
|
|
6121
|
+
throw new ProviderNotAvailableError(
|
|
6122
|
+
"tron",
|
|
6123
|
+
"WalletConnect signing is unavailable"
|
|
6124
|
+
);
|
|
6125
|
+
}
|
|
6126
|
+
signedTx = await connector.signTransaction(unsignedTx);
|
|
6127
|
+
} else {
|
|
6128
|
+
signedTx = await tronWeb.trx.sign(unsignedTx);
|
|
6129
|
+
}
|
|
6130
|
+
const sent = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
5939
6131
|
if (!sent?.result || !sent?.txid) {
|
|
5940
6132
|
throw new TransactionFailedError(
|
|
5941
6133
|
"tron",
|
|
@@ -6018,18 +6210,29 @@ function ChainStrategyProvider({
|
|
|
6018
6210
|
);
|
|
6019
6211
|
const tronStrategy = react.useMemo(
|
|
6020
6212
|
() => new TronChainStrategy({
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6213
|
+
tronLink: {
|
|
6214
|
+
address: tronWallet.tronLink.address,
|
|
6215
|
+
connected: tronWallet.tronLink.connected,
|
|
6216
|
+
select: tronWallet.tronLink.select,
|
|
6217
|
+
connect: tronWallet.tronLink.connect,
|
|
6218
|
+
disconnect: tronWallet.tronLink.disconnect
|
|
6219
|
+
},
|
|
6220
|
+
walletConnect: tronWallet.walletConnect ? {
|
|
6221
|
+
address: tronWallet.walletConnect.address,
|
|
6222
|
+
connected: tronWallet.walletConnect.connected,
|
|
6223
|
+
connecting: tronWallet.walletConnect.connecting,
|
|
6224
|
+
connect: tronWallet.walletConnect.connect,
|
|
6225
|
+
disconnect: tronWallet.walletConnect.disconnect,
|
|
6226
|
+
signTransaction: tronWallet.walletConnect.signTransaction
|
|
6227
|
+
} : void 0
|
|
6026
6228
|
}),
|
|
6027
6229
|
[
|
|
6028
|
-
tronWallet.address,
|
|
6029
|
-
tronWallet.connected,
|
|
6030
|
-
tronWallet.select,
|
|
6031
|
-
tronWallet.connect,
|
|
6032
|
-
tronWallet.disconnect
|
|
6230
|
+
tronWallet.tronLink.address,
|
|
6231
|
+
tronWallet.tronLink.connected,
|
|
6232
|
+
tronWallet.tronLink.select,
|
|
6233
|
+
tronWallet.tronLink.connect,
|
|
6234
|
+
tronWallet.tronLink.disconnect,
|
|
6235
|
+
tronWallet.walletConnect
|
|
6033
6236
|
]
|
|
6034
6237
|
);
|
|
6035
6238
|
const chainRegistry = react.useMemo(
|
|
@@ -25606,7 +25809,7 @@ class WalletConnectModal {
|
|
|
25606
25809
|
}
|
|
25607
25810
|
async initUi() {
|
|
25608
25811
|
if (typeof window !== "undefined") {
|
|
25609
|
-
await Promise.resolve().then(() => require("./index-
|
|
25812
|
+
await Promise.resolve().then(() => require("./index-CebGXD16.cjs"));
|
|
25610
25813
|
const modal = document.createElement("wcm-modal");
|
|
25611
25814
|
document.body.insertAdjacentElement("beforeend", modal);
|
|
25612
25815
|
OptionsCtrl.setIsUiLoaded(true);
|
|
@@ -25654,14 +25857,10 @@ const TRON_MAINNET_CHAIN_ID = "tron:0x2b6653dc";
|
|
|
25654
25857
|
function useTronWalletConnect(projectId) {
|
|
25655
25858
|
const { address, isConnected, isConnecting } = useTronWalletConnectStore();
|
|
25656
25859
|
const { setAddress, setIsConnecting, setActions, reset } = useTronWalletConnectStore();
|
|
25657
|
-
const { setTronConnected } = useConnectedWalletsStore();
|
|
25658
25860
|
const providerRef = react.useRef(null);
|
|
25659
25861
|
const modalRef = react.useRef(null);
|
|
25660
25862
|
const { onClose: closeWalletSelectModal } = useWalletSelectModal();
|
|
25661
25863
|
const appliedTheme = useThemeStore((state2) => state2.appliedTheme);
|
|
25662
|
-
react.useEffect(() => {
|
|
25663
|
-
setTronConnected(isConnected);
|
|
25664
|
-
}, [isConnected, setTronConnected]);
|
|
25665
25864
|
react.useEffect(() => {
|
|
25666
25865
|
if (!projectId || providerRef.current) return;
|
|
25667
25866
|
const initProvider = async () => {
|
|
@@ -25833,6 +26032,194 @@ function useTronWalletConnect(projectId) {
|
|
|
25833
26032
|
signTransaction
|
|
25834
26033
|
};
|
|
25835
26034
|
}
|
|
26035
|
+
function parseBridgeUrlParams(source) {
|
|
26036
|
+
if (source && typeof source === "object") {
|
|
26037
|
+
return source;
|
|
26038
|
+
}
|
|
26039
|
+
const queryString = typeof source === "string" ? source : typeof window !== "undefined" ? window.location.search : "";
|
|
26040
|
+
const searchParams = new URLSearchParams(queryString);
|
|
26041
|
+
return {
|
|
26042
|
+
srcToken: searchParams.get("srcToken") || void 0,
|
|
26043
|
+
srcChain: searchParams.get("srcChain") || void 0,
|
|
26044
|
+
dstChain: searchParams.get("dstChain") || void 0,
|
|
26045
|
+
amount: searchParams.get("amount") || void 0
|
|
26046
|
+
};
|
|
26047
|
+
}
|
|
26048
|
+
function buildQueryString(params) {
|
|
26049
|
+
const searchParams = new URLSearchParams();
|
|
26050
|
+
if (params.srcToken) searchParams.set("srcToken", params.srcToken);
|
|
26051
|
+
if (params.srcChain) searchParams.set("srcChain", params.srcChain);
|
|
26052
|
+
if (params.dstChain) searchParams.set("dstChain", params.dstChain);
|
|
26053
|
+
if (params.amount) searchParams.set("amount", params.amount);
|
|
26054
|
+
const queryString = searchParams.toString();
|
|
26055
|
+
return queryString ? `?${queryString}` : "";
|
|
26056
|
+
}
|
|
26057
|
+
function updateBridgeUrlNative(params) {
|
|
26058
|
+
if (typeof window === "undefined" || !window.history) return;
|
|
26059
|
+
const queryString = buildQueryString(params);
|
|
26060
|
+
const newUrl = `${window.location.pathname}${queryString}${window.location.hash}`;
|
|
26061
|
+
window.history.replaceState(null, "", newUrl);
|
|
26062
|
+
}
|
|
26063
|
+
function useUrlSync(options) {
|
|
26064
|
+
const {
|
|
26065
|
+
enabled = true,
|
|
26066
|
+
urlParams: externalUrlParams,
|
|
26067
|
+
onUrlParamsChange
|
|
26068
|
+
} = options || {};
|
|
26069
|
+
const { chains, fromChain, toChain, setFromChain, setToChain } = useChainsStore();
|
|
26070
|
+
const { tokens, assetMatrix, selectedAssetSymbol, setSelectedAssetSymbol } = useTokensStore();
|
|
26071
|
+
const { inputAmount, setInputAmount } = useBridgeQuoteStore();
|
|
26072
|
+
const [hasInitialized, setHasInitialized] = react.useState(false);
|
|
26073
|
+
const isSyncingRef = react.useRef(false);
|
|
26074
|
+
const lastSyncedParamsRef = react.useRef({});
|
|
26075
|
+
const validateParams = react.useCallback(
|
|
26076
|
+
(urlParams) => {
|
|
26077
|
+
const result = {};
|
|
26078
|
+
if (!chains?.length || !tokens?.length || !assetMatrix) {
|
|
26079
|
+
return result;
|
|
26080
|
+
}
|
|
26081
|
+
if (urlParams.srcToken) {
|
|
26082
|
+
const token = tokens.find(
|
|
26083
|
+
(t2) => t2.symbol.toUpperCase() === urlParams.srcToken?.toUpperCase()
|
|
26084
|
+
);
|
|
26085
|
+
if (token) {
|
|
26086
|
+
result.token = token;
|
|
26087
|
+
}
|
|
26088
|
+
}
|
|
26089
|
+
if (urlParams.srcChain) {
|
|
26090
|
+
const chain2 = chains.find((c2) => c2.chainKey === urlParams.srcChain);
|
|
26091
|
+
if (chain2) {
|
|
26092
|
+
if (result.token) {
|
|
26093
|
+
const tokenOnChain = assetMatrix[result.token.symbol.toUpperCase()]?.[chain2.chainKey];
|
|
26094
|
+
if (tokenOnChain) {
|
|
26095
|
+
result.srcChain = chain2;
|
|
26096
|
+
}
|
|
26097
|
+
} else {
|
|
26098
|
+
result.srcChain = chain2;
|
|
26099
|
+
}
|
|
26100
|
+
}
|
|
26101
|
+
}
|
|
26102
|
+
if (urlParams.dstChain) {
|
|
26103
|
+
const chain2 = chains.find((c2) => c2.chainKey === urlParams.dstChain);
|
|
26104
|
+
if (chain2 && chain2.chainKey !== result.srcChain?.chainKey) {
|
|
26105
|
+
if (result.token) {
|
|
26106
|
+
const tokenOnChain = assetMatrix[result.token.symbol.toUpperCase()]?.[chain2.chainKey];
|
|
26107
|
+
if (tokenOnChain) {
|
|
26108
|
+
result.dstChain = chain2;
|
|
26109
|
+
}
|
|
26110
|
+
} else {
|
|
26111
|
+
result.dstChain = chain2;
|
|
26112
|
+
}
|
|
26113
|
+
}
|
|
26114
|
+
}
|
|
26115
|
+
if (urlParams.amount) {
|
|
26116
|
+
const decimalRegex = /^(\d+([.]\d*)?|[.]\d+)?$/;
|
|
26117
|
+
if (decimalRegex.test(urlParams.amount)) {
|
|
26118
|
+
const numValue = parseFloat(urlParams.amount);
|
|
26119
|
+
if (!isNaN(numValue) && numValue > 0) {
|
|
26120
|
+
result.amount = urlParams.amount;
|
|
26121
|
+
}
|
|
26122
|
+
}
|
|
26123
|
+
}
|
|
26124
|
+
return result;
|
|
26125
|
+
},
|
|
26126
|
+
[chains, tokens, assetMatrix]
|
|
26127
|
+
);
|
|
26128
|
+
const syncStateToUrl = react.useCallback(
|
|
26129
|
+
(includeAmount = false) => {
|
|
26130
|
+
if (!enabled || isSyncingRef.current || !hasInitialized) {
|
|
26131
|
+
return;
|
|
26132
|
+
}
|
|
26133
|
+
isSyncingRef.current = true;
|
|
26134
|
+
const normalizedAmount = inputAmount?.trim();
|
|
26135
|
+
const params = {
|
|
26136
|
+
srcToken: selectedAssetSymbol || void 0,
|
|
26137
|
+
srcChain: fromChain?.chainKey,
|
|
26138
|
+
dstChain: toChain?.chainKey,
|
|
26139
|
+
amount: includeAmount ? normalizedAmount || void 0 : lastSyncedParamsRef.current.amount
|
|
26140
|
+
};
|
|
26141
|
+
lastSyncedParamsRef.current = params;
|
|
26142
|
+
if (onUrlParamsChange) {
|
|
26143
|
+
onUrlParamsChange(params);
|
|
26144
|
+
} else {
|
|
26145
|
+
updateBridgeUrlNative(params);
|
|
26146
|
+
}
|
|
26147
|
+
setTimeout(() => {
|
|
26148
|
+
isSyncingRef.current = false;
|
|
26149
|
+
}, 0);
|
|
26150
|
+
},
|
|
26151
|
+
[
|
|
26152
|
+
enabled,
|
|
26153
|
+
hasInitialized,
|
|
26154
|
+
selectedAssetSymbol,
|
|
26155
|
+
fromChain,
|
|
26156
|
+
toChain,
|
|
26157
|
+
inputAmount,
|
|
26158
|
+
onUrlParamsChange
|
|
26159
|
+
]
|
|
26160
|
+
);
|
|
26161
|
+
const handleAmountBlur = react.useCallback(() => {
|
|
26162
|
+
if (!enabled || !hasInitialized) return;
|
|
26163
|
+
syncStateToUrl(true);
|
|
26164
|
+
}, [enabled, hasInitialized, syncStateToUrl]);
|
|
26165
|
+
react.useEffect(() => {
|
|
26166
|
+
if (!enabled || !chains?.length || !tokens?.length) {
|
|
26167
|
+
return;
|
|
26168
|
+
}
|
|
26169
|
+
const urlParams = externalUrlParams ? parseBridgeUrlParams(externalUrlParams) : parseBridgeUrlParams();
|
|
26170
|
+
if (!urlParams.srcToken && !urlParams.srcChain && !urlParams.dstChain && !urlParams.amount) {
|
|
26171
|
+
setHasInitialized(true);
|
|
26172
|
+
return;
|
|
26173
|
+
}
|
|
26174
|
+
const validated = validateParams(urlParams);
|
|
26175
|
+
const timeoutId = setTimeout(() => {
|
|
26176
|
+
if (validated.token) {
|
|
26177
|
+
setSelectedAssetSymbol(validated.token.symbol);
|
|
26178
|
+
}
|
|
26179
|
+
if (validated.srcChain) {
|
|
26180
|
+
setFromChain(validated.srcChain);
|
|
26181
|
+
}
|
|
26182
|
+
if (validated.dstChain) {
|
|
26183
|
+
setToChain(validated.dstChain);
|
|
26184
|
+
}
|
|
26185
|
+
if (validated.amount) {
|
|
26186
|
+
setInputAmount(validated.amount);
|
|
26187
|
+
}
|
|
26188
|
+
lastSyncedParamsRef.current = {
|
|
26189
|
+
srcToken: validated.token?.symbol || void 0,
|
|
26190
|
+
srcChain: validated.srcChain?.chainKey,
|
|
26191
|
+
dstChain: validated.dstChain?.chainKey,
|
|
26192
|
+
amount: validated.amount
|
|
26193
|
+
};
|
|
26194
|
+
setHasInitialized(true);
|
|
26195
|
+
}, 0);
|
|
26196
|
+
return () => clearTimeout(timeoutId);
|
|
26197
|
+
}, [
|
|
26198
|
+
enabled,
|
|
26199
|
+
chains,
|
|
26200
|
+
tokens,
|
|
26201
|
+
externalUrlParams,
|
|
26202
|
+
validateParams,
|
|
26203
|
+
setSelectedAssetSymbol,
|
|
26204
|
+
setFromChain,
|
|
26205
|
+
setToChain,
|
|
26206
|
+
setInputAmount
|
|
26207
|
+
]);
|
|
26208
|
+
react.useEffect(() => {
|
|
26209
|
+
if (!enabled || !hasInitialized) return;
|
|
26210
|
+
syncStateToUrl(false);
|
|
26211
|
+
}, [
|
|
26212
|
+
enabled,
|
|
26213
|
+
hasInitialized,
|
|
26214
|
+
fromChain?.chainKey,
|
|
26215
|
+
toChain?.chainKey,
|
|
26216
|
+
selectedAssetSymbol,
|
|
26217
|
+
syncStateToUrl
|
|
26218
|
+
]);
|
|
26219
|
+
return {
|
|
26220
|
+
handleAmountBlur
|
|
26221
|
+
};
|
|
26222
|
+
}
|
|
25836
26223
|
const EvaaBridgeWithProviders = (props) => {
|
|
25837
26224
|
const [tonConnectUI] = uiReact.useTonConnectUI();
|
|
25838
26225
|
const tonAddress = uiReact.useTonAddress();
|
|
@@ -25847,7 +26234,7 @@ const EvaaBridgeWithProviders = (props) => {
|
|
|
25847
26234
|
connect: tronConnect,
|
|
25848
26235
|
disconnect: tronDisconnect
|
|
25849
26236
|
} = tronwalletAdapterReactHooks.useWallet();
|
|
25850
|
-
useTronWalletConnect(props.walletConnectProjectId);
|
|
26237
|
+
const tronWalletConnect = useTronWalletConnect(props.walletConnectProjectId);
|
|
25851
26238
|
const { setTonConnected, setMetaMaskConnected, setTronConnected } = useConnectedWalletsStore();
|
|
25852
26239
|
react.useEffect(() => {
|
|
25853
26240
|
setTonConnected(!!tonAddress);
|
|
@@ -25855,12 +26242,13 @@ const EvaaBridgeWithProviders = (props) => {
|
|
|
25855
26242
|
react.useEffect(() => {
|
|
25856
26243
|
setMetaMaskConnected(!!evmIsConnected);
|
|
25857
26244
|
}, [evmIsConnected, setMetaMaskConnected]);
|
|
26245
|
+
const isAnyTronConnected = !!tronConnected || !!tronWalletConnect.isConnected;
|
|
25858
26246
|
react.useEffect(() => {
|
|
25859
|
-
setTronConnected(
|
|
25860
|
-
}, [
|
|
26247
|
+
setTronConnected(isAnyTronConnected);
|
|
26248
|
+
}, [isAnyTronConnected, setTronConnected]);
|
|
25861
26249
|
useAutoSelectNetwork({
|
|
25862
26250
|
tonAddress,
|
|
25863
|
-
tronConnected,
|
|
26251
|
+
tronConnected: isAnyTronConnected,
|
|
25864
26252
|
evmIsConnected
|
|
25865
26253
|
});
|
|
25866
26254
|
return /* @__PURE__ */ jsxRuntime.jsx(BridgeI18nProvider, { defaultLanguage: props.defaultLanguage, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -25878,11 +26266,21 @@ const EvaaBridgeWithProviders = (props) => {
|
|
|
25878
26266
|
address: tonAddress
|
|
25879
26267
|
},
|
|
25880
26268
|
tronWallet: {
|
|
25881
|
-
|
|
25882
|
-
|
|
25883
|
-
|
|
25884
|
-
|
|
25885
|
-
|
|
26269
|
+
tronLink: {
|
|
26270
|
+
address: tronAddress,
|
|
26271
|
+
connected: tronConnected,
|
|
26272
|
+
select: tronSelect,
|
|
26273
|
+
connect: tronConnect,
|
|
26274
|
+
disconnect: tronDisconnect
|
|
26275
|
+
},
|
|
26276
|
+
walletConnect: props.walletConnectProjectId ? {
|
|
26277
|
+
address: tronWalletConnect.address,
|
|
26278
|
+
connected: tronWalletConnect.isConnected,
|
|
26279
|
+
connecting: tronWalletConnect.isConnecting,
|
|
26280
|
+
connect: tronWalletConnect.connect,
|
|
26281
|
+
disconnect: tronWalletConnect.disconnect,
|
|
26282
|
+
signTransaction: tronWalletConnect.signTransaction
|
|
26283
|
+
} : void 0
|
|
25886
26284
|
},
|
|
25887
26285
|
tonClient: props.tonClient,
|
|
25888
26286
|
tonApiKey: props.tonApiKey,
|
|
@@ -25893,6 +26291,9 @@ const EvaaBridgeWithProviders = (props) => {
|
|
|
25893
26291
|
const EvaaBridgeContent = ({
|
|
25894
26292
|
className,
|
|
25895
26293
|
transactionIcons,
|
|
26294
|
+
enableUrlSync = true,
|
|
26295
|
+
urlParams,
|
|
26296
|
+
onUrlParamsChange,
|
|
25896
26297
|
onInitialized,
|
|
25897
26298
|
onAmountChange,
|
|
25898
26299
|
onChainChange
|
|
@@ -25901,6 +26302,11 @@ const EvaaBridgeContent = ({
|
|
|
25901
26302
|
useTokens();
|
|
25902
26303
|
useChains();
|
|
25903
26304
|
const swap = useSwapModel();
|
|
26305
|
+
const { handleAmountBlur } = useUrlSync({
|
|
26306
|
+
enabled: enableUrlSync,
|
|
26307
|
+
urlParams,
|
|
26308
|
+
onUrlParamsChange
|
|
26309
|
+
});
|
|
25904
26310
|
const { fromChain, toChain } = swap;
|
|
25905
26311
|
const { selectedAssetSymbol, assetMatrix } = useTokensStore();
|
|
25906
26312
|
const { quote } = useBridgeQuoteStore();
|
|
@@ -26010,6 +26416,7 @@ const EvaaBridgeContent = ({
|
|
|
26010
26416
|
amount,
|
|
26011
26417
|
isSource: true,
|
|
26012
26418
|
onAmountChange: handleAmountChange,
|
|
26419
|
+
onAmountBlur: handleAmountBlur,
|
|
26013
26420
|
onSelect: handleFromChainChange
|
|
26014
26421
|
}
|
|
26015
26422
|
),
|
|
@@ -26157,4 +26564,4 @@ exports.useSettingsStore = useSettingsStore;
|
|
|
26157
26564
|
exports.useSwapModel = useSwapModel;
|
|
26158
26565
|
exports.useTokensStore = useTokensStore;
|
|
26159
26566
|
exports.useTransactionStore = useTransactionStore;
|
|
26160
|
-
//# sourceMappingURL=index-
|
|
26567
|
+
//# sourceMappingURL=index-BXUBhn_o.cjs.map
|