@wheelx-widget/widget 0.1.17 → 0.1.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/README.md +25 -17
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +115 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
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';
|
|
@@ -43713,12 +43713,9 @@ var WidgetThemeProvider = ({
|
|
|
43713
43713
|
};
|
|
43714
43714
|
|
|
43715
43715
|
// src/api/consts.ts
|
|
43716
|
-
var
|
|
43716
|
+
var BASE_API_URL = "https://api.wheelx.fi";
|
|
43717
43717
|
function getBaseApiUrl() {
|
|
43718
|
-
return
|
|
43719
|
-
}
|
|
43720
|
-
function setBaseApiUrl(url) {
|
|
43721
|
-
_baseApiUrl = url;
|
|
43718
|
+
return BASE_API_URL;
|
|
43722
43719
|
}
|
|
43723
43720
|
async function getChainsAndTokens() {
|
|
43724
43721
|
const url = `${getBaseApiUrl()}/v1/chain-info`;
|
|
@@ -44763,9 +44760,6 @@ function ChainsAndTokensLoader({ children, config }) {
|
|
|
44763
44760
|
var DEFAULT_ENVIRONMENT_ID = "f217660e-2cec-470b-a8f4-ac655b16f802";
|
|
44764
44761
|
var solanaRpcUrl = "https://mainnet.helius-rpc.com/?api-key=7337bed2-6c3a-472f-b06f-9b2be0e1392f";
|
|
44765
44762
|
var WheelXProvider = ({ config, children }) => {
|
|
44766
|
-
if (config?.apiBaseUrl) {
|
|
44767
|
-
setBaseApiUrl(config.apiBaseUrl);
|
|
44768
|
-
}
|
|
44769
44763
|
const queryClient = useMemo(() => new QueryClient(), []);
|
|
44770
44764
|
const evmNetworks = useMemo(() => supportedChains.map((chain) => ({
|
|
44771
44765
|
chainId: chain.id,
|
|
@@ -47986,14 +47980,107 @@ var OptimizedImage = forwardRef(
|
|
|
47986
47980
|
}
|
|
47987
47981
|
);
|
|
47988
47982
|
OptimizedImage.displayName = "OptimizedImage";
|
|
47989
|
-
|
|
47990
|
-
|
|
47991
|
-
|
|
47992
|
-
|
|
47993
|
-
|
|
47994
|
-
|
|
47983
|
+
var usdtAbi = [
|
|
47984
|
+
{
|
|
47985
|
+
name: "approve",
|
|
47986
|
+
type: "function",
|
|
47987
|
+
stateMutability: "nonpayable",
|
|
47988
|
+
inputs: [
|
|
47989
|
+
{ name: "_spender", type: "address" },
|
|
47990
|
+
{ name: "_value", type: "uint256" }
|
|
47991
|
+
],
|
|
47992
|
+
outputs: [{ name: "", type: "bool" }]
|
|
47993
|
+
},
|
|
47994
|
+
{
|
|
47995
|
+
name: "allowance",
|
|
47996
|
+
type: "function",
|
|
47997
|
+
stateMutability: "view",
|
|
47998
|
+
inputs: [
|
|
47999
|
+
{ name: "_owner", type: "address" },
|
|
48000
|
+
{ name: "_spender", type: "address" }
|
|
48001
|
+
],
|
|
48002
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
48003
|
+
}
|
|
48004
|
+
];
|
|
48005
|
+
function useUSDTHandler(chainId) {
|
|
48006
|
+
const config = useConfig();
|
|
48007
|
+
const { address: owner } = useAccount();
|
|
48008
|
+
const [error, setError] = useState(null);
|
|
48009
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
48010
|
+
const handleApprove = async (tokenAddress, spender, amount) => {
|
|
48011
|
+
setError(null);
|
|
48012
|
+
setIsLoading(true);
|
|
48013
|
+
try {
|
|
48014
|
+
if (!owner) {
|
|
48015
|
+
const errorMsg = "No account available. Please connect your wallet and try again.";
|
|
48016
|
+
setError(errorMsg);
|
|
48017
|
+
throw new Error(errorMsg);
|
|
48018
|
+
}
|
|
48019
|
+
const targetChainId = chainId ?? 1;
|
|
48020
|
+
console.log("[USDT Approve] Reading allowance:", {
|
|
48021
|
+
chainId: targetChainId,
|
|
48022
|
+
tokenAddress,
|
|
48023
|
+
owner,
|
|
48024
|
+
spender
|
|
48025
|
+
});
|
|
48026
|
+
const currentAllowance = await readContract(config, {
|
|
48027
|
+
abi: usdtAbi,
|
|
48028
|
+
address: tokenAddress,
|
|
48029
|
+
functionName: "allowance",
|
|
48030
|
+
chainId: targetChainId,
|
|
48031
|
+
args: [owner, spender]
|
|
48032
|
+
});
|
|
48033
|
+
console.log("[USDT Approve] Current allowance:", currentAllowance.toString());
|
|
48034
|
+
if (currentAllowance >= amount) {
|
|
48035
|
+
console.log(
|
|
48036
|
+
"[USDT Approve] Allowance is sufficient, no additional approval needed"
|
|
48037
|
+
);
|
|
48038
|
+
return;
|
|
48039
|
+
}
|
|
48040
|
+
if (currentAllowance > 0n) {
|
|
48041
|
+
console.log("[USDT Approve] Performing allowance reset to zero");
|
|
48042
|
+
const zeroApproveHash = await writeContract(config, {
|
|
48043
|
+
abi: usdtAbi,
|
|
48044
|
+
address: tokenAddress,
|
|
48045
|
+
functionName: "approve",
|
|
48046
|
+
chainId: targetChainId,
|
|
48047
|
+
args: [spender, 0n]
|
|
48048
|
+
});
|
|
48049
|
+
console.log(
|
|
48050
|
+
"[USDT Approve] Waiting for zero-approval transaction confirmation..."
|
|
48051
|
+
);
|
|
48052
|
+
await waitForTransactionReceipt(config, {
|
|
48053
|
+
hash: zeroApproveHash,
|
|
48054
|
+
chainId: targetChainId
|
|
48055
|
+
});
|
|
48056
|
+
console.log("[USDT Approve] Zero-approval completed");
|
|
48057
|
+
}
|
|
48058
|
+
console.log("[USDT Approve] Performing target amount approval");
|
|
48059
|
+
const approveHash = await writeContract(config, {
|
|
48060
|
+
abi: usdtAbi,
|
|
48061
|
+
address: tokenAddress,
|
|
48062
|
+
functionName: "approve",
|
|
48063
|
+
chainId: targetChainId,
|
|
48064
|
+
args: [spender, amount]
|
|
48065
|
+
});
|
|
48066
|
+
console.log(
|
|
48067
|
+
"[USDT Approve] Waiting for target amount approval transaction confirmation..."
|
|
48068
|
+
);
|
|
48069
|
+
await waitForTransactionReceipt(config, {
|
|
48070
|
+
hash: approveHash,
|
|
48071
|
+
chainId: targetChainId
|
|
48072
|
+
});
|
|
48073
|
+
console.log("[USDT Approve] Double approval process completed");
|
|
48074
|
+
} catch (err) {
|
|
48075
|
+
const errorMessage = err instanceof Error ? err.message : "Authorization operation failed";
|
|
48076
|
+
setError(errorMessage);
|
|
48077
|
+
throw err;
|
|
48078
|
+
} finally {
|
|
48079
|
+
setIsLoading(false);
|
|
48080
|
+
}
|
|
47995
48081
|
};
|
|
47996
|
-
};
|
|
48082
|
+
return { handleApprove, error, isLoading };
|
|
48083
|
+
}
|
|
47997
48084
|
var buttonStyles = {
|
|
47998
48085
|
w: "100%",
|
|
47999
48086
|
h: {
|
|
@@ -48167,7 +48254,7 @@ var FormButton = ({
|
|
|
48167
48254
|
startLoading();
|
|
48168
48255
|
const vCode = extractVPathSegment();
|
|
48169
48256
|
const fromAddress = fromTokenInfo.isSolana ? solanaWalletAddress || "" : effectiveEvmAddress || "";
|
|
48170
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48257
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48171
48258
|
if (fromAddress && fromAmount) {
|
|
48172
48259
|
console.log(
|
|
48173
48260
|
"[Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48202,7 +48289,9 @@ var FormButton = ({
|
|
|
48202
48289
|
effectiveEvmAddress,
|
|
48203
48290
|
solanaWalletAddress,
|
|
48204
48291
|
differentAddress,
|
|
48205
|
-
slippage
|
|
48292
|
+
slippage,
|
|
48293
|
+
config?.evmDifferentAddress,
|
|
48294
|
+
config?.solanaDifferentAddress
|
|
48206
48295
|
]
|
|
48207
48296
|
);
|
|
48208
48297
|
const { sendTransaction, isPending } = useSendTransaction({
|
|
@@ -48492,7 +48581,7 @@ var FormButton = ({
|
|
|
48492
48581
|
/* @__PURE__ */ jsx(Icon, { w: "24px", h: "24px", as: WalletIcon }),
|
|
48493
48582
|
/* @__PURE__ */ jsxs(Heading, { variant: buttonHeadingVariant, children: [
|
|
48494
48583
|
"Connect ",
|
|
48495
|
-
name
|
|
48584
|
+
name ,
|
|
48496
48585
|
" Wallet"
|
|
48497
48586
|
] })
|
|
48498
48587
|
] });
|
|
@@ -48567,7 +48656,7 @@ var FormButton = ({
|
|
|
48567
48656
|
startLoading();
|
|
48568
48657
|
const vCode = extractVPathSegment();
|
|
48569
48658
|
const fromAddress = solanaWalletAddress || "";
|
|
48570
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48659
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48571
48660
|
if (fromAddress && fromAmount) {
|
|
48572
48661
|
console.log(
|
|
48573
48662
|
"[Solana Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48608,28 +48697,17 @@ var FormButton = ({
|
|
|
48608
48697
|
}
|
|
48609
48698
|
) });
|
|
48610
48699
|
}
|
|
48611
|
-
if (
|
|
48700
|
+
if (!fromTokenInfo.isSolana && !hasEvmUiWallet) {
|
|
48701
|
+
return renderEvmWalletConnectButton("EVM");
|
|
48702
|
+
}
|
|
48703
|
+
if (fromTokenInfo.isSolana && !solanaWalletAddress) {
|
|
48612
48704
|
return renderSolanaWalletConnectButton();
|
|
48613
48705
|
}
|
|
48614
|
-
if (
|
|
48706
|
+
if (fromTokenInfo.isSolana && !toTokenInfo.isSolana && !skipEvmWalletConnect && !hasEvmUiWallet) {
|
|
48615
48707
|
return renderEvmWalletConnectButton("EVM");
|
|
48616
48708
|
}
|
|
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
|
-
}
|
|
48709
|
+
if (!fromTokenInfo.isSolana && toTokenInfo.isSolana && !skipSolanaWalletConnect && !solanaWalletAddress) {
|
|
48710
|
+
return renderSolanaWalletConnectButton();
|
|
48633
48711
|
}
|
|
48634
48712
|
if (isFetching || fromAmount && !toAmount) {
|
|
48635
48713
|
return /* @__PURE__ */ jsx(
|