Skip to content

Commit

Permalink
Fix address util nullish fallback handling (#3181)
Browse files Browse the repository at this point in the history
### Description

Small fix for address utils

### Related issues

hyperlane-xyz/issues#899

### Backward compatibility

Yes

### Testing

In warp UI
  • Loading branch information
jmrossy authored Jan 24, 2024
1 parent 6845f9f commit df24eec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-lobsters-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/utils': patch
---

Fix for address utils falsy fallbacks
3 changes: 2 additions & 1 deletion typescript/utils/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fromBech32, normalizeBech32, toBech32 } from '@cosmjs/encoding';
import { PublicKey } from '@solana/web3.js';
import { utils as ethersUtils } from 'ethers';

import { isNullish } from './typeof';
import { Address, HexString, ProtocolType } from './types';

const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
Expand Down Expand Up @@ -67,7 +68,7 @@ function routeAddressUtil<T>(
) {
protocol ||= getAddressProtocolType(param);
if (protocol && fns[protocol]) return fns[protocol]!(param);
else if (fallback) return fallback;
else if (!isNullish(fallback)) return fallback;
else throw new Error(`Unsupported protocol ${protocol}`);
}

Expand Down
7 changes: 4 additions & 3 deletions typescript/utils/src/typeof.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export function isNullish<T>(val: T) {
if (val === null || val === undefined) return true;
else return false;
export function isNullish<T>(
val: T,
): val is T extends null | undefined ? T : never {
return val === null || val === undefined;
}

export function isNumeric(value: string | number) {
Expand Down

0 comments on commit df24eec

Please sign in to comment.