Skip to content

Commit

Permalink
fix: crash when transaction.tokenAddress is null
Browse files Browse the repository at this point in the history
  • Loading branch information
gleiser-oliveira committed Jul 20, 2023
1 parent cda2c1c commit 563511a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/clients/api/queries/getTransactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface TransactionResponse {
to: string;
transactionHash: string;
logIndex: string;
tokenAddress: string;
tokenAddress: string | null;
}
7 changes: 5 additions & 2 deletions src/utilities/getTokenByAddress.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Token } from 'types';
import { areAddressesEqual } from 'utilities';

import { TOKENS } from 'constants/tokens';

const getTokenByAddress = (address: string) => {
const getTokenByAddress = (address?: string | null) => {
let token: Token | undefined;

Object.keys(TOKENS)
.filter(key => Object.prototype.hasOwnProperty.call(TOKENS, key))
.forEach(tokenId => {
const currentToken = TOKENS[tokenId as keyof typeof TOKENS];
if (currentToken?.address.toLowerCase() === address.toLowerCase()) {
if (!address) {
token = TOKENS.bnb;
} else if (areAddressesEqual(currentToken?.address, address)) {
token = currentToken;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/getVTokenByAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { VToken } from 'types';

import { VBEP_TOKENS } from 'constants/tokens';

const getVTokenByAddress = (address: string) =>
address.toLowerCase() in VBEP_TOKENS
const getVTokenByAddress = (address?: string | null) =>
!!address && address.toLowerCase() in VBEP_TOKENS
? (VBEP_TOKENS[address.toLowerCase() as keyof typeof VBEP_TOKENS] as VToken)
: undefined;

Expand Down

0 comments on commit 563511a

Please sign in to comment.