mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +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 { validateAddress } from "./utils/validateAddress";
|
||||||
import { Sha256 } from "asmcrypto.js";
|
import { Sha256 } from "asmcrypto.js";
|
||||||
import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMultipleRequest";
|
import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMultipleRequest";
|
||||||
|
|
||||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
||||||
import {
|
import {
|
||||||
addDataPublishesCase,
|
addDataPublishesCase,
|
||||||
@ -98,6 +99,7 @@ import {
|
|||||||
voteOnPollCase,
|
voteOnPollCase,
|
||||||
} from "./background-cases";
|
} from "./background-cases";
|
||||||
import { getData, removeKeysAndLogout, storeData } from "./utils/chromeStorage";
|
import { getData, removeKeysAndLogout, storeData } from "./utils/chromeStorage";
|
||||||
|
import TradeBotRespondRequest from "./transactions/TradeBotRespondRequest";
|
||||||
// import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
|
// import {BackgroundFetch} from '@transistorsoft/capacitor-background-fetch';
|
||||||
|
|
||||||
export let groupSecretkeys = {}
|
export let groupSecretkeys = {}
|
||||||
@ -239,7 +241,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
|
||||||
}
|
}
|
||||||
@ -1762,20 +1773,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,
|
||||||
{
|
{
|
||||||
@ -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();
|
const res = await responseFetch.json();
|
||||||
|
|
||||||
if (res === false) {
|
if (res === false) {
|
||||||
|
@ -58,6 +58,26 @@ const sellerForeignFee = {
|
|||||||
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",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const btcFeePerByte = 0.000001;
|
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) => {
|
export const getUserWalletFunc = async (coin) => {
|
||||||
let userWallet = {};
|
let userWallet = {};
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
@ -1885,26 +1927,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;
|
||||||
@ -2492,7 +2542,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");
|
||||||
@ -2549,8 +2599,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!");
|
||||||
@ -2596,7 +2645,6 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
} else if (checkCoin === "DOGE") {
|
} else if (checkCoin === "DOGE") {
|
||||||
const amount = Number(data.amount);
|
const amount = Number(data.amount);
|
||||||
const recipient = data.destinationAddress;
|
const recipient = data.destinationAddress;
|
||||||
const coin = data.coin;
|
|
||||||
const xprv58 = parsedData.dogePrivateKey;
|
const xprv58 = parsedData.dogePrivateKey;
|
||||||
const feePerByte = data.fee ? data.fee : dogeFeePerByte;
|
const feePerByte = data.fee ? data.fee : dogeFeePerByte;
|
||||||
const dogeWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
const dogeWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
||||||
@ -2605,8 +2653,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!";
|
||||||
@ -2663,7 +2710,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!";
|
||||||
@ -2712,7 +2759,6 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
} else if (checkCoin === "RVN") {
|
} else if (checkCoin === "RVN") {
|
||||||
const amount = Number(data.amount);
|
const amount = Number(data.amount);
|
||||||
const recipient = data.destinationAddress;
|
const recipient = data.destinationAddress;
|
||||||
const coin = data.coin;
|
|
||||||
const xprv58 = parsedData.rvnPrivateKey;
|
const xprv58 = parsedData.rvnPrivateKey;
|
||||||
const feePerByte = data.fee ? data.fee : rvnFeePerByte;
|
const feePerByte = data.fee ? data.fee : rvnFeePerByte;
|
||||||
const rvnWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
const rvnWalletBalance = await getWalletBalance({ coin: checkCoin }, true);
|
||||||
@ -2721,8 +2767,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) {
|
||||||
let errorMsg = "Insufficient Funds!";
|
let errorMsg = "Insufficient Funds!";
|
||||||
@ -2771,7 +2816,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))) {
|
||||||
@ -2779,7 +2824,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.0001;
|
const fee = 0.0001;
|
||||||
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!";
|
let errorMsg = "Insufficient Funds!";
|
||||||
@ -2804,7 +2849,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
arrrAmount: amount,
|
arrrAmount: amount,
|
||||||
memo: memo,
|
memo: memo,
|
||||||
};
|
};
|
||||||
const url = await createEndpoint(`/crosschain/btc/send`);
|
const url = await createEndpoint(`/crosschain/arrr/send`);
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -3023,7 +3068,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(
|
||||||
{
|
{
|
||||||
|
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