mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-03-14 20:02:33 +00:00
added other foreign coins
This commit is contained in:
parent
156e0d10a3
commit
780ccab33a
@ -104,6 +104,7 @@ import { getData, removeKeysAndLogout, storeData } from "./utils/chromeStorage";
|
||||
import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
|
||||
import { LocalNotifications } from '@capacitor/local-notifications';
|
||||
import { executeEvent } from "./utils/events";
|
||||
import TradeBotRespondRequest from "./transactions/TradeBotRespondRequest";
|
||||
|
||||
const uid = new ShortUniqueId({ length: 9, dictionary: 'number' });
|
||||
|
||||
@ -207,7 +208,16 @@ export const getForeignKey = async (foreignBlockchain)=> {
|
||||
switch (foreignBlockchain) {
|
||||
case "LITECOIN":
|
||||
return parsedData.ltcPrivateKey
|
||||
|
||||
case "DOGECOIN":
|
||||
return parsedData.dogePrivateKey
|
||||
case "BITCOIN":
|
||||
return parsedData.btcPrivateKey
|
||||
case "DIGIBYTE":
|
||||
return parsedData.dgbPrivateKey
|
||||
case "RAVENCOIN":
|
||||
return parsedData.rvnPrivateKey
|
||||
case "PIRATECHAIN":
|
||||
return parsedData.arrrSeed58
|
||||
default:
|
||||
return null
|
||||
}
|
||||
@ -1636,20 +1646,42 @@ export async function createBuyOrderTx({ crosschainAtInfo, isGateway, foreignBlo
|
||||
const wallet = await getSaveWallet();
|
||||
|
||||
const address = wallet.address0;
|
||||
|
||||
const message = {
|
||||
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||
foreignKey: await getForeignKey(foreignBlockchain),
|
||||
receivingAddress: address,
|
||||
};
|
||||
let responseVar;
|
||||
const txn = new TradeBotRespondMultipleRequest().createTransaction(
|
||||
message
|
||||
);
|
||||
let message
|
||||
if(foreignBlockchain === 'PIRATECHAIN'){
|
||||
console.log('crosschainAtInfo', crosschainAtInfo, crosschainAtInfo[0].qortalAtAddress)
|
||||
message = {
|
||||
atAddress: crosschainAtInfo[0].qortalAtAddress,
|
||||
foreignKey: await getForeignKey(foreignBlockchain),
|
||||
receivingAddress: address,
|
||||
};
|
||||
} else {
|
||||
message = {
|
||||
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||
foreignKey: await getForeignKey(foreignBlockchain),
|
||||
receivingAddress: address,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const url = await createEndpoint('/crosschain/tradebot/respondmultiple')
|
||||
|
||||
let responseVar;
|
||||
let txn
|
||||
let url
|
||||
if(foreignBlockchain === 'PIRATECHAIN'){
|
||||
txn = new TradeBotRespondRequest().createTransaction(
|
||||
message
|
||||
);
|
||||
|
||||
|
||||
url = await createEndpoint('/crosschain/tradebot/respond')
|
||||
} else {
|
||||
txn = new TradeBotRespondMultipleRequest().createTransaction(
|
||||
message
|
||||
);
|
||||
|
||||
|
||||
url = await createEndpoint('/crosschain/tradebot/respondmultiple')
|
||||
}
|
||||
|
||||
console.log('txn', txn, JSON.stringify(txn))
|
||||
const responseFetch = await fetch(
|
||||
url,
|
||||
{
|
||||
@ -1661,6 +1693,7 @@ export async function createBuyOrderTx({ crosschainAtInfo, isGateway, foreignBlo
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
const res = await responseFetch.json();
|
||||
|
||||
if (res === false) {
|
||||
|
@ -53,11 +53,31 @@ const dgbFeePerByte = 0.00000010
|
||||
const rvnFeePerByte = 0.00001125
|
||||
|
||||
const sellerForeignFee = {
|
||||
'LITECOIN': {
|
||||
value: '~0.00005',
|
||||
ticker: 'LTC'
|
||||
}
|
||||
}
|
||||
LITECOIN: {
|
||||
value: "~0.00005",
|
||||
ticker: "LTC",
|
||||
},
|
||||
DOGECOIN: {
|
||||
value: "~0.005",
|
||||
ticker: "DOGE",
|
||||
},
|
||||
BITCOIN: {
|
||||
value: "~0.0001",
|
||||
ticker: "BTC",
|
||||
},
|
||||
DIGIBYTE: {
|
||||
value: "~0.0005",
|
||||
ticker: "DGB",
|
||||
},
|
||||
RAVENCOIN: {
|
||||
value: "~0.006",
|
||||
ticker: "RVN",
|
||||
},
|
||||
PIRATECHAIN: {
|
||||
value: "~0.0002",
|
||||
ticker: "ARRR",
|
||||
},
|
||||
};
|
||||
|
||||
function roundUpToDecimals(number, decimals = 8) {
|
||||
const factor = Math.pow(10, decimals); // Create a factor based on the number of decimals
|
||||
@ -1806,6 +1826,33 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE
|
||||
}
|
||||
};
|
||||
|
||||
const getPirateWallet = async (arrrSeed58)=> {
|
||||
const isGateway = await isRunningGateway();
|
||||
if (isGateway) {
|
||||
throw new Error("Retrieving PIRATECHAIN balance is not allowed through a gateway.");
|
||||
}
|
||||
const bodyToString = arrrSeed58;
|
||||
const url = await createEndpoint(`/crosschain/arrr/walletaddress`);
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: bodyToString,
|
||||
});
|
||||
let res;
|
||||
try {
|
||||
res = await response.clone().json();
|
||||
} catch (e) {
|
||||
res = await response.text();
|
||||
}
|
||||
if (res?.error && res?.message) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
export const getUserWalletFunc = async (coin) => {
|
||||
let userWallet = {};
|
||||
const wallet = await getSaveWallet();
|
||||
@ -1818,26 +1865,34 @@ export const getUserWalletFunc = async (coin) => {
|
||||
userWallet["publickey"] = parsedData.publicKey;
|
||||
break;
|
||||
case "BTC":
|
||||
case "BITCOIN":
|
||||
userWallet["address"] = parsedData.btcAddress;
|
||||
userWallet["publickey"] = parsedData.btcPublicKey;
|
||||
break;
|
||||
case "LTC":
|
||||
case "LITECOIN":
|
||||
userWallet["address"] = parsedData.ltcAddress;
|
||||
userWallet["publickey"] = parsedData.ltcPublicKey;
|
||||
break;
|
||||
case "DOGE":
|
||||
case "DOGECOIN":
|
||||
userWallet["address"] = parsedData.dogeAddress;
|
||||
userWallet["publickey"] = parsedData.dogePublicKey;
|
||||
break;
|
||||
case "DGB":
|
||||
case "DIGIBYTE":
|
||||
userWallet["address"] = parsedData.dgbAddress;
|
||||
userWallet["publickey"] = parsedData.dgbPublicKey;
|
||||
break;
|
||||
case "RVN":
|
||||
case "RAVENCOIN":
|
||||
userWallet["address"] = parsedData.rvnAddress;
|
||||
userWallet["publickey"] = parsedData.rvnPublicKey;
|
||||
break;
|
||||
case "ARRR":
|
||||
case "PIRATECHAIN":
|
||||
const arrrAddress = await getPirateWallet(parsedData.arrrSeed58)
|
||||
userWallet["address"] = arrrAddress
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -2414,7 +2469,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error('Unable to fetch BTC balance')
|
||||
}
|
||||
const btcWalletBalanceDecimals = Number(btcWalletBalance)
|
||||
const btcAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const btcAmountDecimals = Number(amount)
|
||||
const fee = feePerByte * 500 // default 0.00050000
|
||||
if (btcAmountDecimals + fee > btcWalletBalanceDecimals) {
|
||||
throw new Error("INSUFFICIENT_FUNDS")
|
||||
@ -2471,8 +2526,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
const ltcWalletBalanceDecimals = Number(ltcWalletBalance)
|
||||
const ltcAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8)
|
||||
const ltcAmountDecimals = Number(amount)
|
||||
const fee = feePerByte * 1000 // default 0.00030000
|
||||
if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) {
|
||||
throw new Error("Insufficient Funds!")
|
||||
@ -2526,8 +2580,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
const dogeWalletBalanceDecimals = Number(dogeWalletBalance)
|
||||
const dogeAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8)
|
||||
const dogeAmountDecimals = Number(amount)
|
||||
const fee = feePerByte * 5000 // default 0.05000000
|
||||
if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) {
|
||||
let errorMsg = "Insufficient Funds!"
|
||||
@ -2582,7 +2635,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
|
||||
const dgbAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const dgbAmountDecimals = Number(amount)
|
||||
const fee = feePerByte * 500 // default 0.00005000
|
||||
if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) {
|
||||
let errorMsg = "Insufficient Funds!"
|
||||
@ -2638,8 +2691,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
const rvnWalletBalanceDecimals = Number(rvnWalletBalance)
|
||||
const rvnAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8)
|
||||
const rvnAmountDecimals = Number(amount)
|
||||
const fee = feePerByte * 500 // default 0.00562500
|
||||
if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) {
|
||||
|
||||
@ -2686,7 +2738,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
} else if (checkCoin === "ARRR") {
|
||||
const amount = Number(data.amount)
|
||||
const recipient = data.destinationAddress
|
||||
const memo = data.memo
|
||||
const memo = data?.memo
|
||||
const arrrWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
||||
|
||||
if (isNaN(Number(arrrWalletBalance))) {
|
||||
@ -2694,7 +2746,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
|
||||
const arrrAmountDecimals = Number(amount) * QORT_DECIMALS
|
||||
const arrrAmountDecimals = Number(amount)
|
||||
const fee = 0.00010000
|
||||
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
||||
let errorMsg = "Insufficient Funds!"
|
||||
@ -2951,7 +3003,7 @@ export const createSellOrder = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
||||
const receivingAddress = await getUserWalletFunc('LTC')
|
||||
const receivingAddress = await getUserWalletFunc(data.foreignBlockchain)
|
||||
try {
|
||||
const resPermission = await getUserPermission({
|
||||
text1: "Do you give this application permission to perform a sell order?",
|
||||
|
41
src/transactions/TradeBotRespondRequest.ts
Normal file
41
src/transactions/TradeBotRespondRequest.ts
Normal file
@ -0,0 +1,41 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* CrossChain - TradeBot Respond Request (Buy Action)
|
||||
*
|
||||
* These are special types of transactions (JSON ENCODED)
|
||||
*/
|
||||
|
||||
export default class TradeBotRespondRequest {
|
||||
constructor() {
|
||||
// ...
|
||||
}
|
||||
|
||||
createTransaction(txnReq) {
|
||||
this.atAddress(txnReq.atAddress)
|
||||
this.foreignKey(txnReq.foreignKey)
|
||||
this.receivingAddress(txnReq.receivingAddress)
|
||||
|
||||
return this.txnRequest()
|
||||
}
|
||||
|
||||
atAddress(atAddress) {
|
||||
this._atAddress = atAddress
|
||||
}
|
||||
|
||||
foreignKey(foreignKey) {
|
||||
this._foreignKey = foreignKey
|
||||
}
|
||||
|
||||
receivingAddress(receivingAddress) {
|
||||
this._receivingAddress = receivingAddress
|
||||
}
|
||||
|
||||
txnRequest() {
|
||||
return {
|
||||
atAddress: this._atAddress,
|
||||
foreignKey: this._foreignKey,
|
||||
receivingAddress: this._receivingAddress
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user