Skip to content

Commit f4adde2

Browse files
authored
Check multiple props for the relayer fee (#3363)
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent 621adee commit f4adde2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

wormhole-connect/src/hooks/useTransactionHistoryWHScan.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ interface WormholeScanTransaction {
2121
content: {
2222
payload: {
2323
amount: string;
24+
fee?: string;
2425
callerAppId: string;
2526
fromAddress: string;
2627
parsedPayload: {
27-
feeAmount: string;
28+
feeAmount?: string;
29+
relayerFee?: string;
2830
recipientWallet: string;
2931
toNativeAmount: string;
3032
};
@@ -127,7 +129,7 @@ const useTransactionHistoryWHScan = (
127129
const parseSingleTx = useCallback(
128130
async (tx: WormholeScanTransaction) => {
129131
const { content, data, sourceChain, targetChain } = tx;
130-
const { standarizedProperties } = content || {};
132+
const { standarizedProperties, payload } = content || {};
131133

132134
const fromChainId =
133135
standarizedProperties.fromChain || sourceChain?.chainId;
@@ -193,10 +195,21 @@ const useTransactionHistoryWHScan = (
193195
);
194196
}
195197

196-
if (standarizedProperties.amount && standarizedProperties.fee) {
198+
if (standarizedProperties.amount) {
199+
// Parse fee to calculate receive amount
200+
// WHScan API should parse the payload and set it under standarizedProperties, but that's not the case.
201+
// There are multiple props that can persist the fee value depending on the protocol.
202+
// There is no clear documentation around the set of props specific to protocols, therefore we need to check them all.
203+
const fee =
204+
standarizedProperties.fee ||
205+
payload.fee ||
206+
payload.parsedPayload?.feeAmount ||
207+
payload.parsedPayload?.relayerFee ||
208+
'0';
209+
197210
const receiveAmountValue =
198-
BigInt(standarizedProperties.amount) -
199-
BigInt(standarizedProperties.fee);
211+
BigInt(standarizedProperties.amount) - BigInt(fee);
212+
200213
// It's unlikely, but in case the above subtraction returns a non-positive number,
201214
// we should not show that at all.
202215
if (receiveAmountValue > 0) {

0 commit comments

Comments
 (0)