mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-20 10:05:56 +00:00
added other buy/sell order coins
This commit is contained in:
parent
1394bb349b
commit
e91098990e
@ -30,6 +30,7 @@ import { RequestQueueWithPromise } from "./utils/queue/queue";
|
||||
import { validateAddress } from "./utils/validateAddress";
|
||||
import { Sha256 } from "asmcrypto.js";
|
||||
import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMultipleRequest";
|
||||
|
||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
||||
import {
|
||||
addDataPublishesCase,
|
||||
@ -98,6 +99,7 @@ import {
|
||||
voteOnPollCase,
|
||||
} from "./background-cases";
|
||||
import { getData, removeKeysAndLogout, storeData } from "./utils/chromeStorage";
|
||||
import TradeBotRespondRequest from "./transactions/TradeBotRespondRequest";
|
||||
// import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
|
||||
|
||||
export let groupSecretkeys = {}
|
||||
@ -239,7 +241,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
|
||||
}
|
||||
@ -1762,20 +1773,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,
|
||||
{
|
||||
@ -1787,6 +1820,7 @@ export async function createBuyOrderTx({ crosschainAtInfo, isGateway, foreignBlo
|
||||
}
|
||||
);
|
||||
|
||||
if(!responseFetch?.ok) throw new Error('Failed to submit buy order')
|
||||
const res = await responseFetch.json();
|
||||
|
||||
if (res === false) {
|
||||
|
@ -58,6 +58,26 @@ const sellerForeignFee = {
|
||||
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",
|
||||
},
|
||||
};
|
||||
|
||||
const btcFeePerByte = 0.000001;
|
||||
@ -1873,6 +1893,28 @@ export const getWalletBalance = async (
|
||||
}
|
||||
};
|
||||
|
||||
const getPirateWallet = async (arrrSeed58)=> {
|
||||
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();
|
||||
@ -1885,26 +1927,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;
|
||||
@ -2492,7 +2542,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");
|
||||
@ -2549,8 +2599,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!");
|
||||
@ -2596,7 +2645,6 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
} else if (checkCoin === "DOGE") {
|
||||
const amount = Number(data.amount);
|
||||
const recipient = data.destinationAddress;
|
||||
const coin = data.coin;
|
||||
const xprv58 = parsedData.dogePrivateKey;
|
||||
const feePerByte = data.fee ? data.fee : dogeFeePerByte;
|
||||
const dogeWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
||||
@ -2605,8 +2653,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!";
|
||||
@ -2663,7 +2710,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!";
|
||||
@ -2712,7 +2759,6 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
} else if (checkCoin === "RVN") {
|
||||
const amount = Number(data.amount);
|
||||
const recipient = data.destinationAddress;
|
||||
const coin = data.coin;
|
||||
const xprv58 = parsedData.rvnPrivateKey;
|
||||
const feePerByte = data.fee ? data.fee : rvnFeePerByte;
|
||||
const rvnWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
||||
@ -2721,8 +2767,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) {
|
||||
let errorMsg = "Insufficient Funds!";
|
||||
@ -2771,7 +2816,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))) {
|
||||
@ -2779,7 +2824,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.0001;
|
||||
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
||||
let errorMsg = "Insufficient Funds!";
|
||||
@ -2804,7 +2849,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
arrrAmount: amount,
|
||||
memo: memo,
|
||||
};
|
||||
const url = await createEndpoint(`/crosschain/btc/send`);
|
||||
const url = await createEndpoint(`/crosschain/arrr/send`);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
@ -3023,7 +3068,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(
|
||||
{
|
||||
|
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