mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
update qortalRequest buy order
This commit is contained in:
parent
e7e7871dca
commit
e310cd3617
@ -21,6 +21,7 @@ import {
|
||||
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||
import { QORT_DECIMALS } from "../constants/constants";
|
||||
import Base58 from "../deps/Base58";
|
||||
|
||||
import {
|
||||
base64ToUint8Array,
|
||||
createSymmetricKeyAndNonce,
|
||||
@ -43,6 +44,9 @@ import DeleteTradeOffer from "../transactions/TradeBotDeleteRequest";
|
||||
import signTradeBotTransaction from "../transactions/signTradeBotTransaction";
|
||||
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
|
||||
@ -2260,8 +2264,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[] = [];
|
||||
|
||||
@ -2278,7 +2284,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);
|
||||
@ -2325,7 +2331,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
|
||||
@ -2357,8 +2363,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[] = [];
|
||||
|
||||
@ -2382,7 +2390,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
|
||||
@ -2416,8 +2424,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[] = [];
|
||||
|
||||
@ -2441,7 +2451,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
|
||||
@ -2474,8 +2484,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[] = [];
|
||||
|
||||
@ -2499,7 +2511,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
|
||||
@ -2995,8 +3007,22 @@ 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?",
|
||||
@ -3008,7 +3034,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}`}`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user