@spicenet-io/spiceflow-ui 1.2.2 → 1.2.3
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.cjs.js +39 -16
- package/dist/index.js +39 -16
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -2645,7 +2645,7 @@ const useWallet = () => {
|
|
|
2645
2645
|
};
|
|
2646
2646
|
};
|
|
2647
2647
|
|
|
2648
|
-
const RELAYER_API_URL = process.env.NEXT_PUBLIC_RELAYER_API_URL || "
|
|
2648
|
+
const RELAYER_API_URL = process.env.NEXT_PUBLIC_RELAYER_API_URL || "https://tx-api.spicenet.io";
|
|
2649
2649
|
class RelayerService {
|
|
2650
2650
|
constructor() {
|
|
2651
2651
|
this.baseUrl = RELAYER_API_URL;
|
|
@@ -6012,7 +6012,7 @@ const DepositModal = React.memo(
|
|
|
6012
6012
|
const address = embeddedWalletAddress || embeddedWallet?.address;
|
|
6013
6013
|
const sourceAddress = externalWalletAddress;
|
|
6014
6014
|
const { data: externalWalletClient } = wagmi.useWalletClient();
|
|
6015
|
-
wagmi.useSwitchChain();
|
|
6015
|
+
const { switchChainAsync } = wagmi.useSwitchChain();
|
|
6016
6016
|
const { chain: currentChain } = wagmi.useAccount();
|
|
6017
6017
|
const currentChainRef = React.useRef(currentChain);
|
|
6018
6018
|
React.useEffect(() => {
|
|
@@ -6181,11 +6181,6 @@ const DepositModal = React.memo(
|
|
|
6181
6181
|
});
|
|
6182
6182
|
setShowConfirmation(true);
|
|
6183
6183
|
};
|
|
6184
|
-
const isChainMismatchError = (error2) => {
|
|
6185
|
-
const errorMessage = error2?.message || error2?.shortMessage || error2?.details || error2?.cause?.message || error2?.reason || String(error2 || "");
|
|
6186
|
-
const errorString = errorMessage.toLowerCase();
|
|
6187
|
-
return errorString.includes("does not match") || errorString.includes("current chain") || errorString.includes("expected chain") || errorString.includes("chain mismatch") || errorString.includes("target chain") || errorString.includes("the current chain of the wallet") || errorString.includes("chain of the wallet") || errorString.includes("chain") && errorString.includes("match") && errorString.includes("id") || error2?.code && error2.code === 4902 || error2?.name === "ChainMismatchError" || error2?.name === "ChainMismatch";
|
|
6188
|
-
};
|
|
6189
6184
|
const executeDeposit = async () => {
|
|
6190
6185
|
const validAssets = selectedDepositAssets.filter(
|
|
6191
6186
|
(a) => a.asset && a.amount && parseFloat(a.amount) > 0
|
|
@@ -6219,6 +6214,36 @@ const DepositModal = React.memo(
|
|
|
6219
6214
|
if (!externalWalletClient) {
|
|
6220
6215
|
throw new Error("External wallet not connected");
|
|
6221
6216
|
}
|
|
6217
|
+
if (currentChain?.id !== chainId) {
|
|
6218
|
+
setError("Wrong chain selected. Switching network...");
|
|
6219
|
+
try {
|
|
6220
|
+
await switchChainAsync({ chainId });
|
|
6221
|
+
let attempts = 0;
|
|
6222
|
+
const maxAttempts = 20;
|
|
6223
|
+
while (attempts < maxAttempts) {
|
|
6224
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
6225
|
+
if (currentChainRef.current?.id === chainId) {
|
|
6226
|
+
setError(null);
|
|
6227
|
+
break;
|
|
6228
|
+
}
|
|
6229
|
+
attempts++;
|
|
6230
|
+
}
|
|
6231
|
+
if (currentChainRef.current?.id !== chainId) {
|
|
6232
|
+
throw new Error(
|
|
6233
|
+
`Failed to switch to chain ${chainId}. Please switch manually in your wallet.`
|
|
6234
|
+
);
|
|
6235
|
+
}
|
|
6236
|
+
setError(null);
|
|
6237
|
+
} catch (switchError) {
|
|
6238
|
+
if (switchError.code === 4902 || switchError.name === "ChainNotConfiguredError") {
|
|
6239
|
+
throw new Error(
|
|
6240
|
+
`Chain ${chainId} is not configured in your wallet. Please add it manually.`
|
|
6241
|
+
);
|
|
6242
|
+
} else {
|
|
6243
|
+
throw switchError;
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6222
6247
|
if (nonEip7702Mode) {
|
|
6223
6248
|
if (!destinationChainId) {
|
|
6224
6249
|
throw new Error(
|
|
@@ -6492,21 +6517,19 @@ const DepositModal = React.memo(
|
|
|
6492
6517
|
}
|
|
6493
6518
|
} catch (error2) {
|
|
6494
6519
|
hasError = true;
|
|
6495
|
-
const errorMsgText = error2?.message || error2?.shortMessage || error2?.details || error2?.cause?.message || String(error2 || "");
|
|
6496
6520
|
let errorMessage = "Deposit failed";
|
|
6497
|
-
if (
|
|
6498
|
-
const chainId = validAssets[0]?.asset?.chainId;
|
|
6499
|
-
const chainConfig = chainId ? getChainConfig(chainId) : null;
|
|
6500
|
-
const chainName = chainConfig?.displayName || `Chain ${chainId}`;
|
|
6501
|
-
errorMessage = `Wrong network selected. Please switch your wallet to ${chainName} and click the DEPOSIT button again.`;
|
|
6502
|
-
} else if (error2?.code === 4001 || error2?.code === "ACTION_REJECTED") {
|
|
6521
|
+
if (error2?.code === 4001 || error2?.code === "ACTION_REJECTED") {
|
|
6503
6522
|
errorMessage = "Transaction rejected by user";
|
|
6504
6523
|
} else if (error2?.code === -32603) {
|
|
6505
6524
|
errorMessage = "Internal wallet error. Please try again.";
|
|
6506
|
-
} else if (
|
|
6525
|
+
} else if (error2?.message?.includes("insufficient funds")) {
|
|
6507
6526
|
errorMessage = "Insufficient funds for transaction";
|
|
6508
|
-
} else if (
|
|
6527
|
+
} else if (error2?.message?.includes("User rejected")) {
|
|
6528
|
+
errorMessage = "Transaction rejected by user";
|
|
6529
|
+
} else if (error2?.message?.includes("user rejected")) {
|
|
6509
6530
|
errorMessage = "Transaction rejected by user";
|
|
6531
|
+
} else if (error2?.message?.includes("does not match the target chain") || error2?.message?.includes("Current Chain ID")) {
|
|
6532
|
+
errorMessage = "Network mismatch detected. Please click the button again to proceed.";
|
|
6510
6533
|
} else if (error2 instanceof Error) {
|
|
6511
6534
|
errorMessage = error2.message;
|
|
6512
6535
|
} else if (typeof error2 === "string") {
|
package/dist/index.js
CHANGED
|
@@ -2643,7 +2643,7 @@ const useWallet = () => {
|
|
|
2643
2643
|
};
|
|
2644
2644
|
};
|
|
2645
2645
|
|
|
2646
|
-
const RELAYER_API_URL = process.env.NEXT_PUBLIC_RELAYER_API_URL || "
|
|
2646
|
+
const RELAYER_API_URL = process.env.NEXT_PUBLIC_RELAYER_API_URL || "https://tx-api.spicenet.io";
|
|
2647
2647
|
class RelayerService {
|
|
2648
2648
|
constructor() {
|
|
2649
2649
|
this.baseUrl = RELAYER_API_URL;
|
|
@@ -6010,7 +6010,7 @@ const DepositModal = React.memo(
|
|
|
6010
6010
|
const address = embeddedWalletAddress || embeddedWallet?.address;
|
|
6011
6011
|
const sourceAddress = externalWalletAddress;
|
|
6012
6012
|
const { data: externalWalletClient } = useWalletClient();
|
|
6013
|
-
useSwitchChain();
|
|
6013
|
+
const { switchChainAsync } = useSwitchChain();
|
|
6014
6014
|
const { chain: currentChain } = useAccount();
|
|
6015
6015
|
const currentChainRef = React.useRef(currentChain);
|
|
6016
6016
|
React.useEffect(() => {
|
|
@@ -6179,11 +6179,6 @@ const DepositModal = React.memo(
|
|
|
6179
6179
|
});
|
|
6180
6180
|
setShowConfirmation(true);
|
|
6181
6181
|
};
|
|
6182
|
-
const isChainMismatchError = (error2) => {
|
|
6183
|
-
const errorMessage = error2?.message || error2?.shortMessage || error2?.details || error2?.cause?.message || error2?.reason || String(error2 || "");
|
|
6184
|
-
const errorString = errorMessage.toLowerCase();
|
|
6185
|
-
return errorString.includes("does not match") || errorString.includes("current chain") || errorString.includes("expected chain") || errorString.includes("chain mismatch") || errorString.includes("target chain") || errorString.includes("the current chain of the wallet") || errorString.includes("chain of the wallet") || errorString.includes("chain") && errorString.includes("match") && errorString.includes("id") || error2?.code && error2.code === 4902 || error2?.name === "ChainMismatchError" || error2?.name === "ChainMismatch";
|
|
6186
|
-
};
|
|
6187
6182
|
const executeDeposit = async () => {
|
|
6188
6183
|
const validAssets = selectedDepositAssets.filter(
|
|
6189
6184
|
(a) => a.asset && a.amount && parseFloat(a.amount) > 0
|
|
@@ -6217,6 +6212,36 @@ const DepositModal = React.memo(
|
|
|
6217
6212
|
if (!externalWalletClient) {
|
|
6218
6213
|
throw new Error("External wallet not connected");
|
|
6219
6214
|
}
|
|
6215
|
+
if (currentChain?.id !== chainId) {
|
|
6216
|
+
setError("Wrong chain selected. Switching network...");
|
|
6217
|
+
try {
|
|
6218
|
+
await switchChainAsync({ chainId });
|
|
6219
|
+
let attempts = 0;
|
|
6220
|
+
const maxAttempts = 20;
|
|
6221
|
+
while (attempts < maxAttempts) {
|
|
6222
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
6223
|
+
if (currentChainRef.current?.id === chainId) {
|
|
6224
|
+
setError(null);
|
|
6225
|
+
break;
|
|
6226
|
+
}
|
|
6227
|
+
attempts++;
|
|
6228
|
+
}
|
|
6229
|
+
if (currentChainRef.current?.id !== chainId) {
|
|
6230
|
+
throw new Error(
|
|
6231
|
+
`Failed to switch to chain ${chainId}. Please switch manually in your wallet.`
|
|
6232
|
+
);
|
|
6233
|
+
}
|
|
6234
|
+
setError(null);
|
|
6235
|
+
} catch (switchError) {
|
|
6236
|
+
if (switchError.code === 4902 || switchError.name === "ChainNotConfiguredError") {
|
|
6237
|
+
throw new Error(
|
|
6238
|
+
`Chain ${chainId} is not configured in your wallet. Please add it manually.`
|
|
6239
|
+
);
|
|
6240
|
+
} else {
|
|
6241
|
+
throw switchError;
|
|
6242
|
+
}
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6220
6245
|
if (nonEip7702Mode) {
|
|
6221
6246
|
if (!destinationChainId) {
|
|
6222
6247
|
throw new Error(
|
|
@@ -6490,21 +6515,19 @@ const DepositModal = React.memo(
|
|
|
6490
6515
|
}
|
|
6491
6516
|
} catch (error2) {
|
|
6492
6517
|
hasError = true;
|
|
6493
|
-
const errorMsgText = error2?.message || error2?.shortMessage || error2?.details || error2?.cause?.message || String(error2 || "");
|
|
6494
6518
|
let errorMessage = "Deposit failed";
|
|
6495
|
-
if (
|
|
6496
|
-
const chainId = validAssets[0]?.asset?.chainId;
|
|
6497
|
-
const chainConfig = chainId ? getChainConfig(chainId) : null;
|
|
6498
|
-
const chainName = chainConfig?.displayName || `Chain ${chainId}`;
|
|
6499
|
-
errorMessage = `Wrong network selected. Please switch your wallet to ${chainName} and click the DEPOSIT button again.`;
|
|
6500
|
-
} else if (error2?.code === 4001 || error2?.code === "ACTION_REJECTED") {
|
|
6519
|
+
if (error2?.code === 4001 || error2?.code === "ACTION_REJECTED") {
|
|
6501
6520
|
errorMessage = "Transaction rejected by user";
|
|
6502
6521
|
} else if (error2?.code === -32603) {
|
|
6503
6522
|
errorMessage = "Internal wallet error. Please try again.";
|
|
6504
|
-
} else if (
|
|
6523
|
+
} else if (error2?.message?.includes("insufficient funds")) {
|
|
6505
6524
|
errorMessage = "Insufficient funds for transaction";
|
|
6506
|
-
} else if (
|
|
6525
|
+
} else if (error2?.message?.includes("User rejected")) {
|
|
6526
|
+
errorMessage = "Transaction rejected by user";
|
|
6527
|
+
} else if (error2?.message?.includes("user rejected")) {
|
|
6507
6528
|
errorMessage = "Transaction rejected by user";
|
|
6529
|
+
} else if (error2?.message?.includes("does not match the target chain") || error2?.message?.includes("Current Chain ID")) {
|
|
6530
|
+
errorMessage = "Network mismatch detected. Please click the button again to proceed.";
|
|
6508
6531
|
} else if (error2 instanceof Error) {
|
|
6509
6532
|
errorMessage = error2.message;
|
|
6510
6533
|
} else if (typeof error2 === "string") {
|