|
|
|
@ -537,19 +537,32 @@ Reference: ${invoiceRef}`; |
|
|
|
const decimals = Number(walletButton.dataset.decimals || "18"); |
|
|
|
const decimals = Number(walletButton.dataset.decimals || "18"); |
|
|
|
const tokenContract = walletButton.dataset.tokenContract || ""; |
|
|
|
const tokenContract = walletButton.dataset.tokenContract || ""; |
|
|
|
|
|
|
|
|
|
|
|
await window.ethereum.request({ method: "eth_requestAccounts" }); |
|
|
|
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" }); |
|
|
|
|
|
|
|
const from = Array.isArray(accounts) && accounts.length ? accounts[0] : ""; |
|
|
|
|
|
|
|
if (!from) { |
|
|
|
|
|
|
|
throw new Error("Wallet did not return an account address."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await switchChain(chainId); |
|
|
|
await switchChain(chainId); |
|
|
|
|
|
|
|
|
|
|
|
let txHash; |
|
|
|
let txHash; |
|
|
|
if (assetType === "native") { |
|
|
|
if (assetType === "native") { |
|
|
|
txHash = await window.ethereum.request({ |
|
|
|
txHash = await window.ethereum.request({ |
|
|
|
method: "eth_sendTransaction", |
|
|
|
method: "eth_sendTransaction", |
|
|
|
params: [{ to: to, value: toHexBigIntFromDecimal(amount, decimals) }] |
|
|
|
params: [{ |
|
|
|
|
|
|
|
from: from, |
|
|
|
|
|
|
|
to: to, |
|
|
|
|
|
|
|
value: toHexBigIntFromDecimal(amount, decimals) |
|
|
|
|
|
|
|
}] |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
txHash = await window.ethereum.request({ |
|
|
|
txHash = await window.ethereum.request({ |
|
|
|
method: "eth_sendTransaction", |
|
|
|
method: "eth_sendTransaction", |
|
|
|
params: [{ to: tokenContract, data: erc20TransferData(to, amount, decimals) }] |
|
|
|
params: [{ |
|
|
|
|
|
|
|
from: from, |
|
|
|
|
|
|
|
to: tokenContract, |
|
|
|
|
|
|
|
data: erc20TransferData(to, amount, decimals) |
|
|
|
|
|
|
|
}] |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|