@rash2x/bridge-widget 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evaa-bridge.cjs +52 -64
- package/dist/evaa-bridge.cjs.map +1 -1
- package/dist/evaa-bridge.mjs +52 -64
- package/dist/evaa-bridge.mjs.map +1 -1
- package/package.json +1 -1
package/dist/evaa-bridge.mjs
CHANGED
|
@@ -1489,8 +1489,12 @@ function useBalances(chainKey, address) {
|
|
|
1489
1489
|
[balanceBySymbol]
|
|
1490
1490
|
);
|
|
1491
1491
|
const isLoading = query.isLoading || query.isFetching;
|
|
1492
|
+
const balances = useMemo(
|
|
1493
|
+
() => query.data || {},
|
|
1494
|
+
[query.data]
|
|
1495
|
+
);
|
|
1492
1496
|
return {
|
|
1493
|
-
balances
|
|
1497
|
+
balances,
|
|
1494
1498
|
getBalance,
|
|
1495
1499
|
isLoading,
|
|
1496
1500
|
query
|
|
@@ -3721,7 +3725,9 @@ function useBridgeTransaction() {
|
|
|
3721
3725
|
function useGasEstimate(amountNum) {
|
|
3722
3726
|
const { fromChain } = useChainsStore();
|
|
3723
3727
|
const { selectedAssetSymbol, tokens } = useTokensStore();
|
|
3724
|
-
const
|
|
3728
|
+
const getSourceGasReserveHuman = useSettingsStore(
|
|
3729
|
+
(state) => state.getSourceGasReserveHuman
|
|
3730
|
+
);
|
|
3725
3731
|
const { srcAddress } = useAddresses();
|
|
3726
3732
|
const { balances, isLoading: balancesLoading } = useBalances(
|
|
3727
3733
|
fromChain?.chainKey,
|
|
@@ -3729,59 +3735,44 @@ function useGasEstimate(amountNum) {
|
|
|
3729
3735
|
);
|
|
3730
3736
|
const { chainRegistry } = useChainStrategies();
|
|
3731
3737
|
const balancesKnown = !balancesLoading;
|
|
3732
|
-
const
|
|
3733
|
-
null
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
}
|
|
3771
|
-
}
|
|
3772
|
-
estimateGas();
|
|
3773
|
-
return () => {
|
|
3774
|
-
cancelled = true;
|
|
3775
|
-
};
|
|
3776
|
-
}, [
|
|
3777
|
-
fromChain,
|
|
3778
|
-
selectedAssetSymbol,
|
|
3779
|
-
tokens,
|
|
3780
|
-
amountNum,
|
|
3781
|
-
balances,
|
|
3782
|
-
chainRegistry,
|
|
3783
|
-
getSourceGasReserveHuman
|
|
3784
|
-
]);
|
|
3738
|
+
const strategy = useMemo(() => {
|
|
3739
|
+
if (!fromChain) return null;
|
|
3740
|
+
return chainRegistry.getStrategy(fromChain.chainKey);
|
|
3741
|
+
}, [fromChain, chainRegistry]);
|
|
3742
|
+
const { data: gasRequirement } = useQuery({
|
|
3743
|
+
queryKey: [
|
|
3744
|
+
"gas-estimate",
|
|
3745
|
+
fromChain?.chainKey,
|
|
3746
|
+
selectedAssetSymbol,
|
|
3747
|
+
amountNum,
|
|
3748
|
+
balances
|
|
3749
|
+
],
|
|
3750
|
+
queryFn: async () => {
|
|
3751
|
+
if (!fromChain || !strategy) {
|
|
3752
|
+
return null;
|
|
3753
|
+
}
|
|
3754
|
+
const selectedToken = tokens?.find(
|
|
3755
|
+
(t2) => t2.symbol.toUpperCase() === selectedAssetSymbol?.toUpperCase()
|
|
3756
|
+
) || null;
|
|
3757
|
+
const nativeTokenSymbol = fromChain.nativeCurrency?.symbol ?? "";
|
|
3758
|
+
const nativeDecimals = fromChain.nativeCurrency?.decimals || 18;
|
|
3759
|
+
const reserveFallback = getSourceGasReserveHuman(fromChain.chainKey);
|
|
3760
|
+
const result = await strategy.estimateGasRequirement({
|
|
3761
|
+
selectedToken,
|
|
3762
|
+
nativeTokenSymbol,
|
|
3763
|
+
amount: amountNum,
|
|
3764
|
+
balances,
|
|
3765
|
+
nativeDecimals,
|
|
3766
|
+
reserveFallback
|
|
3767
|
+
});
|
|
3768
|
+
return result;
|
|
3769
|
+
},
|
|
3770
|
+
enabled: !!fromChain && !!strategy,
|
|
3771
|
+
staleTime: 3e4,
|
|
3772
|
+
gcTime: 5 * 6e4,
|
|
3773
|
+
refetchOnWindowFocus: false,
|
|
3774
|
+
retry: 1
|
|
3775
|
+
});
|
|
3785
3776
|
return {
|
|
3786
3777
|
nativeSym: gasRequirement?.nativeSym || "",
|
|
3787
3778
|
nativeBalance: gasRequirement?.nativeBalance || 0,
|
|
@@ -6486,7 +6477,6 @@ class EvmChainStrategy {
|
|
|
6486
6477
|
this.provider = new BrowserProvider(config.walletClient.transport);
|
|
6487
6478
|
}
|
|
6488
6479
|
}
|
|
6489
|
-
// ========== Identity ==========
|
|
6490
6480
|
canHandle(chainKey) {
|
|
6491
6481
|
const key = chainKey.toLowerCase();
|
|
6492
6482
|
return key !== "ton" && key !== "tron";
|
|
@@ -6497,7 +6487,6 @@ class EvmChainStrategy {
|
|
|
6497
6487
|
getName() {
|
|
6498
6488
|
return "EVM Chain Strategy";
|
|
6499
6489
|
}
|
|
6500
|
-
// ========== Wallet Management ==========
|
|
6501
6490
|
async connect() {
|
|
6502
6491
|
}
|
|
6503
6492
|
async disconnect() {
|
|
@@ -6521,7 +6510,6 @@ class EvmChainStrategy {
|
|
|
6521
6510
|
getConnectLabel(t2) {
|
|
6522
6511
|
return t2("wallets.connectEvmWallet");
|
|
6523
6512
|
}
|
|
6524
|
-
// ========== Balance & Validation ==========
|
|
6525
6513
|
async getBalances(address, tokens) {
|
|
6526
6514
|
return await getEvmBalances(address, tokens);
|
|
6527
6515
|
}
|
|
@@ -6529,7 +6517,6 @@ class EvmChainStrategy {
|
|
|
6529
6517
|
if (!address) return false;
|
|
6530
6518
|
return /^0x[0-9a-fA-F]{40}$/.test(address);
|
|
6531
6519
|
}
|
|
6532
|
-
// ========== Gas Estimation ==========
|
|
6533
6520
|
async estimateGasRequirement(params) {
|
|
6534
6521
|
const provider = this.provider;
|
|
6535
6522
|
const {
|
|
@@ -6576,7 +6563,6 @@ class EvmChainStrategy {
|
|
|
6576
6563
|
isNativeSelected
|
|
6577
6564
|
};
|
|
6578
6565
|
}
|
|
6579
|
-
// ========== Transaction Execution ==========
|
|
6580
6566
|
validateSteps(steps) {
|
|
6581
6567
|
if (!steps || steps.length === 0) {
|
|
6582
6568
|
throw new InvalidStepsError("evm", "No transaction steps provided");
|
|
@@ -6679,7 +6665,6 @@ class EvmChainStrategy {
|
|
|
6679
6665
|
};
|
|
6680
6666
|
}
|
|
6681
6667
|
}
|
|
6682
|
-
// ========== Private Helper Methods ==========
|
|
6683
6668
|
async executeTransaction(step) {
|
|
6684
6669
|
const provider = this.provider;
|
|
6685
6670
|
const signer = await provider?.getSigner();
|
|
@@ -7534,9 +7519,12 @@ function ChainStrategyProvider({
|
|
|
7534
7519
|
() => new ChainStrategyRegistry([evmStrategy, tonStrategy, tronStrategy]),
|
|
7535
7520
|
[evmStrategy, tonStrategy, tronStrategy]
|
|
7536
7521
|
);
|
|
7537
|
-
const value =
|
|
7538
|
-
|
|
7539
|
-
|
|
7522
|
+
const value = useMemo(
|
|
7523
|
+
() => ({
|
|
7524
|
+
chainRegistry
|
|
7525
|
+
}),
|
|
7526
|
+
[chainRegistry]
|
|
7527
|
+
);
|
|
7540
7528
|
return /* @__PURE__ */ jsx(ChainStrategyContext.Provider, { value, children });
|
|
7541
7529
|
}
|
|
7542
7530
|
const EvaaBridgeWithProviders = (props) => {
|