fix send coin and balance btc

This commit is contained in:
PhilReact 2024-11-16 04:02:44 +02:00
parent 76825e9f07
commit 953b60831a

View File

@ -1405,6 +1405,10 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE
throw new Error(errorMsg); throw new Error(errorMsg);
} }
const isGateway = await isRunningGateway()
if(data?.coin === 'ARRR' && isGateway) throw new Error('Cannot view ARRR balance through the gateway. Please use your local node.')
const value = (await getPermission(`qAPPAutoWalletBalance-${appInfo?.name}-${data.coin}`)) || false; const value = (await getPermission(`qAPPAutoWalletBalance-${appInfo?.name}-${data.coin}`)) || false;
let skip = false; let skip = false;
if (value) { if (value) {
@ -1457,7 +1461,7 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE
case "BTC": case "BTC":
_url = await createEndpoint(`/crosschain/btc/walletbalance`); _url = await createEndpoint(`/crosschain/btc/walletbalance`);
_body = parsedData.derivedMasterPublicKey; _body = parsedData.btcPublicKey;
break; break;
case "LTC": case "LTC":
_url = await createEndpoint(`/crosschain/ltc/walletbalance`); _url = await createEndpoint(`/crosschain/ltc/walletbalance`);
@ -2098,6 +2102,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee * QORT_DECIMALS
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2122,7 +2127,7 @@ export const sendCoin = async (data, isFromExtension) => {
const btcWalletBalanceDecimals = Number(btcWalletBalance) const btcWalletBalanceDecimals = Number(btcWalletBalance)
const btcAmountDecimals = Number(amount) * QORT_DECIMALS const btcAmountDecimals = Number(amount) * QORT_DECIMALS
const fee = feePerByte * 500 // default 0.00050000 const fee = feePerByte * 500 // default 0.00050000
if (btcAmountDecimals + (fee * QORT_DECIMALS) > btcWalletBalanceDecimals) { if (btcAmountDecimals + fee > btcWalletBalanceDecimals) {
throw new Error("INSUFFICIENT_FUNDS") throw new Error("INSUFFICIENT_FUNDS")
} }
@ -2130,7 +2135,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} BTC`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2139,7 +2144,7 @@ export const sendCoin = async (data, isFromExtension) => {
xprv58: xprv58, xprv58: xprv58,
receivingAddress: recipient, receivingAddress: recipient,
bitcoinAmount: amount, bitcoinAmount: amount,
feePerByte: feePerByte * QORT_DECIMALS feePerByte: feePerByte
} }
const url = await createEndpoint(`/crosschain/btc/send`); const url = await createEndpoint(`/crosschain/btc/send`);
@ -2180,14 +2185,14 @@ export const sendCoin = async (data, isFromExtension) => {
const ltcAmountDecimals = Number(amount) * QORT_DECIMALS const ltcAmountDecimals = Number(amount) * QORT_DECIMALS
const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8) const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8)
const fee = feePerByte * 1000 // default 0.00030000 const fee = feePerByte * 1000 // default 0.00030000
if (ltcAmountDecimals + (fee * QORT_DECIMALS) > ltcWalletBalanceDecimals) { if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) {
throw new Error("Insufficient Funds!") throw new Error("Insufficient Funds!")
} }
const resPermission = await getUserPermission({ const resPermission = await getUserPermission({
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} LTC`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2197,7 +2202,7 @@ export const sendCoin = async (data, isFromExtension) => {
xprv58: xprv58, xprv58: xprv58,
receivingAddress: recipient, receivingAddress: recipient,
litecoinAmount: amount, litecoinAmount: amount,
feePerByte: feePerByte * QORT_DECIMALS feePerByte: feePerByte
} }
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
@ -2235,7 +2240,7 @@ export const sendCoin = async (data, isFromExtension) => {
const dogeAmountDecimals = Number(amount) * QORT_DECIMALS const dogeAmountDecimals = Number(amount) * QORT_DECIMALS
const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8) const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8)
const fee = feePerByte * 5000 // default 0.05000000 const fee = feePerByte * 5000 // default 0.05000000
if (dogeAmountDecimals + (fee * QORT_DECIMALS) > dogeWalletBalanceDecimals) { if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) {
let errorMsg = "Insufficient Funds!" let errorMsg = "Insufficient Funds!"
throw new Error(errorMsg) throw new Error(errorMsg)
} }
@ -2244,7 +2249,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} DOGE`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2253,7 +2258,7 @@ export const sendCoin = async (data, isFromExtension) => {
xprv58: xprv58, xprv58: xprv58,
receivingAddress: recipient, receivingAddress: recipient,
dogecoinAmount: amount, dogecoinAmount: amount,
feePerByte: feePerByte * QORT_DECIMALS feePerByte: feePerByte
} }
const url = await createEndpoint(`/crosschain/doge/send`); const url = await createEndpoint(`/crosschain/doge/send`);
@ -2290,7 +2295,7 @@ export const sendCoin = async (data, isFromExtension) => {
const dgbWalletBalanceDecimals = Number(dgbWalletBalance) const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
const dgbAmountDecimals = Number(amount) * QORT_DECIMALS const dgbAmountDecimals = Number(amount) * QORT_DECIMALS
const fee = feePerByte * 500 // default 0.00005000 const fee = feePerByte * 500 // default 0.00005000
if (dgbAmountDecimals + (fee * QORT_DECIMALS) > dgbWalletBalanceDecimals) { if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) {
let errorMsg = "Insufficient Funds!" let errorMsg = "Insufficient Funds!"
throw new Error(errorMsg) throw new Error(errorMsg)
} }
@ -2299,7 +2304,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} DGB`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2308,7 +2313,7 @@ export const sendCoin = async (data, isFromExtension) => {
xprv58: xprv58, xprv58: xprv58,
receivingAddress: recipient, receivingAddress: recipient,
digibyteAmount: amount, digibyteAmount: amount,
feePerByte: feePerByte * QORT_DECIMALS feePerByte: feePerByte
} }
const url = await createEndpoint(`/crosschain/dgb/send`); const url = await createEndpoint(`/crosschain/dgb/send`);
@ -2347,7 +2352,7 @@ export const sendCoin = async (data, isFromExtension) => {
const rvnAmountDecimals = Number(amount) * QORT_DECIMALS const rvnAmountDecimals = Number(amount) * QORT_DECIMALS
const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8) const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8)
const fee = feePerByte * 500 // default 0.00562500 const fee = feePerByte * 500 // default 0.00562500
if (rvnAmountDecimals + (fee * QORT_DECIMALS) > rvnWalletBalanceDecimals) { if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) {
let errorMsg = "Insufficient Funds!" let errorMsg = "Insufficient Funds!"
throw new Error(errorMsg) throw new Error(errorMsg)
@ -2357,7 +2362,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} RVN`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;
@ -2366,7 +2371,7 @@ export const sendCoin = async (data, isFromExtension) => {
xprv58: xprv58, xprv58: xprv58,
receivingAddress: recipient, receivingAddress: recipient,
ravencoinAmount: amount, ravencoinAmount: amount,
feePerByte: feePerByte * QORT_DECIMALS feePerByte: feePerByte
} }
const url = await createEndpoint(`/crosschain/rvn/send`); const url = await createEndpoint(`/crosschain/rvn/send`);
@ -2402,7 +2407,7 @@ export const sendCoin = async (data, isFromExtension) => {
const arrrWalletBalanceDecimals = Number(arrrWalletBalance) const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
const arrrAmountDecimals = Number(amount) * QORT_DECIMALS const arrrAmountDecimals = Number(amount) * QORT_DECIMALS
const fee = 0.00010000 const fee = 0.00010000
if (arrrAmountDecimals + (fee * QORT_DECIMALS) > arrrWalletBalanceDecimals) { if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
let errorMsg = "Insufficient Funds!" let errorMsg = "Insufficient Funds!"
throw new Error(errorMsg) throw new Error(errorMsg)
} }
@ -2411,7 +2416,7 @@ export const sendCoin = async (data, isFromExtension) => {
text1: "Do you give this application permission to send coins?", text1: "Do you give this application permission to send coins?",
text2: `To: ${recipient}`, text2: `To: ${recipient}`,
highlightedText: `${amount} ${checkCoin}`, highlightedText: `${amount} ${checkCoin}`,
fee: fee foreignFee: `${fee} ARRR`
}, isFromExtension); }, isFromExtension);
const { accepted } = resPermission; const { accepted } = resPermission;