update qortalRequest buy order

This commit is contained in:
PhilReact 2025-01-16 21:49:17 +02:00
parent e7e7871dca
commit e310cd3617

View File

@ -21,6 +21,7 @@ import {
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption"; import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
import { QORT_DECIMALS } from "../constants/constants"; import { QORT_DECIMALS } from "../constants/constants";
import Base58 from "../deps/Base58"; import Base58 from "../deps/Base58";
import { import {
base64ToUint8Array, base64ToUint8Array,
createSymmetricKeyAndNonce, createSymmetricKeyAndNonce,
@ -43,6 +44,9 @@ import DeleteTradeOffer from "../transactions/TradeBotDeleteRequest";
import signTradeBotTransaction from "../transactions/signTradeBotTransaction"; import signTradeBotTransaction from "../transactions/signTradeBotTransaction";
import nacl from "../deps/nacl-fast"; import nacl from "../deps/nacl-fast";
import utils from "../utils/utils"; import utils from "../utils/utils";
import { RequestQueueWithPromise } from "../utils/queue/queue";
export const requestQueueGetAtAddresses = new RequestQueueWithPromise(10);
const btcFeePerByte = 0.00000100 const btcFeePerByte = 0.00000100
const ltcFeePerByte = 0.00000030 const ltcFeePerByte = 0.00000030
@ -2260,8 +2264,10 @@ export const getTxActivitySummary = async (data) => {
}; };
export const updateForeignFee = async (data) => { export const updateForeignFee = async (data) => {
const localNodeAvailable = await isUsingLocal() const isGateway = await isRunningGateway();
if(!localNodeAvailable) throw new Error('Please use your local node.') if (isGateway) {
throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ['coin', 'type', 'value']; const requiredFields = ['coin', 'type', 'value'];
const missingFields: string[] = []; const missingFields: string[] = [];
@ -2278,7 +2284,7 @@ export const getTxActivitySummary = async (data) => {
} }
const { coin, type, value } = data; const { coin, type, value } = data;
const url = `/crosschain/${coin}/update${type}`; const url = `/crosschain/${coin.toLowerCase()}/update${type}`;
try { try {
const endpoint = await createEndpoint(url); const endpoint = await createEndpoint(url);
@ -2325,7 +2331,7 @@ export const getTxActivitySummary = async (data) => {
} }
const coin = data.coin.toLowerCase(); const coin = data.coin.toLowerCase();
const url = `/crosschain/${coin}/serverconnectionhistory`; const url = `/crosschain/${coin.toLowerCase()}/serverconnectionhistory`;
try { try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
@ -2357,8 +2363,10 @@ export const getTxActivitySummary = async (data) => {
}; };
export const setCurrentForeignServer = async (data) => { export const setCurrentForeignServer = async (data) => {
const localNodeAvailable = await isUsingLocal() const isGateway = await isRunningGateway();
if(!localNodeAvailable) throw new Error('Please use your local node.') if (isGateway) {
throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ['coin']; const requiredFields = ['coin'];
const missingFields: string[] = []; const missingFields: string[] = [];
@ -2382,7 +2390,7 @@ export const getTxActivitySummary = async (data) => {
connectionType: type, connectionType: type,
}; };
const url = `/crosschain/${coin}/setcurrentserver`; const url = `/crosschain/${coin.toLowerCase()}/setcurrentserver`;
try { try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
@ -2416,8 +2424,10 @@ export const getTxActivitySummary = async (data) => {
export const addForeignServer = async (data) => { export const addForeignServer = async (data) => {
const localNodeAvailable = await isUsingLocal() const isGateway = await isRunningGateway();
if(!localNodeAvailable) throw new Error('Please use your local node.') if (isGateway) {
throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ['coin']; const requiredFields = ['coin'];
const missingFields: string[] = []; const missingFields: string[] = [];
@ -2441,7 +2451,7 @@ export const getTxActivitySummary = async (data) => {
connectionType: type, connectionType: type,
}; };
const url = `/crosschain/${coin}/addserver`; const url = `/crosschain/${coin.toLowerCase()}/addserver`;
try { try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
@ -2474,8 +2484,10 @@ export const getTxActivitySummary = async (data) => {
}; };
export const removeForeignServer = async (data) => { export const removeForeignServer = async (data) => {
const localNodeAvailable = await isUsingLocal() const isGateway = await isRunningGateway();
if(!localNodeAvailable) throw new Error('Please use your local node.') if (isGateway) {
throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ['coin']; const requiredFields = ['coin'];
const missingFields: string[] = []; const missingFields: string[] = [];
@ -2499,7 +2511,7 @@ export const getTxActivitySummary = async (data) => {
connectionType: type, connectionType: type,
}; };
const url = `/crosschain/${coin}/removeserver`; const url = `/crosschain/${coin.toLowerCase()}/removeserver`;
try { try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
@ -2995,8 +3007,22 @@ export const createBuyOrder = async (data, isFromExtension) => {
} }
const isGateway = await isRunningGateway() const isGateway = await isRunningGateway()
const foreignBlockchain = data.foreignBlockchain const foreignBlockchain = data.foreignBlockchain
const crosschainAtInfo = data.crosschainAtInfo;
const atAddresses = data.crosschainAtInfo?.map((order)=> order.qortalAtAddress); const atAddresses = data.crosschainAtInfo?.map((order)=> order.qortalAtAddress);
const atPromises = atAddresses
.map((atAddress) =>
requestQueueGetAtAddresses.enqueue(async () => {
const url = await createEndpoint(`/crosschain/trade/${atAddress}`)
const resAddress = await fetch(url);
const resData = await resAddress.json();
if(foreignBlockchain !== resData?.foreignBlockchain){
throw new Error('All requested ATs need to be of the same foreign Blockchain.')
}
return resData
})
);
const crosschainAtInfo = await Promise.all(atPromises);
try { try {
const resPermission = await getUserPermission({ const resPermission = await getUserPermission({
text1: "Do you give this application permission to perform a buy order?", text1: "Do you give this application permission to perform a buy order?",
@ -3008,7 +3034,7 @@ export const createBuyOrder = async (data, isFromExtension) => {
return latest + +cur?.qortAmount; return latest + +cur?.qortAmount;
}, 0)} QORT FOR ${roundUpToDecimals( }, 0)} QORT FOR ${roundUpToDecimals(
crosschainAtInfo?.reduce((latest, cur) => { crosschainAtInfo?.reduce((latest, cur) => {
return latest + +cur?.foreignAmount; return latest + +cur?.expectedForeignAmount;
}, 0) }, 0)
)} )}
${` ${crosschainAtInfo?.[0]?.foreignBlockchain}`}`, ${` ${crosschainAtInfo?.[0]?.foreignBlockchain}`}`,