mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-05-13 21:27:51 +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 {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
|
||||||
import { LocalNotifications } from '@capacitor/local-notifications';
|
import { LocalNotifications } from '@capacitor/local-notifications';
|
||||||
import { executeEvent } from "./utils/events";
|
import { executeEvent } from "./utils/events";
|
||||||
|
import TradeBotRespondRequest from "./transactions/TradeBotRespondRequest";
|
||||||
|
|
||||||
const uid = new ShortUniqueId({ length: 9, dictionary: 'number' });
|
const uid = new ShortUniqueId({ length: 9, dictionary: 'number' });
|
||||||
|
|
||||||
@ -207,7 +208,16 @@ export const getForeignKey = async (foreignBlockchain)=> {
|
|||||||
switch (foreignBlockchain) {
|
switch (foreignBlockchain) {
|
||||||
case "LITECOIN":
|
case "LITECOIN":
|
||||||
return parsedData.ltcPrivateKey
|
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:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -1636,20 +1646,42 @@ export async function createBuyOrderTx({ crosschainAtInfo, isGateway, foreignBlo
|
|||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
|
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
|
let message
|
||||||
const message = {
|
if(foreignBlockchain === 'PIRATECHAIN'){
|
||||||
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
console.log('crosschainAtInfo', crosschainAtInfo, crosschainAtInfo[0].qortalAtAddress)
|
||||||
foreignKey: await getForeignKey(foreignBlockchain),
|
message = {
|
||||||
receivingAddress: address,
|
atAddress: crosschainAtInfo[0].qortalAtAddress,
|
||||||
};
|
foreignKey: await getForeignKey(foreignBlockchain),
|
||||||
let responseVar;
|
receivingAddress: address,
|
||||||
const txn = new TradeBotRespondMultipleRequest().createTransaction(
|
};
|
||||||
message
|
} else {
|
||||||
);
|
message = {
|
||||||
|
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
|
foreignKey: await getForeignKey(foreignBlockchain),
|
||||||
|
receivingAddress: address,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let responseVar;
|
||||||
const url = await createEndpoint('/crosschain/tradebot/respondmultiple')
|
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(
|
const responseFetch = await fetch(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
@ -1661,6 +1693,7 @@ export async function createBuyOrderTx({ crosschainAtInfo, isGateway, foreignBlo
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const res = await responseFetch.json();
|
const res = await responseFetch.json();
|
||||||
|
|
||||||
if (res === false) {
|
if (res === false) {
|
||||||
|
@ -53,11 +53,31 @@ const dgbFeePerByte = 0.00000010
|
|||||||
const rvnFeePerByte = 0.00001125
|
const rvnFeePerByte = 0.00001125
|
||||||
|
|
||||||
const sellerForeignFee = {
|
const sellerForeignFee = {
|
||||||
'LITECOIN': {
|
LITECOIN: {
|
||||||
value: '~0.00005',
|
value: "~0.00005",
|
||||||
ticker: 'LTC'
|
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) {
|
function roundUpToDecimals(number, decimals = 8) {
|
||||||
const factor = Math.pow(10, decimals); // Create a factor based on the number of decimals
|
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) => {
|
export const getUserWalletFunc = async (coin) => {
|
||||||
let userWallet = {};
|
let userWallet = {};
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
@ -1818,26 +1865,34 @@ export const getUserWalletFunc = async (coin) => {
|
|||||||
userWallet["publickey"] = parsedData.publicKey;
|
userWallet["publickey"] = parsedData.publicKey;
|
||||||
break;
|
break;
|
||||||
case "BTC":
|
case "BTC":
|
||||||
|
case "BITCOIN":
|
||||||
userWallet["address"] = parsedData.btcAddress;
|
userWallet["address"] = parsedData.btcAddress;
|
||||||
userWallet["publickey"] = parsedData.btcPublicKey;
|
userWallet["publickey"] = parsedData.btcPublicKey;
|
||||||
break;
|
break;
|
||||||
case "LTC":
|
case "LTC":
|
||||||
|
case "LITECOIN":
|
||||||
userWallet["address"] = parsedData.ltcAddress;
|
userWallet["address"] = parsedData.ltcAddress;
|
||||||
userWallet["publickey"] = parsedData.ltcPublicKey;
|
userWallet["publickey"] = parsedData.ltcPublicKey;
|
||||||
break;
|
break;
|
||||||
case "DOGE":
|
case "DOGE":
|
||||||
|
case "DOGECOIN":
|
||||||
userWallet["address"] = parsedData.dogeAddress;
|
userWallet["address"] = parsedData.dogeAddress;
|
||||||
userWallet["publickey"] = parsedData.dogePublicKey;
|
userWallet["publickey"] = parsedData.dogePublicKey;
|
||||||
break;
|
break;
|
||||||
case "DGB":
|
case "DGB":
|
||||||
|
case "DIGIBYTE":
|
||||||
userWallet["address"] = parsedData.dgbAddress;
|
userWallet["address"] = parsedData.dgbAddress;
|
||||||
userWallet["publickey"] = parsedData.dgbPublicKey;
|
userWallet["publickey"] = parsedData.dgbPublicKey;
|
||||||
break;
|
break;
|
||||||
case "RVN":
|
case "RVN":
|
||||||
|
case "RAVENCOIN":
|
||||||
userWallet["address"] = parsedData.rvnAddress;
|
userWallet["address"] = parsedData.rvnAddress;
|
||||||
userWallet["publickey"] = parsedData.rvnPublicKey;
|
userWallet["publickey"] = parsedData.rvnPublicKey;
|
||||||
break;
|
break;
|
||||||
case "ARRR":
|
case "ARRR":
|
||||||
|
case "PIRATECHAIN":
|
||||||
|
const arrrAddress = await getPirateWallet(parsedData.arrrSeed58)
|
||||||
|
userWallet["address"] = arrrAddress
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -2414,7 +2469,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error('Unable to fetch BTC balance')
|
throw new Error('Unable to fetch BTC balance')
|
||||||
}
|
}
|
||||||
const btcWalletBalanceDecimals = Number(btcWalletBalance)
|
const btcWalletBalanceDecimals = Number(btcWalletBalance)
|
||||||
const btcAmountDecimals = Number(amount) * QORT_DECIMALS
|
const btcAmountDecimals = Number(amount)
|
||||||
const fee = feePerByte * 500 // default 0.00050000
|
const fee = feePerByte * 500 // default 0.00050000
|
||||||
if (btcAmountDecimals + fee > btcWalletBalanceDecimals) {
|
if (btcAmountDecimals + fee > btcWalletBalanceDecimals) {
|
||||||
throw new Error("INSUFFICIENT_FUNDS")
|
throw new Error("INSUFFICIENT_FUNDS")
|
||||||
@ -2471,8 +2526,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const ltcWalletBalanceDecimals = Number(ltcWalletBalance)
|
const ltcWalletBalanceDecimals = Number(ltcWalletBalance)
|
||||||
const ltcAmountDecimals = Number(amount) * QORT_DECIMALS
|
const ltcAmountDecimals = Number(amount)
|
||||||
const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8)
|
|
||||||
const fee = feePerByte * 1000 // default 0.00030000
|
const fee = feePerByte * 1000 // default 0.00030000
|
||||||
if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) {
|
if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) {
|
||||||
throw new Error("Insufficient Funds!")
|
throw new Error("Insufficient Funds!")
|
||||||
@ -2526,8 +2580,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const dogeWalletBalanceDecimals = Number(dogeWalletBalance)
|
const dogeWalletBalanceDecimals = Number(dogeWalletBalance)
|
||||||
const dogeAmountDecimals = Number(amount) * QORT_DECIMALS
|
const dogeAmountDecimals = Number(amount)
|
||||||
const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8)
|
|
||||||
const fee = feePerByte * 5000 // default 0.05000000
|
const fee = feePerByte * 5000 // default 0.05000000
|
||||||
if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) {
|
if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
@ -2582,7 +2635,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
|
const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
|
||||||
const dgbAmountDecimals = Number(amount) * QORT_DECIMALS
|
const dgbAmountDecimals = Number(amount)
|
||||||
const fee = feePerByte * 500 // default 0.00005000
|
const fee = feePerByte * 500 // default 0.00005000
|
||||||
if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) {
|
if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
@ -2638,8 +2691,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const rvnWalletBalanceDecimals = Number(rvnWalletBalance)
|
const rvnWalletBalanceDecimals = Number(rvnWalletBalance)
|
||||||
const rvnAmountDecimals = Number(amount) * QORT_DECIMALS
|
const rvnAmountDecimals = Number(amount)
|
||||||
const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8)
|
|
||||||
const fee = feePerByte * 500 // default 0.00562500
|
const fee = feePerByte * 500 // default 0.00562500
|
||||||
if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) {
|
if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) {
|
||||||
|
|
||||||
@ -2686,7 +2738,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
} else if (checkCoin === "ARRR") {
|
} else if (checkCoin === "ARRR") {
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data.destinationAddress
|
||||||
const memo = data.memo
|
const memo = data?.memo
|
||||||
const arrrWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
const arrrWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
||||||
|
|
||||||
if (isNaN(Number(arrrWalletBalance))) {
|
if (isNaN(Number(arrrWalletBalance))) {
|
||||||
@ -2694,7 +2746,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
|
const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
|
||||||
const arrrAmountDecimals = Number(amount) * QORT_DECIMALS
|
const arrrAmountDecimals = Number(amount)
|
||||||
const fee = 0.00010000
|
const fee = 0.00010000
|
||||||
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
@ -2951,7 +3003,7 @@ export const createSellOrder = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const receivingAddress = await getUserWalletFunc('LTC')
|
const receivingAddress = await getUserWalletFunc(data.foreignBlockchain)
|
||||||
try {
|
try {
|
||||||
const resPermission = await getUserPermission({
|
const resPermission = await getUserPermission({
|
||||||
text1: "Do you give this application permission to perform a sell order?",
|
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