@aurora-is-near/intents-swap-widget 3.4.2 → 3.5.0
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createWalletClient as h, custom as E, encodeFunctionData as p, erc20Abi as
|
|
2
|
-
import { polygon as
|
|
1
|
+
import { createWalletClient as h, custom as E, encodeFunctionData as p, erc20Abi as d } from "viem";
|
|
2
|
+
import { polygon as M, optimism as b, base as g, bsc as V, arbitrum as k, gnosis as v, mainnet as I } from "viem/chains";
|
|
3
3
|
import "../constants/chains.js";
|
|
4
4
|
import { isEvmChain as N } from "../utils/evm/isEvmChain.js";
|
|
5
5
|
import "ethers";
|
|
@@ -7,64 +7,65 @@ import { getTransactionLink as w } from "../utils/formatters/getTransactionLink.
|
|
|
7
7
|
import "../utils/cn.js";
|
|
8
8
|
import { isEvmAddress as l } from "../utils/evm/isEvmAddress.js";
|
|
9
9
|
import { switchEthereumChain as T } from "../utils/evm/switchEthereumChain.js";
|
|
10
|
-
const
|
|
10
|
+
const A = {
|
|
11
11
|
eth: I,
|
|
12
12
|
gnosis: v,
|
|
13
13
|
arb: k,
|
|
14
14
|
bsc: V,
|
|
15
|
-
base:
|
|
16
|
-
op:
|
|
17
|
-
pol:
|
|
15
|
+
base: g,
|
|
16
|
+
op: b,
|
|
17
|
+
pol: M,
|
|
18
18
|
bera: null,
|
|
19
19
|
avax: null
|
|
20
20
|
}, F = () => ({ make: async ({
|
|
21
|
-
address:
|
|
21
|
+
address: r,
|
|
22
22
|
amount: i,
|
|
23
|
-
tokenAddress:
|
|
24
|
-
evmChainId:
|
|
23
|
+
tokenAddress: n,
|
|
24
|
+
evmChainId: o,
|
|
25
25
|
isNativeEthTransfer: u,
|
|
26
26
|
chain: e
|
|
27
27
|
}) => {
|
|
28
|
-
if (!l(
|
|
29
|
-
throw new Error(`Invalid EVM address: ${
|
|
30
|
-
if (!
|
|
28
|
+
if (!l(r))
|
|
29
|
+
throw new Error(`Invalid EVM address: ${r}`);
|
|
30
|
+
if (!o)
|
|
31
31
|
throw new Error("EVM chain ID is required for EVM transfers.");
|
|
32
32
|
if (!window.ethereum)
|
|
33
33
|
throw new Error("No injected Ethereum wallet found.");
|
|
34
|
-
await T(
|
|
35
|
-
const
|
|
34
|
+
await T(o);
|
|
35
|
+
const a = h({
|
|
36
36
|
transport: E(window.ethereum)
|
|
37
|
-
})
|
|
38
|
-
|
|
37
|
+
});
|
|
38
|
+
let [t] = await a.getAddresses();
|
|
39
|
+
if (t || ([t] = await a.requestAddresses()), !t)
|
|
39
40
|
throw new Error("No EVM account found in the injected wallet.");
|
|
40
|
-
const s = N(e) ?
|
|
41
|
+
const s = N(e) ? A[e] : null;
|
|
41
42
|
if (u) {
|
|
42
|
-
const m = await
|
|
43
|
-
account:
|
|
44
|
-
to:
|
|
43
|
+
const m = await a.sendTransaction({
|
|
44
|
+
account: t,
|
|
45
|
+
to: r,
|
|
45
46
|
value: BigInt(i),
|
|
46
47
|
chain: s
|
|
47
48
|
});
|
|
48
49
|
return {
|
|
49
50
|
hash: m,
|
|
50
|
-
transactionLink: w(
|
|
51
|
+
transactionLink: w(o, m)
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
if (!
|
|
54
|
-
throw new Error(`Invalid EVM token address: ${
|
|
54
|
+
if (!n || !l(n))
|
|
55
|
+
throw new Error(`Invalid EVM token address: ${n}`);
|
|
55
56
|
const f = p({
|
|
56
|
-
abi:
|
|
57
|
+
abi: d,
|
|
57
58
|
functionName: "transfer",
|
|
58
|
-
args: [
|
|
59
|
-
}), c = await
|
|
60
|
-
account:
|
|
61
|
-
to:
|
|
59
|
+
args: [r, BigInt(i)]
|
|
60
|
+
}), c = await a.sendTransaction({
|
|
61
|
+
account: t,
|
|
62
|
+
to: n,
|
|
62
63
|
data: f,
|
|
63
64
|
chain: s
|
|
64
65
|
});
|
|
65
66
|
return {
|
|
66
67
|
hash: c,
|
|
67
|
-
transactionLink: w(
|
|
68
|
+
transactionLink: w(o, c)
|
|
68
69
|
};
|
|
69
70
|
} });
|
|
70
71
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMakeEvmTransfer.js","sources":["../../src/hooks/useMakeEvmTransfer.ts"],"sourcesContent":["import {\n Chain,\n createWalletClient,\n custom,\n EIP1193Provider,\n encodeFunctionData,\n erc20Abi,\n} from 'viem';\nimport {\n arbitrum,\n base,\n bsc,\n gnosis,\n mainnet,\n optimism,\n polygon,\n} from 'viem/chains';\nimport { getTransactionLink, isEvmChain } from '../utils';\nimport { MakeTransferArgs } from '../types';\nimport { isEvmAddress } from '../utils/evm/isEvmAddress';\nimport { switchEthereumChain } from '../utils/evm/switchEthereumChain';\nimport { EVM_CHAINS } from '../constants';\n\ndeclare global {\n interface Window {\n ethereum?: EIP1193Provider;\n }\n}\n\nconst VIEM_CHAIN_MAP: Record<(typeof EVM_CHAINS)[number], Chain | null> = {\n eth: mainnet,\n gnosis,\n arb: arbitrum,\n bsc,\n base,\n op: optimism,\n pol: polygon,\n bera: null,\n avax: null,\n};\n\nexport const useMakeEvmTransfer = () => {\n const make = async ({\n address,\n amount,\n tokenAddress,\n evmChainId,\n isNativeEthTransfer,\n chain: chainKey,\n }: MakeTransferArgs) => {\n if (!isEvmAddress(address)) {\n throw new Error(`Invalid EVM address: ${address}`);\n }\n\n if (!evmChainId) {\n throw new Error('EVM chain ID is required for EVM transfers.');\n }\n\n if (!window.ethereum) {\n throw new Error('No injected Ethereum wallet found.');\n }\n\n // Automatically switch to the correct chain if needed\n await switchEthereumChain(evmChainId);\n\n // Create wallet client from injected wallet (e.g. MetaMask)\n const walletClient = createWalletClient({\n transport: custom(window.ethereum),\n });\n\n
|
|
1
|
+
{"version":3,"file":"useMakeEvmTransfer.js","sources":["../../src/hooks/useMakeEvmTransfer.ts"],"sourcesContent":["import {\n Chain,\n createWalletClient,\n custom,\n EIP1193Provider,\n encodeFunctionData,\n erc20Abi,\n} from 'viem';\nimport {\n arbitrum,\n base,\n bsc,\n gnosis,\n mainnet,\n optimism,\n polygon,\n} from 'viem/chains';\nimport { getTransactionLink, isEvmChain } from '../utils';\nimport { MakeTransferArgs } from '../types';\nimport { isEvmAddress } from '../utils/evm/isEvmAddress';\nimport { switchEthereumChain } from '../utils/evm/switchEthereumChain';\nimport { EVM_CHAINS } from '../constants';\n\ndeclare global {\n interface Window {\n ethereum?: EIP1193Provider;\n }\n}\n\nconst VIEM_CHAIN_MAP: Record<(typeof EVM_CHAINS)[number], Chain | null> = {\n eth: mainnet,\n gnosis,\n arb: arbitrum,\n bsc,\n base,\n op: optimism,\n pol: polygon,\n bera: null,\n avax: null,\n};\n\nexport const useMakeEvmTransfer = () => {\n const make = async ({\n address,\n amount,\n tokenAddress,\n evmChainId,\n isNativeEthTransfer,\n chain: chainKey,\n }: MakeTransferArgs) => {\n if (!isEvmAddress(address)) {\n throw new Error(`Invalid EVM address: ${address}`);\n }\n\n if (!evmChainId) {\n throw new Error('EVM chain ID is required for EVM transfers.');\n }\n\n if (!window.ethereum) {\n throw new Error('No injected Ethereum wallet found.');\n }\n\n // Automatically switch to the correct chain if needed\n await switchEthereumChain(evmChainId);\n\n // Create wallet client from injected wallet (e.g. MetaMask, AppKit)\n const walletClient = createWalletClient({\n transport: custom(window.ethereum),\n });\n\n // Try to get addresses without prompting first (works for MetaMask and already-connected wallets)\n let [from] = await walletClient.getAddresses();\n\n // Fallback: If no address found, request addresses (needed for AppKit/WalletConnect)\n if (!from) {\n [from] = await walletClient.requestAddresses();\n }\n\n if (!from) {\n throw new Error('No EVM account found in the injected wallet.');\n }\n\n const chain = isEvmChain(chainKey) ? VIEM_CHAIN_MAP[chainKey] : null;\n\n // Native ETH transfer\n if (isNativeEthTransfer) {\n const hash = await walletClient.sendTransaction({\n account: from,\n to: address,\n value: BigInt(amount),\n chain,\n });\n\n return {\n hash,\n transactionLink: getTransactionLink(evmChainId, hash),\n };\n }\n\n if (!tokenAddress || !isEvmAddress(tokenAddress)) {\n throw new Error(`Invalid EVM token address: ${tokenAddress}`);\n }\n\n // ERC20 transfer\n const data = encodeFunctionData({\n abi: erc20Abi,\n functionName: 'transfer',\n args: [address, BigInt(amount)],\n });\n\n const hash = await walletClient.sendTransaction({\n account: from,\n to: tokenAddress,\n data,\n chain,\n });\n\n return {\n hash,\n transactionLink: getTransactionLink(evmChainId, hash),\n };\n };\n\n return { make };\n};\n"],"names":["VIEM_CHAIN_MAP","mainnet","gnosis","arbitrum","bsc","base","optimism","polygon","useMakeEvmTransfer","address","amount","tokenAddress","evmChainId","isNativeEthTransfer","chainKey","isEvmAddress","switchEthereumChain","walletClient","createWalletClient","custom","from","chain","isEvmChain","hash","getTransactionLink","data","encodeFunctionData","erc20Abi"],"mappings":";;;;;;;;;AA6BA,MAAMA,IAAoE;AAAA,EACxE,KAAKC;AAAA,EACL,QAAAC;AAAA,EACA,KAAKC;AAAA,EACL,KAAAC;AAAA,EACA,MAAAC;AAAA,EACA,IAAIC;AAAA,EACJ,KAAKC;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AACR,GAEaC,IAAqB,OAkFzB,EAAE,MAjFI,OAAO;AAAA,EAClB,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,cAAAC;AAAA,EACA,YAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,OAAOC;AAAA,MACe;AACtB,MAAI,CAACC,EAAaN,CAAO;AACvB,UAAM,IAAI,MAAM,wBAAwBA,CAAO,EAAE;AAGnD,MAAI,CAACG;AACH,UAAM,IAAI,MAAM,6CAA6C;AAG/D,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,oCAAoC;AAItD,QAAMI,EAAoBJ,CAAU;AAGpC,QAAMK,IAAeC,EAAmB;AAAA,IACtC,WAAWC,EAAO,OAAO,QAAQ;AAAA,EAAA,CAClC;AAGD,MAAI,CAACC,CAAI,IAAI,MAAMH,EAAa,aAAA;AAOhC,MAJKG,MACH,CAACA,CAAI,IAAI,MAAMH,EAAa,iBAAA,IAG1B,CAACG;AACH,UAAM,IAAI,MAAM,8CAA8C;AAGhE,QAAMC,IAAQC,EAAWR,CAAQ,IAAId,EAAec,CAAQ,IAAI;AAGhE,MAAID,GAAqB;AACvB,UAAMU,IAAO,MAAMN,EAAa,gBAAgB;AAAA,MAC9C,SAASG;AAAA,MACT,IAAIX;AAAA,MACJ,OAAO,OAAOC,CAAM;AAAA,MACpB,OAAAW;AAAA,IAAA,CACD;AAED,WAAO;AAAA,MACL,MAAAE;AAAAA,MACA,iBAAiBC,EAAmBZ,GAAYW,CAAI;AAAA,IAAA;AAAA,EAExD;AAEA,MAAI,CAACZ,KAAgB,CAACI,EAAaJ,CAAY;AAC7C,UAAM,IAAI,MAAM,8BAA8BA,CAAY,EAAE;AAI9D,QAAMc,IAAOC,EAAmB;AAAA,IAC9B,KAAKC;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAClB,GAAS,OAAOC,CAAM,CAAC;AAAA,EAAA,CAC/B,GAEKa,IAAO,MAAMN,EAAa,gBAAgB;AAAA,IAC9C,SAASG;AAAA,IACT,IAAIT;AAAA,IACJ,MAAAc;AAAA,IACA,OAAAJ;AAAA,EAAA,CACD;AAED,SAAO;AAAA,IACL,MAAAE;AAAA,IACA,iBAAiBC,EAAmBZ,GAAYW,CAAI;AAAA,EAAA;AAExD,EAES;"}
|
package/package.json
CHANGED
|
@@ -63,12 +63,18 @@ export const useMakeEvmTransfer = () => {
|
|
|
63
63
|
// Automatically switch to the correct chain if needed
|
|
64
64
|
await switchEthereumChain(evmChainId);
|
|
65
65
|
|
|
66
|
-
// Create wallet client from injected wallet (e.g. MetaMask)
|
|
66
|
+
// Create wallet client from injected wallet (e.g. MetaMask, AppKit)
|
|
67
67
|
const walletClient = createWalletClient({
|
|
68
68
|
transport: custom(window.ethereum),
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
// Try to get addresses without prompting first (works for MetaMask and already-connected wallets)
|
|
72
|
+
let [from] = await walletClient.getAddresses();
|
|
73
|
+
|
|
74
|
+
// Fallback: If no address found, request addresses (needed for AppKit/WalletConnect)
|
|
75
|
+
if (!from) {
|
|
76
|
+
[from] = await walletClient.requestAddresses();
|
|
77
|
+
}
|
|
72
78
|
|
|
73
79
|
if (!from) {
|
|
74
80
|
throw new Error('No EVM account found in the injected wallet.');
|