mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +00:00
started buy order qortalrequset
This commit is contained in:
parent
37de676069
commit
40e8e316a8
@ -20,6 +20,7 @@ const defaultDomains = [
|
|||||||
'https://ext-node.qortal.link',
|
'https://ext-node.qortal.link',
|
||||||
'wss://ext-node.qortal.link',
|
'wss://ext-node.qortal.link',
|
||||||
'https://appnode.qortal.org',
|
'https://appnode.qortal.org',
|
||||||
|
'wss://appnode.qortal.org',
|
||||||
"https://api.qortal.org",
|
"https://api.qortal.org",
|
||||||
"https://api2.qortal.org",
|
"https://api2.qortal.org",
|
||||||
"https://appnode.qortal.org",
|
"https://appnode.qortal.org",
|
||||||
@ -27,7 +28,8 @@ const defaultDomains = [
|
|||||||
"https://apinode1.qortalnodes.live",
|
"https://apinode1.qortalnodes.live",
|
||||||
"https://apinode2.qortalnodes.live",
|
"https://apinode2.qortalnodes.live",
|
||||||
"https://apinode3.qortalnodes.live",
|
"https://apinode3.qortalnodes.live",
|
||||||
"https://apinode4.qortalnodes.live"
|
"https://apinode4.qortalnodes.live",
|
||||||
|
"https://www.qort.trade"
|
||||||
|
|
||||||
];
|
];
|
||||||
// let allowedDomains: string[] = [...defaultDomains]
|
// let allowedDomains: string[] = [...defaultDomains]
|
||||||
|
35
package-lock.json
generated
35
package-lock.json
generated
@ -41,6 +41,7 @@
|
|||||||
"@transistorsoft/capacitor-background-fetch": "^6.0.1",
|
"@transistorsoft/capacitor-background-fetch": "^6.0.1",
|
||||||
"@types/chrome": "^0.0.263",
|
"@types/chrome": "^0.0.263",
|
||||||
"asmcrypto.js": "2.3.2",
|
"asmcrypto.js": "2.3.2",
|
||||||
|
"axios": "^1.7.7",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"buffer": "6.0.3",
|
"buffer": "6.0.3",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^3.6.0",
|
||||||
@ -5099,6 +5100,16 @@
|
|||||||
"node": ">=0.8"
|
"node": ">=0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "1.7.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
|
||||||
|
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.6",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/babel-plugin-macros": {
|
"node_modules/babel-plugin-macros": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz",
|
||||||
@ -8146,6 +8157,25 @@
|
|||||||
"node": ">= 10.0.0"
|
"node": ">= 10.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.15.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
|
||||||
|
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/foreground-child": {
|
"node_modules/foreground-child": {
|
||||||
"version": "3.3.0",
|
"version": "3.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz",
|
||||||
@ -13822,6 +13852,11 @@
|
|||||||
"prosemirror-transform": "^1.1.0"
|
"prosemirror-transform": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/proxy-from-env": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||||
|
},
|
||||||
"node_modules/psl": {
|
"node_modules/psl": {
|
||||||
"version": "1.9.0",
|
"version": "1.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
"@transistorsoft/capacitor-background-fetch": "^6.0.1",
|
"@transistorsoft/capacitor-background-fetch": "^6.0.1",
|
||||||
"@types/chrome": "^0.0.263",
|
"@types/chrome": "^0.0.263",
|
||||||
"asmcrypto.js": "2.3.2",
|
"asmcrypto.js": "2.3.2",
|
||||||
|
"axios": "^1.7.7",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"buffer": "6.0.3",
|
"buffer": "6.0.3",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^3.6.0",
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
} from "./backgroundFunctions/encryption";
|
} from "./backgroundFunctions/encryption";
|
||||||
import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from "./constants/codes";
|
import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from "./constants/codes";
|
||||||
import Base58 from "./deps/Base58";
|
import Base58 from "./deps/Base58";
|
||||||
|
import axios from 'axios'
|
||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
decryptSingle,
|
decryptSingle,
|
||||||
@ -1360,12 +1361,13 @@ export async function handleActiveGroupDataFromSocket({ groups, directs }) {
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message }) {
|
async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message, atAddresses }) {
|
||||||
let _reference = new Uint8Array(64);
|
let _reference = new Uint8Array(64);
|
||||||
self.crypto.getRandomValues(_reference);
|
self.crypto.getRandomValues(_reference);
|
||||||
|
|
||||||
let sendTimestamp = Date.now();
|
let sendTimestamp = Date.now();
|
||||||
|
const wallet = await getSaveWallet();
|
||||||
|
const address = wallet.address0;
|
||||||
let reference = Base58.encode(_reference);
|
let reference = Base58.encode(_reference);
|
||||||
const resKeyPair = await getKeyPair();
|
const resKeyPair = await getKeyPair();
|
||||||
const parsedData = resKeyPair;
|
const parsedData = resKeyPair;
|
||||||
@ -1400,8 +1402,31 @@ async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message })
|
|||||||
isEncrypted: 1,
|
isEncrypted: 1,
|
||||||
isText: 1,
|
isText: 1,
|
||||||
});
|
});
|
||||||
if (!hasEnoughBalance) {
|
//TODO
|
||||||
throw new Error('You must have at least 4 QORT to trade using the gateway.')
|
// if (!hasEnoughBalance) {
|
||||||
|
if(!hasEnoughBalance){
|
||||||
|
const _encryptedMessage = tx._encryptedMessage;
|
||||||
|
const encryptedMessageToBase58 = Base58.encode(_encryptedMessage);
|
||||||
|
const signature = "id-" + Date.now() + "-" + Math.floor(Math.random() * 1000)
|
||||||
|
const res = await axios.post(
|
||||||
|
`https://www.qort.trade/api/transaction/updatetxgateway`,
|
||||||
|
{
|
||||||
|
qortalAtAddresses: atAddresses, qortAddress: address, node: buyTradeNodeBaseUrl, status: "message-sent", encryptedMessageToBase58, signature ,
|
||||||
|
reference, senderPublicKey: parsedData.publicKey,
|
||||||
|
sender: address,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
encryptedMessageToBase58,
|
||||||
|
status: "message-sent",
|
||||||
|
signature
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const path = `${import.meta.env.BASE_URL}memory-pow.wasm.full`;
|
const path = `${import.meta.env.BASE_URL}memory-pow.wasm.full`;
|
||||||
|
|
||||||
@ -1712,16 +1737,49 @@ export async function createBuyOrderTx({ crosschainAtInfo, useLocal }) {
|
|||||||
qortAddress: proxyAccountAddress,
|
qortAddress: proxyAccountAddress,
|
||||||
recipientPublicKey: proxyAccountPublicKey,
|
recipientPublicKey: proxyAccountPublicKey,
|
||||||
message,
|
message,
|
||||||
|
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (res?.signature) {
|
if (res?.signature) {
|
||||||
let responseMessage;
|
let responseMessage;
|
||||||
|
|
||||||
const message = await listenForChatMessageForBuyOrder({
|
if(res?.encryptedMessageToBase58){
|
||||||
nodeBaseUrl: buyTradeNodeBaseUrl,
|
const message = await listenForChatMessageForBuyOrder({
|
||||||
senderAddress: proxyAccountAddress,
|
nodeBaseUrl: buyTradeNodeBaseUrl,
|
||||||
senderPublicKey: proxyAccountPublicKey,
|
senderAddress: proxyAccountAddress,
|
||||||
signature: res?.signature,
|
senderPublicKey: proxyAccountPublicKey,
|
||||||
});
|
signature: res?.signature,
|
||||||
|
});
|
||||||
|
responseMessage = {
|
||||||
|
callResponse: message.callResponse,
|
||||||
|
extra: {
|
||||||
|
message: message?.extra?.message,
|
||||||
|
senderAddress: address,
|
||||||
|
node: buyTradeNodeBaseUrl,
|
||||||
|
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const message = await listenForChatMessageForBuyOrder({
|
||||||
|
nodeBaseUrl: buyTradeNodeBaseUrl,
|
||||||
|
senderAddress: proxyAccountAddress,
|
||||||
|
senderPublicKey: proxyAccountPublicKey,
|
||||||
|
signature: res?.signature,
|
||||||
|
});
|
||||||
|
|
||||||
|
responseMessage = {
|
||||||
|
callResponse: message.callResponse,
|
||||||
|
extra: {
|
||||||
|
message: message?.extra?.message,
|
||||||
|
senderAddress: address,
|
||||||
|
node: buyTradeNodeBaseUrl,
|
||||||
|
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// const status = response.callResponse === true ? 'trade-ongoing' : 'trade-failed'
|
// const status = response.callResponse === true ? 'trade-ongoing' : 'trade-failed'
|
||||||
// if (res?.encryptedMessageToBase58) {
|
// if (res?.encryptedMessageToBase58) {
|
||||||
// return {
|
// return {
|
||||||
@ -1742,16 +1800,7 @@ export async function createBuyOrderTx({ crosschainAtInfo, useLocal }) {
|
|||||||
// node: buyTradeNodeBaseUrl,
|
// node: buyTradeNodeBaseUrl,
|
||||||
// qortAddress: address,
|
// qortAddress: address,
|
||||||
// };
|
// };
|
||||||
responseMessage = {
|
|
||||||
callResponse: message.callResponse,
|
|
||||||
extra: {
|
|
||||||
message: message?.extra?.message,
|
|
||||||
senderAddress: address,
|
|
||||||
node: buyTradeNodeBaseUrl,
|
|
||||||
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
|
||||||
},
|
|
||||||
encryptedMessageToBase58
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseMessage
|
return responseMessage
|
||||||
} else {
|
} else {
|
||||||
|
@ -201,8 +201,8 @@ export const AppsCategoryDesktop = ({
|
|||||||
</AppsWidthLimiter>
|
</AppsWidthLimiter>
|
||||||
<AppsWidthLimiter>
|
<AppsWidthLimiter>
|
||||||
<StyledVirtuosoContainer
|
<StyledVirtuosoContainer
|
||||||
sx={{
|
sx={{
|
||||||
height: rootHeight,
|
height: `calc(100vh - 36px - 90px)`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
|
@ -221,6 +221,7 @@ export const AppsDesktop = ({ mode, setMode, show , myName, goToHome, setDesktop
|
|||||||
}, [tabs]);
|
}, [tabs]);
|
||||||
const setSelectedTabFunc = (e) => {
|
const setSelectedTabFunc = (e) => {
|
||||||
const data = e.detail?.data;
|
const data = e.detail?.data;
|
||||||
|
if(e.detail?.isDevMode) return
|
||||||
|
|
||||||
setSelectedTab(data);
|
setSelectedTab(data);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -113,7 +113,7 @@ export const AppsDevMode = ({ mode, setMode, show , myName, goToHome, setDesktop
|
|||||||
}, [tabs]);
|
}, [tabs]);
|
||||||
const setSelectedTabFunc = (e) => {
|
const setSelectedTabFunc = (e) => {
|
||||||
const data = e.detail?.data;
|
const data = e.detail?.data;
|
||||||
|
if(!e.detail?.isDevMode) return
|
||||||
setSelectedTab(data);
|
setSelectedTab(data);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
executeEvent("appsDevModeSetTabsToNav", {
|
executeEvent("appsDevModeSetTabsToNav", {
|
||||||
|
@ -16,7 +16,8 @@ export const AppsDevModeTabComponent = ({isSelected, app}) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
executeEvent('setSelectedTab', {
|
executeEvent('setSelectedTab', {
|
||||||
data: app
|
data: app,
|
||||||
|
isDevMode: true
|
||||||
})
|
})
|
||||||
}}>
|
}}>
|
||||||
<TabParent sx={{
|
<TabParent sx={{
|
||||||
|
@ -96,7 +96,7 @@ export const AppsLibraryDesktop = ({
|
|||||||
myName,
|
myName,
|
||||||
hasPublishApp,
|
hasPublishApp,
|
||||||
isShow,
|
isShow,
|
||||||
categories = { categories },
|
categories
|
||||||
}) => {
|
}) => {
|
||||||
const [searchValue, setSearchValue] = useState("");
|
const [searchValue, setSearchValue] = useState("");
|
||||||
const virtuosoRef = useRef();
|
const virtuosoRef = useRef();
|
||||||
|
@ -183,7 +183,7 @@ const UIQortalRequests = [
|
|||||||
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
|
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
|
||||||
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
||||||
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
||||||
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER'
|
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'CREATE_TRADE_SELL_ORDER'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { addForeignServer, addListItems, createBuyOrder, createPoll, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
|
import { addForeignServer, addListItems, createBuyOrder, createPoll, createSellOrder, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
|
||||||
import { getData, storeData } from "./utils/chromeStorage";
|
import { getData, storeData } from "./utils/chromeStorage";
|
||||||
|
|
||||||
|
|
||||||
@ -604,6 +604,25 @@ function setLocalStorage(key, data) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "CREATE_TRADE_SELL_ORDER": {
|
||||||
|
try {
|
||||||
|
const res = await createSellOrder(request.payload, isFromExtension);
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
payload: res,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
} catch (error) {
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
error: error.message,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1365,22 +1365,31 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE
|
|||||||
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const value = (await getPermission(`qAPPAutoWalletBalance-${data.coin}`)) || false;
|
||||||
|
console.log('value', value)
|
||||||
|
let skip = false;
|
||||||
|
if (value) {
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
let resPermission
|
let resPermission
|
||||||
|
|
||||||
if(!bypassPermission){
|
if(!bypassPermission && !skip){
|
||||||
resPermission = await getUserPermission({
|
resPermission = await getUserPermission({
|
||||||
text1: "Do you give this application permission to fetch your",
|
text1: "Do you give this application permission to fetch your",
|
||||||
highlightedText: `${data.coin} balance`,
|
highlightedText: `${data.coin} balance`,
|
||||||
|
checkbox1: {
|
||||||
|
value: true,
|
||||||
|
label: "Always allow balance to be retrieved automatically",
|
||||||
|
},
|
||||||
}, isFromExtension);
|
}, isFromExtension);
|
||||||
} else {
|
}
|
||||||
resPermission = {
|
console.log('resPermission', resPermission)
|
||||||
accepted: false
|
const { accepted = false, checkbox1 = false } = resPermission || {};
|
||||||
}
|
if(resPermission){
|
||||||
|
setPermission(`qAPPAutoWalletBalance-${data.coin}`, checkbox1);
|
||||||
}
|
}
|
||||||
|
if (accepted || bypassPermission || skip) {
|
||||||
const { accepted } = resPermission;
|
|
||||||
|
|
||||||
if (accepted || bypassPermission) {
|
|
||||||
let coin = data.coin;
|
let coin = data.coin;
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
@ -2424,6 +2433,65 @@ export const createBuyOrder = async (data, isFromExtension) => {
|
|||||||
throw new Error('Process Type must be either local or gateway')
|
throw new Error('Process Type must be either local or gateway')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resPermission = await getUserPermission({
|
||||||
|
text1: "Do you give this application permission to perform a buy order?",
|
||||||
|
text2: `${atAddresses?.length}${" "}
|
||||||
|
${`buy order${
|
||||||
|
atAddresses?.length === 1 ? "" : "s"
|
||||||
|
}`}`,
|
||||||
|
text3: `${crosschainAtInfo?.reduce((latest, cur) => {
|
||||||
|
return latest + +cur?.qortAmount;
|
||||||
|
}, 0)} QORT FOR ${roundUpToDecimals(
|
||||||
|
crosschainAtInfo?.reduce((latest, cur) => {
|
||||||
|
return latest + +cur?.foreignAmount;
|
||||||
|
}, 0)
|
||||||
|
)}
|
||||||
|
${` ${crosschainAtInfo?.[0]?.foreignBlockchain}`}`,
|
||||||
|
highlightedText: `Using ${processType}`,
|
||||||
|
fee: ''
|
||||||
|
}, isFromExtension);
|
||||||
|
const { accepted } = resPermission;
|
||||||
|
if (accepted) {
|
||||||
|
const resBuyOrder = await createBuyOrderTx(
|
||||||
|
{
|
||||||
|
crosschainAtInfo,
|
||||||
|
useLocal: processType === 'local' ? true : false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return resBuyOrder;
|
||||||
|
} else {
|
||||||
|
throw new Error("User declined request");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error?.message || "Failed to submit trade order.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createSellOrder = async (data, isFromExtension) => {
|
||||||
|
|
||||||
|
const requiredFields = [
|
||||||
|
"crosschainAtInfo",
|
||||||
|
"processType"
|
||||||
|
];
|
||||||
|
const missingFields: string[] = [];
|
||||||
|
requiredFields.forEach((field) => {
|
||||||
|
if (!data[field]) {
|
||||||
|
missingFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
const missingFieldsString = missingFields.join(", ");
|
||||||
|
const errorMsg = `Missing fields: ${missingFieldsString}`;
|
||||||
|
throw new Error(errorMsg);
|
||||||
|
}
|
||||||
|
const crosschainAtInfo = data.crosschainAtInfo;
|
||||||
|
const atAddresses = data.crosschainAtInfo?.map((order)=> order.qortalAtAddress);
|
||||||
|
const processType = data.processType;
|
||||||
|
if(processType !== 'local' && processType !== 'gateway'){
|
||||||
|
throw new Error('Process Type must be either local or gateway')
|
||||||
|
}
|
||||||
|
|
||||||
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?",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user