@wheelx-widget/widget 0.1.16 → 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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +116 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -74,6 +74,11 @@ interface WidgetConfig {
|
|
|
74
74
|
evmDifferentAddress?: string;
|
|
75
75
|
/** Solana链固定收款异地址(base58格式)。配置后,to网络为Solana链时优先使用此地址 */
|
|
76
76
|
solanaDifferentAddress?: string;
|
|
77
|
+
/**
|
|
78
|
+
* 返佣ID(affiliation code)。
|
|
79
|
+
* 配置后在 quote 请求中优先使用此值;为空时回退到从 URL path 中提取。
|
|
80
|
+
*/
|
|
81
|
+
affiliation?: string;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
interface WheelXProviderProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,11 @@ interface WidgetConfig {
|
|
|
74
74
|
evmDifferentAddress?: string;
|
|
75
75
|
/** Solana链固定收款异地址(base58格式)。配置后,to网络为Solana链时优先使用此地址 */
|
|
76
76
|
solanaDifferentAddress?: string;
|
|
77
|
+
/**
|
|
78
|
+
* 返佣ID(affiliation code)。
|
|
79
|
+
* 配置后在 quote 请求中优先使用此值;为空时回退到从 URL path 中提取。
|
|
80
|
+
*/
|
|
81
|
+
affiliation?: string;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
interface WheelXProviderProps {
|
package/dist/index.js
CHANGED
|
@@ -48010,14 +48010,107 @@ var OptimizedImage = React5.forwardRef(
|
|
|
48010
48010
|
}
|
|
48011
48011
|
);
|
|
48012
48012
|
OptimizedImage.displayName = "OptimizedImage";
|
|
48013
|
-
|
|
48014
|
-
|
|
48015
|
-
|
|
48016
|
-
|
|
48017
|
-
|
|
48018
|
-
|
|
48013
|
+
var usdtAbi = [
|
|
48014
|
+
{
|
|
48015
|
+
name: "approve",
|
|
48016
|
+
type: "function",
|
|
48017
|
+
stateMutability: "nonpayable",
|
|
48018
|
+
inputs: [
|
|
48019
|
+
{ name: "_spender", type: "address" },
|
|
48020
|
+
{ name: "_value", type: "uint256" }
|
|
48021
|
+
],
|
|
48022
|
+
outputs: [{ name: "", type: "bool" }]
|
|
48023
|
+
},
|
|
48024
|
+
{
|
|
48025
|
+
name: "allowance",
|
|
48026
|
+
type: "function",
|
|
48027
|
+
stateMutability: "view",
|
|
48028
|
+
inputs: [
|
|
48029
|
+
{ name: "_owner", type: "address" },
|
|
48030
|
+
{ name: "_spender", type: "address" }
|
|
48031
|
+
],
|
|
48032
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
48033
|
+
}
|
|
48034
|
+
];
|
|
48035
|
+
function useUSDTHandler(chainId) {
|
|
48036
|
+
const config = wagmi.useConfig();
|
|
48037
|
+
const { address: owner } = wagmi.useAccount();
|
|
48038
|
+
const [error, setError] = React5.useState(null);
|
|
48039
|
+
const [isLoading, setIsLoading] = React5.useState(false);
|
|
48040
|
+
const handleApprove = async (tokenAddress, spender, amount) => {
|
|
48041
|
+
setError(null);
|
|
48042
|
+
setIsLoading(true);
|
|
48043
|
+
try {
|
|
48044
|
+
if (!owner) {
|
|
48045
|
+
const errorMsg = "No account available. Please connect your wallet and try again.";
|
|
48046
|
+
setError(errorMsg);
|
|
48047
|
+
throw new Error(errorMsg);
|
|
48048
|
+
}
|
|
48049
|
+
const targetChainId = chainId ?? 1;
|
|
48050
|
+
console.log("[USDT Approve] Reading allowance:", {
|
|
48051
|
+
chainId: targetChainId,
|
|
48052
|
+
tokenAddress,
|
|
48053
|
+
owner,
|
|
48054
|
+
spender
|
|
48055
|
+
});
|
|
48056
|
+
const currentAllowance = await readContract(config, {
|
|
48057
|
+
abi: usdtAbi,
|
|
48058
|
+
address: tokenAddress,
|
|
48059
|
+
functionName: "allowance",
|
|
48060
|
+
chainId: targetChainId,
|
|
48061
|
+
args: [owner, spender]
|
|
48062
|
+
});
|
|
48063
|
+
console.log("[USDT Approve] Current allowance:", currentAllowance.toString());
|
|
48064
|
+
if (currentAllowance >= amount) {
|
|
48065
|
+
console.log(
|
|
48066
|
+
"[USDT Approve] Allowance is sufficient, no additional approval needed"
|
|
48067
|
+
);
|
|
48068
|
+
return;
|
|
48069
|
+
}
|
|
48070
|
+
if (currentAllowance > 0n) {
|
|
48071
|
+
console.log("[USDT Approve] Performing allowance reset to zero");
|
|
48072
|
+
const zeroApproveHash = await writeContract(config, {
|
|
48073
|
+
abi: usdtAbi,
|
|
48074
|
+
address: tokenAddress,
|
|
48075
|
+
functionName: "approve",
|
|
48076
|
+
chainId: targetChainId,
|
|
48077
|
+
args: [spender, 0n]
|
|
48078
|
+
});
|
|
48079
|
+
console.log(
|
|
48080
|
+
"[USDT Approve] Waiting for zero-approval transaction confirmation..."
|
|
48081
|
+
);
|
|
48082
|
+
await waitForTransactionReceipt(config, {
|
|
48083
|
+
hash: zeroApproveHash,
|
|
48084
|
+
chainId: targetChainId
|
|
48085
|
+
});
|
|
48086
|
+
console.log("[USDT Approve] Zero-approval completed");
|
|
48087
|
+
}
|
|
48088
|
+
console.log("[USDT Approve] Performing target amount approval");
|
|
48089
|
+
const approveHash = await writeContract(config, {
|
|
48090
|
+
abi: usdtAbi,
|
|
48091
|
+
address: tokenAddress,
|
|
48092
|
+
functionName: "approve",
|
|
48093
|
+
chainId: targetChainId,
|
|
48094
|
+
args: [spender, amount]
|
|
48095
|
+
});
|
|
48096
|
+
console.log(
|
|
48097
|
+
"[USDT Approve] Waiting for target amount approval transaction confirmation..."
|
|
48098
|
+
);
|
|
48099
|
+
await waitForTransactionReceipt(config, {
|
|
48100
|
+
hash: approveHash,
|
|
48101
|
+
chainId: targetChainId
|
|
48102
|
+
});
|
|
48103
|
+
console.log("[USDT Approve] Double approval process completed");
|
|
48104
|
+
} catch (err) {
|
|
48105
|
+
const errorMessage = err instanceof Error ? err.message : "Authorization operation failed";
|
|
48106
|
+
setError(errorMessage);
|
|
48107
|
+
throw err;
|
|
48108
|
+
} finally {
|
|
48109
|
+
setIsLoading(false);
|
|
48110
|
+
}
|
|
48019
48111
|
};
|
|
48020
|
-
};
|
|
48112
|
+
return { handleApprove, error, isLoading };
|
|
48113
|
+
}
|
|
48021
48114
|
var buttonStyles = {
|
|
48022
48115
|
w: "100%",
|
|
48023
48116
|
h: {
|
|
@@ -48191,7 +48284,7 @@ var FormButton = ({
|
|
|
48191
48284
|
startLoading();
|
|
48192
48285
|
const vCode = extractVPathSegment();
|
|
48193
48286
|
const fromAddress = fromTokenInfo.isSolana ? solanaWalletAddress || "" : effectiveEvmAddress || "";
|
|
48194
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48287
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48195
48288
|
if (fromAddress && fromAmount) {
|
|
48196
48289
|
console.log(
|
|
48197
48290
|
"[Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48226,7 +48319,9 @@ var FormButton = ({
|
|
|
48226
48319
|
effectiveEvmAddress,
|
|
48227
48320
|
solanaWalletAddress,
|
|
48228
48321
|
differentAddress,
|
|
48229
|
-
slippage
|
|
48322
|
+
slippage,
|
|
48323
|
+
config?.evmDifferentAddress,
|
|
48324
|
+
config?.solanaDifferentAddress
|
|
48230
48325
|
]
|
|
48231
48326
|
);
|
|
48232
48327
|
const { sendTransaction, isPending } = wagmi.useSendTransaction({
|
|
@@ -48516,7 +48611,7 @@ var FormButton = ({
|
|
|
48516
48611
|
/* @__PURE__ */ jsxRuntime.jsx(react.Icon, { w: "24px", h: "24px", as: WalletIcon }),
|
|
48517
48612
|
/* @__PURE__ */ jsxRuntime.jsxs(Heading, { variant: buttonHeadingVariant, children: [
|
|
48518
48613
|
"Connect ",
|
|
48519
|
-
name
|
|
48614
|
+
name ,
|
|
48520
48615
|
" Wallet"
|
|
48521
48616
|
] })
|
|
48522
48617
|
] });
|
|
@@ -48591,7 +48686,7 @@ var FormButton = ({
|
|
|
48591
48686
|
startLoading();
|
|
48592
48687
|
const vCode = extractVPathSegment();
|
|
48593
48688
|
const fromAddress = solanaWalletAddress || "";
|
|
48594
|
-
const toAddress = toTokenInfo.isSolana ? solanaWalletAddress || "" : differentAddress || effectiveEvmAddress || "";
|
|
48689
|
+
const toAddress = toTokenInfo.isSolana ? config?.solanaDifferentAddress || solanaWalletAddress || "" : config?.evmDifferentAddress || differentAddress || effectiveEvmAddress || "";
|
|
48595
48690
|
if (fromAddress && fromAmount) {
|
|
48596
48691
|
console.log(
|
|
48597
48692
|
"[Solana Transaction] Refetching quote after transaction rejection..."
|
|
@@ -48632,28 +48727,17 @@ var FormButton = ({
|
|
|
48632
48727
|
}
|
|
48633
48728
|
) });
|
|
48634
48729
|
}
|
|
48635
|
-
if (
|
|
48730
|
+
if (!fromTokenInfo.isSolana && !hasEvmUiWallet) {
|
|
48731
|
+
return renderEvmWalletConnectButton("EVM");
|
|
48732
|
+
}
|
|
48733
|
+
if (fromTokenInfo.isSolana && !solanaWalletAddress) {
|
|
48636
48734
|
return renderSolanaWalletConnectButton();
|
|
48637
48735
|
}
|
|
48638
|
-
if (
|
|
48736
|
+
if (fromTokenInfo.isSolana && !toTokenInfo.isSolana && !skipEvmWalletConnect && !hasEvmUiWallet) {
|
|
48639
48737
|
return renderEvmWalletConnectButton("EVM");
|
|
48640
48738
|
}
|
|
48641
|
-
if (!
|
|
48642
|
-
|
|
48643
|
-
return renderSolanaWalletConnectButton();
|
|
48644
|
-
}
|
|
48645
|
-
return renderEvmWalletConnectButton();
|
|
48646
|
-
} else if (!hasEvmUiWallet && solanaWalletAddress) {
|
|
48647
|
-
if (!fromTokenInfo.isSolana && !toTokenInfo.isSolana || !fromTokenInfo.isSolana && toTokenInfo.isSolana || fromTokenInfo.isSolana && !toTokenInfo.isSolana && !skipEvmWalletConnect) {
|
|
48648
|
-
return renderEvmWalletConnectButton("EVM");
|
|
48649
|
-
}
|
|
48650
|
-
} else if (hasEvmUiWallet && !solanaWalletAddress) {
|
|
48651
|
-
if (fromTokenInfo.isSolana || toTokenInfo.isSolana && !skipSolanaWalletConnect) {
|
|
48652
|
-
return renderSolanaWalletConnectButton();
|
|
48653
|
-
}
|
|
48654
|
-
if (fromTokenInfo.isSolana && toTokenInfo.isSolana || !fromTokenInfo.isSolana && toTokenInfo.isSolana && !skipSolanaWalletConnect || fromTokenInfo.isSolana && !toTokenInfo.isSolana) {
|
|
48655
|
-
return renderSolanaWalletConnectButton();
|
|
48656
|
-
}
|
|
48739
|
+
if (!fromTokenInfo.isSolana && toTokenInfo.isSolana && !skipSolanaWalletConnect && !solanaWalletAddress) {
|
|
48740
|
+
return renderSolanaWalletConnectButton();
|
|
48657
48741
|
}
|
|
48658
48742
|
if (isFetching || fromAmount && !toAmount) {
|
|
48659
48743
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -55861,6 +55945,8 @@ var MainForm = ({ config }) => {
|
|
|
55861
55945
|
const prevAddressRef = React5.useRef(address);
|
|
55862
55946
|
const prevSolanaAddressRef = React5.useRef(solanaWalletAddress);
|
|
55863
55947
|
const isWalletChangingRef = React5.useRef(false);
|
|
55948
|
+
const affiliationRef = React5.useRef(config?.affiliation);
|
|
55949
|
+
affiliationRef.current = config?.affiliation;
|
|
55864
55950
|
const fromAddress = React5.useMemo(() => {
|
|
55865
55951
|
if (fromTokenInfo.isSolana) {
|
|
55866
55952
|
return solanaWalletAddress || "";
|
|
@@ -55933,6 +56019,7 @@ var MainForm = ({ config }) => {
|
|
|
55933
56019
|
}
|
|
55934
56020
|
}
|
|
55935
56021
|
const p = params;
|
|
56022
|
+
p.affiliation = affiliationRef.current || p.affiliation;
|
|
55936
56023
|
const isAutoRefetchRequest = Boolean(isAutoRefetch);
|
|
55937
56024
|
const traceId = createTraceId();
|
|
55938
56025
|
const requestStartedAt = Date.now();
|