bridge_ui: terra address helper
Change-Id: I01d5a474d1f26fd3c500e6f9d1bcede65c013c1e
This commit is contained in:
parent
4d7f11fc6c
commit
69349ab5c7
|
@ -24,7 +24,7 @@ export const SolanaWalletProvider: FC = (props) => {
|
|||
}, []);
|
||||
|
||||
return (
|
||||
<WalletProvider wallets={wallets}>
|
||||
<WalletProvider wallets={wallets} autoConnect>
|
||||
<WalletDialogProvider>{props.children}</WalletDialogProvider>
|
||||
</WalletProvider>
|
||||
);
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue