mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* noves integration * code refactored * PR changes added * Code set up for new proxy 'describeTxs' * minor fix * Rename Novestranslate.ts to NovesTranslate.ts * some quick stuff * partial fixes and commit for changing how useDescribeTxs and txsContent work (new GET endpoint) * Pending PR fixes * tx asset flows pageSize of 50 * PR comments fixes * rename expected api endpoint for the describe_txs endpoint, more accurate and descriptive * one final re-name for api endpoint (make it clear it's an object vs an action) * scrollRef fix * build error fix * design fixes * sub heading fix * Removed pagination in account history * remove duplicate route * updated table theme and icon gap * Removed wrong color in table * removed null validation in page params * updated margin * margin fix * add icons to contracts * Sub-heading interpretation simplified * token alignment fix * tests added for new functions * margin fix * remove divider on mobile asset flows --------- Co-authored-by: NahuelNoves <[email protected]> Co-authored-by: francisco-noves <[email protected]>
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import type { NovesResponseData, NovesSentReceived } from 'types/api/noves';
|
|
|
|
import type { NovesFlowViewItem } from 'ui/tx/assetFlows/utils/generateFlowViewData';
|
|
|
|
export interface FromToData {
|
|
text: string;
|
|
address: string;
|
|
name?: string | null;
|
|
}
|
|
|
|
export const getFromTo = (txData: NovesResponseData, currentAddress: string): FromToData => {
|
|
const raw = txData.rawTransactionData;
|
|
const sent = txData.classificationData.sent;
|
|
let sentFound: Array<NovesSentReceived> = [];
|
|
if (sent && sent[0]) {
|
|
sentFound = sent
|
|
.filter((sent) => sent.from.address.toLocaleLowerCase() === currentAddress)
|
|
.filter((sent) => sent.to.address);
|
|
}
|
|
|
|
const received = txData.classificationData.received;
|
|
let receivedFound: Array<NovesSentReceived> = [];
|
|
if (received && received[0]) {
|
|
receivedFound = received
|
|
.filter((received) => received.to.address?.toLocaleLowerCase() === currentAddress)
|
|
.filter((received) => received.from.address);
|
|
}
|
|
|
|
if (sentFound[0] && receivedFound[0]) {
|
|
if (sentFound.length === receivedFound.length) {
|
|
if (raw.toAddress.toLocaleLowerCase() === currentAddress) {
|
|
return { text: 'Received from', address: raw.fromAddress };
|
|
}
|
|
|
|
if (raw.fromAddress.toLocaleLowerCase() === currentAddress) {
|
|
return { text: 'Sent to', address: raw.toAddress };
|
|
}
|
|
}
|
|
if (sentFound.length > receivedFound.length) {
|
|
// already filtered if null
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
return { text: 'Sent to', address: sentFound[0].to.address! } ;
|
|
} else {
|
|
return { text: 'Received from', address: receivedFound[0].from.address } ;
|
|
}
|
|
}
|
|
|
|
if (sent && sentFound[0]) {
|
|
// already filtered if null
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
return { text: 'Sent to', address: sentFound[0].to.address! } ;
|
|
}
|
|
|
|
if (received && receivedFound[0]) {
|
|
return { text: 'Received from', address: receivedFound[0].from.address };
|
|
}
|
|
|
|
if (raw.toAddress && raw.toAddress.toLocaleLowerCase() === currentAddress) {
|
|
return { text: 'Received from', address: raw.fromAddress };
|
|
}
|
|
|
|
if (raw.fromAddress && raw.fromAddress.toLocaleLowerCase() === currentAddress) {
|
|
return { text: 'Sent to', address: raw.toAddress };
|
|
}
|
|
|
|
if (!raw.toAddress && raw.fromAddress) {
|
|
return { text: 'Received from', address: raw.fromAddress };
|
|
}
|
|
|
|
if (!raw.fromAddress && raw.toAddress) {
|
|
return { text: 'Sent to', address: raw.toAddress };
|
|
}
|
|
|
|
return { text: 'Sent to', address: currentAddress };
|
|
};
|
|
|
|
export const getFromToValue = (txData: NovesResponseData, currentAddress: string) => {
|
|
const fromTo = getFromTo(txData, currentAddress);
|
|
|
|
return fromTo.text.split(' ').shift()?.toLowerCase();
|
|
};
|
|
|
|
export const getActionFromTo = (item: NovesFlowViewItem): FromToData => {
|
|
return {
|
|
text: item.action.flowDirection === 'toRight' ? 'Sent to' : 'Received from',
|
|
address: item.rightActor.address,
|
|
name: item.rightActor.name,
|
|
};
|
|
};
|