@wheelx-widget/widget 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +113 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { Fraction, RoundingMode } from 'bi-fraction';
|
|
|
17
17
|
import { base, soneium, ink as ink$1, bsc as bsc$1 } from 'viem/chains';
|
|
18
18
|
import { PublicKey, VersionedTransaction, VersionedMessage, Transaction } from '@solana/web3.js';
|
|
19
19
|
import { parseAccount, getAddress } from 'viem/utils';
|
|
20
|
-
import { writeContract as writeContract$1, waitForTransactionReceipt as waitForTransactionReceipt$1, getTransaction, call
|
|
20
|
+
import { readContract as readContract$1, writeContract as writeContract$1, waitForTransactionReceipt as waitForTransactionReceipt$1, getTransaction, call } from 'viem/actions';
|
|
21
21
|
import { MdOutlineStarOutline, MdOutlineStarPurple500, MdFavoriteBorder, MdFavorite, MdLocalGasStation } from 'react-icons/md';
|
|
22
22
|
import { WalletIcon as WalletIcon$1 } from '@dynamic-labs/wallet-book';
|
|
23
23
|
import { FiEdit } from 'react-icons/fi';
|
|
@@ -47986,14 +47986,107 @@ var OptimizedImage = forwardRef(
|
|
|
47986
47986
|
}
|
|
47987
47987
|
);
|
|
47988
47988
|
OptimizedImage.displayName = "OptimizedImage";
|
|
47989
|
-
|
|
47990
|
-
|
|
47991
|
-
|
|
47992
|
-
|
|
47993
|
-
|
|
47994
|
-
|
|
47989
|
+
var usdtAbi = [
|
|
47990
|
+
{
|
|
47991
|
+
name: "approve",
|
|
47992
|
+
type: "function",
|
|
47993
|
+
stateMutability: "nonpayable",
|
|
47994
|
+
inputs: [
|
|
47995
|
+
{ name: "_spender", type: "address" },
|
|
47996
|
+
{ name: "_value", type: "uint256" }
|
|
47997
|
+
],
|
|
47998
|
+
outputs: [{ name: "", type: "bool" }]
|
|
47999
|
+
},
|
|
48000
|
+
{
|
|
48001
|
+
name: "allowance",
|
|
48002
|
+
type: "function",
|
|
48003
|
+
stateMutability: "view",
|
|
48004
|
+
inputs: [
|
|
48005
|
+
{ name: "_owner", type: "address" },
|
|
48006
|
+
{ name: "_spender", type: "address" }
|
|
48007
|
+
],
|
|
48008
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
48009
|
+
}
|
|
48010
|
+
];
|
|
48011
|
+
function useUSDTHandler(chainId) {
|
|
48012
|
+
const config = useConfig();
|
|
48013
|
+
const { address: owner } = useAccount();
|
|
48014
|
+
const [error, setError] = useState(null);
|
|
48015
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
48016
|
+
const handleApprove = async (tokenAddress, spender, amount) => {
|
|
48017
|
+
setError(null);
|
|
48018
|
+
setIsLoading(true);
|
|
48019
|
+
try {
|
|
48020
|
+
if (!owner) {
|
|
48021
|
+
const errorMsg = "No account available. Please connect your wallet and try again.";
|
|
48022
|
+
setError(errorMsg);
|
|
48023
|
+
throw new Error(errorMsg);
|
|
48024
|
+
}
|
|
48025
|
+
const targetChainId = chainId ?? 1;
|
|
48026
|
+
console.log("[USDT Approve] Reading allowance:", {
|
|
48027
|
+
chainId: targetChainId,
|
|
48028
|
+
tokenAddress,
|
|
48029
|
+
owner,
|
|
48030
|
+
spender
|
|
48031
|
+
});
|
|
48032
|
+
const currentAllowance = await readContract(config, {
|
|
48033
|
+
abi: usdtAbi,
|
|
48034
|
+
address: tokenAddress,
|
|
48035
|
+
functionName: "allowance",
|
|
48036
|
+
chainId: targetChainId,
|
|
48037
|
+
args: [owner, spender]
|
|
48038
|
+
});
|
|
48039
|
+
console.log("[USDT Approve] Current allowance:", currentAllowance.toString());
|
|
48040
|
+
if (currentAllowance >= amount) {
|
|
48041
|
+
console.log(
|
|
48042
|
+
"[USDT Approve] Allowance is sufficient, no additional approval needed"
|
|
48043
|
+
);
|
|
48044
|
+
return;
|
|
48045
|
+
}
|
|
48046
|
+
if (currentAllowance > 0n) {
|
|
48047
|
+
console.log("[USDT Approve] Performing allowance reset to zero");
|
|
48048
|
+
const zeroApproveHash = await writeContract(config, {
|
|
48049
|
+
abi: usdtAbi,
|
|
48050
|
+
address: tokenAddress,
|
|
48051
|
+
functionName: "approve",
|
|
48052
|
+
chainId: targetChainId,
|
|
48053
|
+
args: [spender, 0n]
|
|
48054
|
+
});
|
|
48055
|
+
console.log(
|
|
48056
|
+
"[USDT Approve] Waiting for zero-approval transaction confirmation..."
|
|
48057
|
+
);
|
|
48058
|
+
await waitForTransactionReceipt(config, {
|
|
48059
|
+
hash: zeroApproveHash,
|
|
48060
|
+
chainId: targetChainId
|
|
48061
|
+
});
|
|
48062
|
+
console.log("[USDT Approve] Zero-approval completed");
|
|
48063
|
+
}
|
|
48064
|
+
console.log("[USDT Approve] Performing target amount approval");
|
|
48065
|
+
const approveHash = await writeContract(config, {
|
|
48066
|
+
abi: usdtAbi,
|
|
48067
|
+
address: tokenAddress,
|
|
48068
|
+
functionName: "approve",
|
|
48069
|
+
chainId: targetChainId,
|
|
48070
|
+
args: [spender, amount]
|
|
48071
|
+
});
|
|
48072
|
+
console.log(
|
|
48073
|
+
"[USDT Approve] Waiting for target amount approval transaction confirmation..."
|
|
48074
|
+
);
|
|
48075
|
+
await waitForTransactionReceipt(config, {
|
|
48076
|
+
hash: approveHash,
|
|
48077
|
+
chainId: targetChainId
|
|
48078
|
+
});
|
|
48079
|
+
console.log("[USDT Approve] Double approval process completed");
|
|
48080
|
+
} catch (err) {
|
|
48081
|
+
const errorMessage = err instanceof Error ? err.message : "Authorization operation failed";
|
|
48082
|
+
setError(errorMessage);
|
|
48083
|
+
throw err;
|
|
48084
|
+
} finally {
|
|
48085
|
+
setIsLoading(false);
|
|
48086
|
+
}
|
|
47995
48087
|
};
|
|
47996
|
-
};
|
|
48088
|
+
return { handleApprove, error, isLoading };
|
|
48089
|
+
}
|
|
47997
48090
|
var buttonStyles = {
|
|
47998
48091
|
w: "100%",
|
|
47999
48092
|
h: {
|
|
@@ -48167,7 +48260,7 @@ var FormButton = ({
|
|
|
48167
48260
|
startLoading();
|
|
48168
48261
|
const vCode = extractVPathSegment();
|
|
48169
48262
|
const fromAddress = fromTokenInfo.isSolana ? solanaWalletAddress || "" : effectiveEvmAddress || "";
|
|
48170
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48263
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48171
48264
|
if (fromAddress && fromAmount) {
|
|
48172
48265
|
console.log(
|
|
48173
48266
|
"[Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48202,7 +48295,9 @@ var FormButton = ({
|
|
|
48202
48295
|
effectiveEvmAddress,
|
|
48203
48296
|
solanaWalletAddress,
|
|
48204
48297
|
differentAddress,
|
|
48205
|
-
slippage
|
|
48298
|
+
slippage,
|
|
48299
|
+
config?.evmDifferentAddress,
|
|
48300
|
+
config?.solanaDifferentAddress
|
|
48206
48301
|
]
|
|
48207
48302
|
);
|
|
48208
48303
|
const { sendTransaction, isPending } = useSendTransaction({
|
|
@@ -48492,7 +48587,7 @@ var FormButton = ({
|
|
|
48492
48587
|
/* @__PURE__ */ jsx(Icon, { w: "24px", h: "24px", as: WalletIcon }),
|
|
48493
48588
|
/* @__PURE__ */ jsxs(Heading, { variant: buttonHeadingVariant, children: [
|
|
48494
48589
|
"Connect ",
|
|
48495
|
-
name
|
|
48590
|
+
name ,
|
|
48496
48591
|
" Wallet"
|
|
48497
48592
|
] })
|
|
48498
48593
|
] });
|
|
@@ -48567,7 +48662,7 @@ var FormButton = ({
|
|
|
48567
48662
|
startLoading();
|
|
48568
48663
|
const vCode = extractVPathSegment();
|
|
48569
48664
|
const fromAddress = solanaWalletAddress || "";
|
|
48570
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48665
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48571
48666
|
if (fromAddress && fromAmount) {
|
|
48572
48667
|
console.log(
|
|
48573
48668
|
"[Solana Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48608,28 +48703,17 @@ var FormButton = ({
|
|
|
48608
48703
|
}
|
|
48609
48704
|
) });
|
|
48610
48705
|
}
|
|
48611
|
-
if (
|
|
48706
|
+
if (!fromTokenInfo.isSolana && !hasEvmUiWallet) {
|
|
48707
|
+
return renderEvmWalletConnectButton("EVM");
|
|
48708
|
+
}
|
|
48709
|
+
if (fromTokenInfo.isSolana && !solanaWalletAddress) {
|
|
48612
48710
|
return renderSolanaWalletConnectButton();
|
|
48613
48711
|
}
|
|
48614
|
-
if (
|
|
48712
|
+
if (fromTokenInfo.isSolana && !toTokenInfo.isSolana && !skipEvmWalletConnect && !hasEvmUiWallet) {
|
|
48615
48713
|
return renderEvmWalletConnectButton("EVM");
|
|
48616
48714
|
}
|
|
48617
|
-
if (!
|
|
48618
|
-
|
|
48619
|
-
return renderSolanaWalletConnectButton();
|
|
48620
|
-
}
|
|
48621
|
-
return renderEvmWalletConnectButton();
|
|
48622
|
-
} else if (!hasEvmUiWallet && solanaWalletAddress) {
|
|
48623
|
-
if (!fromTokenInfo.isSolana && !toTokenInfo.isSolana || !fromTokenInfo.isSolana && toTokenInfo.isSolana || fromTokenInfo.isSolana && !toTokenInfo.isSolana && !skipEvmWalletConnect) {
|
|
48624
|
-
return renderEvmWalletConnectButton("EVM");
|
|
48625
|
-
}
|
|
48626
|
-
} else if (hasEvmUiWallet && !solanaWalletAddress) {
|
|
48627
|
-
if (fromTokenInfo.isSolana || toTokenInfo.isSolana && !skipSolanaWalletConnect) {
|
|
48628
|
-
return renderSolanaWalletConnectButton();
|
|
48629
|
-
}
|
|
48630
|
-
if (fromTokenInfo.isSolana && toTokenInfo.isSolana || !fromTokenInfo.isSolana && toTokenInfo.isSolana && !skipSolanaWalletConnect || fromTokenInfo.isSolana && !toTokenInfo.isSolana) {
|
|
48631
|
-
return renderSolanaWalletConnectButton();
|
|
48632
|
-
}
|
|
48715
|
+
if (!fromTokenInfo.isSolana && toTokenInfo.isSolana && !skipSolanaWalletConnect && !solanaWalletAddress) {
|
|
48716
|
+
return renderSolanaWalletConnectButton();
|
|
48633
48717
|
}
|
|
48634
48718
|
if (isFetching || fromAmount && !toAmount) {
|
|
48635
48719
|
return /* @__PURE__ */ jsx(
|