Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-37] Add parsing for fast transfers (Wormhole liquidity layer) #3283

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions wormhole-connect/src/hooks/useTransactionHistoryMayan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ interface MayanTransaction {
fromTokenChain: ChainId;
fromTokenAddress: string;
fromTokenPrice: number;
fromTokenSymbol: string;
toTokenPrice: number;
toTokenAddress: string;
toTokenChain: ChainId;
toTokenSymbol: string;
status: string;
clientStatus: string;
initiatedAt: string;
Expand Down Expand Up @@ -91,6 +93,28 @@ const useTransactionHistoryMayan = (
return undefined;
}

// Last resort to find source token by symbol
if (!fromToken) {
const fromTokenBySymbol = config.tokens.findBySymbol(
fromChain,
tx.fromTokenSymbol,
);
if (fromTokenBySymbol) {
fromToken = fromTokenBySymbol;
}
}

// Last resort to find destination token by symbol
if (!toToken) {
const toTokenBySymbol = config.tokens.findBySymbol(
toChain,
tx.toTokenSymbol,
);
if (toTokenBySymbol) {
toToken = toTokenBySymbol;
}
}

// Skip this transaction if we can't find source or destination token configs
if (!fromToken || !toToken) {
console.error('Cant find tokenz');
Expand Down
21 changes: 19 additions & 2 deletions wormhole-connect/src/hooks/useTransactionHistoryWHScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ const useTransactionHistoryWHScan = (

const tokenChain = chainIdToChain(tokenChainId);

// Skip if we don't have the token chain
if (!tokenChain) {
return;
}

let token = config.tokens.get(
tokenChain,
standarizedProperties.tokenAddress,
Expand All @@ -161,7 +166,7 @@ const useTransactionHistoryWHScan = (
return;
}

const toChain = chainIdToChain(toChainId) as Chain;
const toChain = chainIdToChain(toChainId);

// data.tokenAmount holds the normalized token amount value.
// Otherwise we need to format standarizedProperties.amount using decimals
Expand Down Expand Up @@ -313,15 +318,27 @@ const useTransactionHistoryWHScan = (
[parseSingleTx],
);

// Parser for WLL or FAST_TRANSFERS transactions (appId === WORMHOLE_LIQUIDITY_LAYER, FAST_TRANSFERS)
// IMPORTANT: This is where we can add any customizations specific to WLL data
// that we have retrieved from WHScan API
const parseLLTx = useCallback(
(tx: WormholeScanTransaction) => {
return parseSingleTx(tx);
},
[parseSingleTx],
);

const PARSERS = useMemo(
() => ({
PORTAL_TOKEN_BRIDGE: parseTokenBridgeTx,
NATIVE_TOKEN_TRANSFER: parseNTTTx,
CCTP_WORMHOLE_INTEGRATION: parseCCTPTx,
ETH_BRIDGE: parsePorticoTx,
USDT_BRIDGE: parsePorticoTx,
FAST_TRANSFERS: parseLLTx,
WORMHOLE_LIQUIDITY_LAYER: parseLLTx,
}),
[parseCCTPTx, parseNTTTx, parsePorticoTx, parseTokenBridgeTx],
[parseCCTPTx, parseNTTTx, parsePorticoTx, parseTokenBridgeTx, parseLLTx],
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading