diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts index c264126..099ae51 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -47,6 +47,9 @@ import { decryptResource, getGroupAdmins, getPublishesFromAdmins, validateSecret import { getPublishesFromAdminsAdminSpace } from "../components/Chat/AdminSpaceInner"; import nacl from "../deps/nacl-fast"; import utils from "../utils/utils"; +import { RequestQueueWithPromise } from "../utils/queue/queue"; + +export const requestQueueGetAtAddresses = new RequestQueueWithPromise(10); const btcFeePerByte = 0.00000100 const ltcFeePerByte = 0.00000030 @@ -2309,8 +2312,10 @@ export const getTxActivitySummary = async (data) => { }; export const updateForeignFee = async (data) => { - const localNodeAvailable = await isUsingLocal() - if(!localNodeAvailable) throw new Error('Please use your local node.') + const isGateway = await isRunningGateway(); + if (isGateway) { + throw new Error("This action cannot be done through a gateway"); + } const requiredFields = ['coin', 'type', 'value']; const missingFields: string[] = []; @@ -2327,7 +2332,7 @@ export const getTxActivitySummary = async (data) => { } const { coin, type, value } = data; - const url = `/crosschain/${coin}/update${type}`; + const url = `/crosschain/${coin.toLowerCase()}/update${type}`; try { const endpoint = await createEndpoint(url); @@ -2374,7 +2379,7 @@ export const getTxActivitySummary = async (data) => { } const coin = data.coin.toLowerCase(); - const url = `/crosschain/${coin}/serverconnectionhistory`; + const url = `/crosschain/${coin.toLowerCase()}/serverconnectionhistory`; try { const endpoint = await createEndpoint(url); // Assuming createEndpoint is available @@ -2406,8 +2411,10 @@ export const getTxActivitySummary = async (data) => { }; export const setCurrentForeignServer = async (data) => { - const localNodeAvailable = await isUsingLocal() - if(!localNodeAvailable) throw new Error('Please use your local node.') + const isGateway = await isRunningGateway(); + if (isGateway) { + throw new Error("This action cannot be done through a gateway"); + } const requiredFields = ['coin']; const missingFields: string[] = []; @@ -2431,7 +2438,7 @@ export const getTxActivitySummary = async (data) => { connectionType: type, }; - const url = `/crosschain/${coin}/setcurrentserver`; + const url = `/crosschain/${coin.toLowerCase()}/setcurrentserver`; try { const endpoint = await createEndpoint(url); // Assuming createEndpoint is available @@ -2465,8 +2472,10 @@ export const getTxActivitySummary = async (data) => { export const addForeignServer = async (data) => { - const localNodeAvailable = await isUsingLocal() - if(!localNodeAvailable) throw new Error('Please use your local node.') + const isGateway = await isRunningGateway(); + if (isGateway) { + throw new Error("This action cannot be done through a gateway"); + } const requiredFields = ['coin']; const missingFields: string[] = []; @@ -2490,7 +2499,7 @@ export const getTxActivitySummary = async (data) => { connectionType: type, }; - const url = `/crosschain/${coin}/addserver`; + const url = `/crosschain/${coin.toLowerCase()}/addserver`; try { const endpoint = await createEndpoint(url); // Assuming createEndpoint is available @@ -2523,8 +2532,10 @@ export const getTxActivitySummary = async (data) => { }; export const removeForeignServer = async (data) => { - const localNodeAvailable = await isUsingLocal() - if(!localNodeAvailable) throw new Error('Please use your local node.') + const isGateway = await isRunningGateway(); + if (isGateway) { + throw new Error("This action cannot be done through a gateway"); + } const requiredFields = ['coin']; const missingFields: string[] = []; @@ -2548,7 +2559,7 @@ export const getTxActivitySummary = async (data) => { connectionType: type, }; - const url = `/crosschain/${coin}/removeserver`; + const url = `/crosschain/${coin.toLowerCase()}/removeserver`; try { const endpoint = await createEndpoint(url); // Assuming createEndpoint is available @@ -3054,9 +3065,24 @@ export const createBuyOrder = async (data, isFromExtension) => { } const isGateway = await isRunningGateway() const foreignBlockchain = data.foreignBlockchain - const crosschainAtInfo = data.crosschainAtInfo; + 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 { const resPermission = await getUserPermission({ text1: "Do you give this application permission to perform a buy order?", @@ -3068,7 +3094,7 @@ export const createBuyOrder = async (data, isFromExtension) => { return latest + +cur?.qortAmount; }, 0)} QORT FOR ${roundUpToDecimals( crosschainAtInfo?.reduce((latest, cur) => { - return latest + +cur?.foreignAmount; + return latest + +cur?.expectedForeignAmount; }, 0) )} ${` ${crosschainAtInfo?.[0]?.foreignBlockchain}`}`,