bridge_ui: Updated terra dependencies
Updated @terra-money/wallet-provider to 3.8.0
This commit is contained in:
parent
27e8952c8b
commit
b38f842e40
File diff suppressed because it is too large
Load Diff
|
@ -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",
|
||||||
|
|
|
@ -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}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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 (
|
||||||
|
|
|
@ -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,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue