diff --git a/bridge_ui/src/contexts/SolanaWalletContext.tsx b/bridge_ui/src/contexts/SolanaWalletContext.tsx index 1cbbc6d5e..55f8acc5e 100644 --- a/bridge_ui/src/contexts/SolanaWalletContext.tsx +++ b/bridge_ui/src/contexts/SolanaWalletContext.tsx @@ -24,7 +24,7 @@ export const SolanaWalletProvider: FC = (props) => { }, []); return ( - + {props.children} ); diff --git a/bridge_ui/src/hooks/useSyncTargetAddress.ts b/bridge_ui/src/hooks/useSyncTargetAddress.ts index c956e59e5..135234ad2 100644 --- a/bridge_ui/src/hooks/useSyncTargetAddress.ts +++ b/bridge_ui/src/hooks/useSyncTargetAddress.ts @@ -22,7 +22,7 @@ import { } from "../store/selectors"; import { setTargetAddressHex } from "../store/transferSlice"; import { uint8ArrayToHex } from "../utils/array"; -import bech32 from "bech32"; +import { canonicalAddress } from "../utils/terra"; function useSyncTargetAddress(shouldFire: boolean) { const dispatch = useDispatch(); @@ -81,10 +81,7 @@ function useSyncTargetAddress(shouldFire: boolean) { dispatch( setTargetAddressHex( uint8ArrayToHex( - zeroPad( - new Uint8Array(bech32.fromWords(bech32.decode(terraWallet.walletAddress).words)), - 32 - ) + zeroPad(canonicalAddress(terraWallet.walletAddress), 32) ) ) ); diff --git a/bridge_ui/src/utils/array.ts b/bridge_ui/src/utils/array.ts index 7a81d1e76..a16ca1e3a 100644 --- a/bridge_ui/src/utils/array.ts +++ b/bridge_ui/src/utils/array.ts @@ -2,9 +2,11 @@ import { ChainId, CHAIN_ID_ETH, CHAIN_ID_SOLANA, + CHAIN_ID_TERRA, } from "@certusone/wormhole-sdk"; import { PublicKey } from "@solana/web3.js"; import { hexValue } from "ethers/lib/utils"; +import { humanAddress } from "./terra"; export const uint8ArrayToHex = (a: Uint8Array) => Buffer.from(a).toString("hex"); @@ -17,4 +19,6 @@ export const hexToNativeString = (h: string | undefined, c: ChainId) => ? new PublicKey(hexToUint8Array(h)).toString() : c === CHAIN_ID_ETH ? hexValue(hexToUint8Array(h)) + : c === CHAIN_ID_TERRA + ? humanAddress(hexToUint8Array(h.substr(24))) // terra expects 20 bytes, not 32 : h; diff --git a/bridge_ui/src/utils/terra.ts b/bridge_ui/src/utils/terra.ts index 0c66c2a55..4fe941822 100644 --- a/bridge_ui/src/utils/terra.ts +++ b/bridge_ui/src/utils/terra.ts @@ -3,6 +3,7 @@ import { ConnectedWallet as TerraConnectedWallet, } from "@terra-money/wallet-provider"; import { LCDClient } from "@terra-money/terra.js"; +import bech32 from "bech32"; // TODO: Loop txInfo for timed out transactions. // lcd.tx.txInfo(transaction.result.txhash); @@ -16,3 +17,10 @@ export async function waitForTerraExecution( }); return transaction; } + +export function canonicalAddress(humanAddress: string) { + return new Uint8Array(bech32.fromWords(bech32.decode(humanAddress).words)); +} +export function humanAddress(canonicalAddress: Uint8Array) { + return bech32.encode("terra", bech32.toWords(canonicalAddress)); +}