mirror of
https://github.com/Qortal/q-trade.git
synced 2025-06-15 19:01:21 +00:00
added initial fetch of tradeoffers without socket
This commit is contained in:
parent
889a1e06da
commit
ddde841c7a
@ -440,7 +440,7 @@ export const TradeOffers: React.FC<any> = ({
|
||||
};
|
||||
}, []);
|
||||
|
||||
const processOffersWithPresence = () => {
|
||||
const processOffersWithPresence = useCallback(() => {
|
||||
if (offeringTrades.current === null) return;
|
||||
async function asyncForEach(array: any, callback: any) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
@ -496,7 +496,7 @@ export const TradeOffers: React.FC<any> = ({
|
||||
};
|
||||
|
||||
startOfferPresenceMapping();
|
||||
};
|
||||
},[setStuckTrades]);
|
||||
|
||||
const restartTradeOffersWebSocket = () => {
|
||||
setTimeout(() => initTradeOffersWebSocket(true), 50);
|
||||
@ -543,8 +543,44 @@ export const TradeOffers: React.FC<any> = ({
|
||||
};
|
||||
};
|
||||
|
||||
const initTradeOffersWebSocket = (restarted = false) => {
|
||||
const fetchOffers = useCallback(async (selectedCoin) => {
|
||||
try {
|
||||
|
||||
const response = await fetch(
|
||||
`/crosschain/tradeoffers?foreignBlockchain=${selectedCoin}&includeHistoric=true`
|
||||
);
|
||||
const data = await response.json();
|
||||
const transformed = data.map(item => ({
|
||||
qortalAtAddress: item.qortalAtAddress,
|
||||
qortalCreator: item.qortalCreator,
|
||||
qortalCreatorTradeAddress: item.qortalCreatorTradeAddress,
|
||||
qortAmount: item.qortAmount,
|
||||
btcAmount: item.expectedBitcoin ?? item.btcAmount, // fallback if already correct
|
||||
foreignAmount: item.expectedForeignAmount ?? item.foreignAmount,
|
||||
tradeTimeout: item.tradeTimeout,
|
||||
mode: item.mode,
|
||||
timestamp: item.timestamp ?? item.creationTimestamp,
|
||||
foreignBlockchain: item.foreignBlockchain,
|
||||
acctName: item.acctName
|
||||
}));
|
||||
|
||||
console.log('data', data)
|
||||
offeringTrades.current = [
|
||||
...transformed?.filter(
|
||||
(coin) => coin?.foreignBlockchain === selectedCoin && coin?.mode === 'OFFERING'
|
||||
),
|
||||
];
|
||||
processOffersWithPresence();
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
},[]);
|
||||
|
||||
const initTradeOffersWebSocket = async (restarted = false) => {
|
||||
if (socketRef.current) return;
|
||||
if(restarted === false){
|
||||
await fetchOffers(selectedCoin)
|
||||
}
|
||||
let socketTimeout: any;
|
||||
|
||||
let socketLink;
|
||||
@ -588,6 +624,9 @@ export const TradeOffers: React.FC<any> = ({
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (isUsingGateway === null) return;
|
||||
blockedTradesList.current = JSON.parse(
|
||||
|
@ -356,8 +356,15 @@ export const CreateSell = ({ qortAddress, show }) => {
|
||||
const StuckOrders = ({setOpenStuckOrders})=> {
|
||||
const [stuckTrades] = useAtom(stuckTradesAtom)
|
||||
const address = useGlobal().auth.address
|
||||
const filteredByAddress = stuckTrades?.filter((item)=> item?.qortalCreator === address)
|
||||
|
||||
const filteredByAddress = stuckTrades
|
||||
?.filter((item) => item?.qortalCreator === address)
|
||||
.sort((a, b) => {
|
||||
const timestampA = a?.timestamp ?? a?.creationTimestamp ?? 0;
|
||||
const timestampB = b?.timestamp ?? b?.creationTimestamp ?? 0;
|
||||
return timestampB - timestampA; // Newest first
|
||||
});
|
||||
|
||||
console.log('filteredByAddress', filteredByAddress)
|
||||
return (
|
||||
<BootstrapDialog
|
||||
aria-labelledby="customized-dialog-title"
|
||||
|
@ -24,7 +24,8 @@ interface AtData {
|
||||
foreignBlockchain: string;
|
||||
foreignAmount: number;
|
||||
qortalAtAddress: string;
|
||||
timestamp: number
|
||||
timestamp?: number
|
||||
creationTimestamp?: number
|
||||
}
|
||||
|
||||
const VirtuosoTableComponents: TableComponents<AtData> = {
|
||||
@ -87,7 +88,7 @@ function rowContent(_index: number, row: AtData) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableCell>{formatTimestampForum(row?.timestamp)}</TableCell>
|
||||
<TableCell>{formatTimestampForum(row?.timestamp || row?.creationTimestamp)}</TableCell>
|
||||
<TableCell>{row?.qortAmount}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
|
Loading…
x
Reference in New Issue
Block a user