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",
"private": true,
"dependencies": {
"@certusone/wormhole-sdk": "^0.1.5",
"@certusone/wormhole-sdk": "^0.2.0",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60",
@ -25,7 +25,7 @@
"@solana/wallet-adapter-wallets": "^0.9.0",
"@solana/wallet-base": "^0.0.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",
"bech32": "^1.1.4",
"bn.js": "^5.1.3",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import {
isNativeTerra,
} from "@certusone/wormhole-sdk";
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 axios from "axios";
// import { TerraTokenMetadata } from "../hooks/useTerraTokenMap";
@ -40,8 +40,7 @@ export async function waitForTerraExecution(transaction: TxResult) {
console.error(e);
}
}
if (info.code !== undefined) {
// error code
if (isTxError(info)) {
throw new Error(
`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);
//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.
let gasPrices = await axios
const gasPrices = await axios
.get(TERRA_GAS_PRICES_URL)
.then((result) => result.data);
const account = await lcd.auth.accountInfo(wallet.walletAddress);
const feeEstimate = await lcd.tx.estimateFee(
wallet.walletAddress,
[...msgs],
[
{
sequenceNumber: account.getSequenceNumber(),
publicKey: account.getPublicKey(),
},
],
{
msgs: [...msgs],
memo,
feeDenoms,
gasPrices,