bridge_ui: Updated terra dependencies

Updated @terra-money/wallet-provider to 3.8.0
This commit is contained in:
Kevin Peters 2022-02-10 21:38:37 +00:00 committed by Evan Gray
parent 27e8952c8b
commit b38f842e40
8 changed files with 393 additions and 713 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@certusone/wormhole-sdk": "^0.1.5", "@certusone/wormhole-sdk": "^0.2.0",
"@material-ui/core": "^4.12.2", "@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.11.2", "@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60", "@material-ui/lab": "^4.0.0-alpha.60",
@ -25,7 +25,7 @@
"@solana/wallet-adapter-wallets": "^0.9.0", "@solana/wallet-adapter-wallets": "^0.9.0",
"@solana/wallet-base": "^0.0.1", "@solana/wallet-base": "^0.0.1",
"@solana/web3.js": "^1.24.1", "@solana/web3.js": "^1.24.1",
"@terra-money/wallet-provider": "^2.2.0", "@terra-money/wallet-provider": "^3.8.0",
"axios": "^0.21.1", "axios": "^0.21.1",
"bech32": "^1.1.4", "bech32": "^1.1.4",
"bn.js": "^5.1.3", "bn.js": "^5.1.3",

View File

@ -1,8 +1,10 @@
import { Typography } from "@material-ui/core";
import { useTerraWallet } from "../contexts/TerraWalletContext"; import { useTerraWallet } from "../contexts/TerraWalletContext";
import ToggleConnectedButton from "./ToggleConnectedButton"; import ToggleConnectedButton from "./ToggleConnectedButton";
const TerraWalletKey = () => { const TerraWalletKey = () => {
const { connect, disconnect, connected, wallet } = useTerraWallet(); const { connect, disconnect, connected, wallet, providerError } =
useTerraWallet();
const pk = const pk =
(wallet && (wallet &&
wallet.wallets && wallet.wallets &&
@ -10,12 +12,19 @@ const TerraWalletKey = () => {
wallet.wallets[0].terraAddress) || wallet.wallets[0].terraAddress) ||
""; "";
return ( return (
<ToggleConnectedButton <>
connect={connect} <ToggleConnectedButton
disconnect={disconnect} connect={connect}
connected={connected} disconnect={disconnect}
pk={pk} connected={connected}
/> pk={pk}
/>
{providerError ? (
<Typography variant="body2" color="error">
{providerError}
</Typography>
) : null}
</>
); );
}; };

View File

@ -3,6 +3,7 @@ import {
Wallet, Wallet,
WalletProvider, WalletProvider,
useWallet, useWallet,
ConnectType,
} from "@terra-money/wallet-provider"; } from "@terra-money/wallet-provider";
import React, { import React, {
ReactChildren, ReactChildren,
@ -35,6 +36,7 @@ interface ITerraWalletContext {
disconnect(): void; disconnect(): void;
connected: boolean; connected: boolean;
wallet: any; wallet: any;
providerError: string | null;
} }
const TerraWalletContext = React.createContext<ITerraWalletContext>({ const TerraWalletContext = React.createContext<ITerraWalletContext>({
@ -42,6 +44,7 @@ const TerraWalletContext = React.createContext<ITerraWalletContext>({
disconnect: () => {}, disconnect: () => {},
connected: false, connected: false,
wallet: null, wallet: null,
providerError: null,
}); });
export const TerraWalletWrapper = ({ export const TerraWalletWrapper = ({
@ -53,19 +56,27 @@ export const TerraWalletWrapper = ({
const terraWallet = useWallet(); const terraWallet = useWallet();
const [, setWallet] = useState<Wallet | undefined>(undefined); const [, setWallet] = useState<Wallet | undefined>(undefined);
const [connected, setConnected] = useState(false); const [connected, setConnected] = useState(false);
const [providerError, setProviderError] = useState<string | null>(null);
const connect = useCallback(() => { const connect = useCallback(() => {
const CHROME_EXTENSION = 1;
if (terraWallet) { if (terraWallet) {
terraWallet.connect(terraWallet.availableConnectTypes[CHROME_EXTENSION]); // TODO: Support other connect types
if (terraWallet.availableConnectTypes.includes(ConnectType.EXTENSION)) {
terraWallet.connect(ConnectType.EXTENSION);
setConnected(true);
setProviderError(null);
} else {
setConnected(false);
setProviderError("Please install the Terra Station Extension");
}
setWallet(terraWallet); setWallet(terraWallet);
setConnected(true);
} }
}, [terraWallet]); }, [terraWallet]);
const disconnect = useCallback(() => { const disconnect = useCallback(() => {
setConnected(false); setConnected(false);
setWallet(undefined); setWallet(undefined);
setProviderError(null);
}, []); }, []);
const contextValue = useMemo( const contextValue = useMemo(
@ -74,8 +85,9 @@ export const TerraWalletWrapper = ({
disconnect, disconnect,
connected, connected,
wallet: terraWallet, wallet: terraWallet,
providerError,
}), }),
[connect, disconnect, connected, terraWallet] [connect, disconnect, connected, terraWallet, providerError]
); );
return ( return (

View File

@ -40,7 +40,7 @@ export default function useGetIsTransferCompleted(recoveryOnly: boolean): {
const targetAddress = useSelector(selectTransferTargetAddressHex); const targetAddress = useSelector(selectTransferTargetAddressHex);
const targetChain = useSelector(selectTransferTargetChain); const targetChain = useSelector(selectTransferTargetChain);
const { isReady, walletAddress } = useIsWalletReady(targetChain, false); const { isReady } = useIsWalletReady(targetChain, false);
const { provider, chainId: evmChainId } = useEthereumProvider(); const { provider, chainId: evmChainId } = useEthereumProvider();
const signedVAA = useTransferSignedVAA(); const signedVAA = useTransferSignedVAA();
@ -90,7 +90,7 @@ export default function useGetIsTransferCompleted(recoveryOnly: boolean): {
setIsLoading(false); setIsLoading(false);
} }
})(); })();
} else if (targetChain === CHAIN_ID_TERRA && walletAddress) { } else if (targetChain === CHAIN_ID_TERRA) {
setIsLoading(true); setIsLoading(true);
(async () => { (async () => {
try { try {
@ -98,7 +98,6 @@ export default function useGetIsTransferCompleted(recoveryOnly: boolean): {
transferCompleted = await getIsTransferCompletedTerra( transferCompleted = await getIsTransferCompletedTerra(
getTokenBridgeAddressForChain(targetChain), getTokenBridgeAddressForChain(targetChain),
signedVAA, signedVAA,
walletAddress,
lcdClient, lcdClient,
TERRA_GAS_PRICES_URL TERRA_GAS_PRICES_URL
); );
@ -122,7 +121,6 @@ export default function useGetIsTransferCompleted(recoveryOnly: boolean): {
targetAddress, targetAddress,
signedVAA, signedVAA,
isReady, isReady,
walletAddress,
provider, provider,
]); ]);

View File

@ -28,7 +28,7 @@ export default function useTerraNativeBalances(
const lcd = new LCDClient(TERRA_HOST); const lcd = new LCDClient(TERRA_HOST);
lcd.bank lcd.bank
.balance(walletAddress) .balance(walletAddress)
.then((coins) => { .then(([coins]) => {
// coins doesn't support reduce // coins doesn't support reduce
const balancePairs = coins.map(({ amount, denom }) => [ const balancePairs = coins.map(({ amount, denom }) => [
denom, denom,

View File

@ -108,7 +108,7 @@ const getBalancesTerra = async (walletAddress: string) => {
const lcd = new LCDClient(TERRA_HOST); const lcd = new LCDClient(TERRA_HOST);
return lcd.bank return lcd.bank
.balance(walletAddress) .balance(walletAddress)
.then((coins) => { .then(([coins]) => {
const balances = coins const balances = coins
.filter(({ denom }) => { .filter(({ denom }) => {
return TARGET_DENOMS.includes(denom); return TARGET_DENOMS.includes(denom);

View File

@ -4,7 +4,7 @@ import {
isNativeTerra, isNativeTerra,
} from "@certusone/wormhole-sdk"; } from "@certusone/wormhole-sdk";
import { formatUnits } from "@ethersproject/units"; import { formatUnits } from "@ethersproject/units";
import { LCDClient } from "@terra-money/terra.js"; import { LCDClient, isTxError } from "@terra-money/terra.js";
import { ConnectedWallet, TxResult } from "@terra-money/wallet-provider"; import { ConnectedWallet, TxResult } from "@terra-money/wallet-provider";
import axios from "axios"; import axios from "axios";
// import { TerraTokenMetadata } from "../hooks/useTerraTokenMap"; // import { TerraTokenMetadata } from "../hooks/useTerraTokenMap";
@ -40,8 +40,7 @@ export async function waitForTerraExecution(transaction: TxResult) {
console.error(e); console.error(e);
} }
} }
if (info.code !== undefined) { if (isTxError(info)) {
// error code
throw new Error( throw new Error(
`Tx ${transaction.result.txhash}: error code ${info.code}: ${info.raw_log}` `Tx ${transaction.result.txhash}: error code ${info.code}: ${info.raw_log}`
); );
@ -73,14 +72,21 @@ export async function postWithFees(
const lcd = new LCDClient(TERRA_HOST); const lcd = new LCDClient(TERRA_HOST);
//let gasPrices = await lcd.config.gasPrices //Unsure if the values returned from this are hardcoded or not. //let gasPrices = await lcd.config.gasPrices //Unsure if the values returned from this are hardcoded or not.
//Thus, we are going to pull it directly from the current FCD. //Thus, we are going to pull it directly from the current FCD.
let gasPrices = await axios const gasPrices = await axios
.get(TERRA_GAS_PRICES_URL) .get(TERRA_GAS_PRICES_URL)
.then((result) => result.data); .then((result) => result.data);
const account = await lcd.auth.accountInfo(wallet.walletAddress);
const feeEstimate = await lcd.tx.estimateFee( const feeEstimate = await lcd.tx.estimateFee(
wallet.walletAddress, [
[...msgs], {
sequenceNumber: account.getSequenceNumber(),
publicKey: account.getPublicKey(),
},
],
{ {
msgs: [...msgs],
memo, memo,
feeDenoms, feeDenoms,
gasPrices, gasPrices,