From 953b60831a26b9263975e8ffd3a186b56026617c Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sat, 16 Nov 2024 04:02:44 +0200 Subject: [PATCH] fix send coin and balance btc --- src/qortalRequests/get.ts | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts index a7b13f9..7c84cb0 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -1405,6 +1405,10 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE 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; let skip = false; if (value) { @@ -1457,7 +1461,7 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE case "BTC": _url = await createEndpoint(`/crosschain/btc/walletbalance`); - _body = parsedData.derivedMasterPublicKey; + _body = parsedData.btcPublicKey; break; case "LTC": _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?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, + fee: fee * QORT_DECIMALS }, isFromExtension); const { accepted } = resPermission; @@ -2122,7 +2127,7 @@ export const sendCoin = async (data, isFromExtension) => { const btcWalletBalanceDecimals = Number(btcWalletBalance) const btcAmountDecimals = Number(amount) * QORT_DECIMALS const fee = feePerByte * 500 // default 0.00050000 - if (btcAmountDecimals + (fee * QORT_DECIMALS) > btcWalletBalanceDecimals) { + if (btcAmountDecimals + fee > btcWalletBalanceDecimals) { 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?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} BTC` }, isFromExtension); const { accepted } = resPermission; @@ -2139,7 +2144,7 @@ export const sendCoin = async (data, isFromExtension) => { xprv58: xprv58, receivingAddress: recipient, bitcoinAmount: amount, - feePerByte: feePerByte * QORT_DECIMALS + feePerByte: feePerByte } const url = await createEndpoint(`/crosschain/btc/send`); @@ -2180,14 +2185,14 @@ export const sendCoin = async (data, isFromExtension) => { const ltcAmountDecimals = Number(amount) * QORT_DECIMALS const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8) const fee = feePerByte * 1000 // default 0.00030000 - if (ltcAmountDecimals + (fee * QORT_DECIMALS) > ltcWalletBalanceDecimals) { + if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) { throw new Error("Insufficient Funds!") } const resPermission = await getUserPermission({ text1: "Do you give this application permission to send coins?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} LTC` }, isFromExtension); const { accepted } = resPermission; @@ -2197,7 +2202,7 @@ export const sendCoin = async (data, isFromExtension) => { xprv58: xprv58, receivingAddress: recipient, litecoinAmount: amount, - feePerByte: feePerByte * QORT_DECIMALS + feePerByte: feePerByte } const response = await fetch(url, { method: 'POST', @@ -2235,7 +2240,7 @@ export const sendCoin = async (data, isFromExtension) => { const dogeAmountDecimals = Number(amount) * QORT_DECIMALS const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8) const fee = feePerByte * 5000 // default 0.05000000 - if (dogeAmountDecimals + (fee * QORT_DECIMALS) > dogeWalletBalanceDecimals) { + if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) { let errorMsg = "Insufficient Funds!" throw new Error(errorMsg) } @@ -2244,7 +2249,7 @@ export const sendCoin = async (data, isFromExtension) => { text1: "Do you give this application permission to send coins?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} DOGE` }, isFromExtension); const { accepted } = resPermission; @@ -2253,7 +2258,7 @@ export const sendCoin = async (data, isFromExtension) => { xprv58: xprv58, receivingAddress: recipient, dogecoinAmount: amount, - feePerByte: feePerByte * QORT_DECIMALS + feePerByte: feePerByte } const url = await createEndpoint(`/crosschain/doge/send`); @@ -2290,7 +2295,7 @@ export const sendCoin = async (data, isFromExtension) => { const dgbWalletBalanceDecimals = Number(dgbWalletBalance) const dgbAmountDecimals = Number(amount) * QORT_DECIMALS const fee = feePerByte * 500 // default 0.00005000 - if (dgbAmountDecimals + (fee * QORT_DECIMALS) > dgbWalletBalanceDecimals) { + if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) { let errorMsg = "Insufficient Funds!" throw new Error(errorMsg) } @@ -2299,7 +2304,7 @@ export const sendCoin = async (data, isFromExtension) => { text1: "Do you give this application permission to send coins?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} DGB` }, isFromExtension); const { accepted } = resPermission; @@ -2308,7 +2313,7 @@ export const sendCoin = async (data, isFromExtension) => { xprv58: xprv58, receivingAddress: recipient, digibyteAmount: amount, - feePerByte: feePerByte * QORT_DECIMALS + feePerByte: feePerByte } const url = await createEndpoint(`/crosschain/dgb/send`); @@ -2347,7 +2352,7 @@ export const sendCoin = async (data, isFromExtension) => { const rvnAmountDecimals = Number(amount) * QORT_DECIMALS const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8) const fee = feePerByte * 500 // default 0.00562500 - if (rvnAmountDecimals + (fee * QORT_DECIMALS) > rvnWalletBalanceDecimals) { + if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) { let errorMsg = "Insufficient Funds!" throw new Error(errorMsg) @@ -2357,7 +2362,7 @@ export const sendCoin = async (data, isFromExtension) => { text1: "Do you give this application permission to send coins?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} RVN` }, isFromExtension); const { accepted } = resPermission; @@ -2366,7 +2371,7 @@ export const sendCoin = async (data, isFromExtension) => { xprv58: xprv58, receivingAddress: recipient, ravencoinAmount: amount, - feePerByte: feePerByte * QORT_DECIMALS + feePerByte: feePerByte } const url = await createEndpoint(`/crosschain/rvn/send`); @@ -2402,7 +2407,7 @@ export const sendCoin = async (data, isFromExtension) => { const arrrWalletBalanceDecimals = Number(arrrWalletBalance) const arrrAmountDecimals = Number(amount) * QORT_DECIMALS const fee = 0.00010000 - if (arrrAmountDecimals + (fee * QORT_DECIMALS) > arrrWalletBalanceDecimals) { + if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) { let errorMsg = "Insufficient Funds!" throw new Error(errorMsg) } @@ -2411,7 +2416,7 @@ export const sendCoin = async (data, isFromExtension) => { text1: "Do you give this application permission to send coins?", text2: `To: ${recipient}`, highlightedText: `${amount} ${checkCoin}`, - fee: fee + foreignFee: `${fee} ARRR` }, isFromExtension); const { accepted } = resPermission;