From d962b6d4253e5bd3f68cfab4647b29862dc691b6 Mon Sep 17 00:00:00 2001 From: Alan Soares Date: Wed, 17 Aug 2022 16:15:30 +1200 Subject: [PATCH] chore: cleanup --- .../clients/bridges/IBCBridge/IBCBridge.ts | 5 ---- wallet-keplr/src/KeplrWalletProvider.ts | 26 ++++++++++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/src/clients/bridges/IBCBridge/IBCBridge.ts b/core/src/clients/bridges/IBCBridge/IBCBridge.ts index 37c60c152..31ab6e976 100644 --- a/core/src/clients/bridges/IBCBridge/IBCBridge.ts +++ b/core/src/clients/bridges/IBCBridge/IBCBridge.ts @@ -32,11 +32,6 @@ import { TokenRegistry } from "../../native/TokenRegistry"; import { CosmosWalletProvider } from "../../wallets/cosmos/CosmosWalletProvider"; import { BaseBridge, BridgeParams, BridgeTx, IBCBridgeTx } from "../BaseBridge"; import { getTransferTimeoutData } from "./getTransferTimeoutData"; -import { - DEFAULT_FEE, - SifchainEncodeObject, - SifSigningStargateClient, -} from "../../../clients/sifchain"; export type IBCBridgeContext = { sifRpcUrl: string; diff --git a/wallet-keplr/src/KeplrWalletProvider.ts b/wallet-keplr/src/KeplrWalletProvider.ts index fa052eaf0..0b526bbe4 100644 --- a/wallet-keplr/src/KeplrWalletProvider.ts +++ b/wallet-keplr/src/KeplrWalletProvider.ts @@ -4,6 +4,7 @@ import { StargateClient, } from "@cosmjs/stargate"; import { cosmos, ibc } from "@keplr-wallet/cosmos"; +import { AminoMsg } from "@cosmjs/amino"; import { Chain, Network } from "@sifchain/sdk"; import { @@ -82,9 +83,14 @@ export class KeplrWalletProvider extends CosmosWalletProvider { ): Promise { const chainConfig = this.getIBCChainConfig(chain); const keplr = await getKeplrProvider(); - await keplr?.experimentalSuggestChain(chainConfig.keplrChainInfo); - await keplr?.enable(chainConfig.chainId); - const sendingSigner = keplr?.getOfflineSigner(chainConfig.chainId); + + if (!keplr) { + throw new Error("Keplr not installed"); + } + + await keplr.experimentalSuggestChain(chainConfig.keplrChainInfo); + await keplr.enable(chainConfig.chainId); + const sendingSigner = keplr.getOfflineSigner(chainConfig.chainId); if (!sendingSigner) throw new Error(`Failed to get sendingSigner for ${chainConfig.chainId}`); @@ -167,8 +173,10 @@ export class KeplrWalletProvider extends CosmosWalletProvider { const key = await keplr?.getKey(chainConfig.chainId); const bech32Address = key!.bech32Address; - const aminoMsgs = tx.msgs.map(converter.toAmino.bind(converter)); - const aminoMsg = aminoMsgs[0]; + const aminoMsgs: AminoMsg[] = tx.msgs.map( + converter.toAmino.bind(converter), + ); + const [aminoMsg] = aminoMsgs; const protoMsg = { type_url: "/ibc.applications.transfer.v1.MsgTransfer", @@ -273,7 +281,7 @@ export class KeplrWalletProvider extends CosmosWalletProvider { const converter = new NativeAminoTypes(); - const msgs = tx.msgs.map(converter.toAmino.bind(converter)); + const msgs: AminoMsg[] = tx.msgs.map(converter.toAmino.bind(converter)); const fee = { amount: [tx.fee.price], @@ -289,6 +297,11 @@ export class KeplrWalletProvider extends CosmosWalletProvider { ); } const keplr = await getKeplrProvider(); + + if (!keplr) { + throw new Error("No keplr provider found"); + } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const signDoc = makeSignDoc( msgs, @@ -318,7 +331,6 @@ export class KeplrWalletProvider extends CosmosWalletProvider { } async broadcast(chain: Chain, tx: NativeDexSignedTransaction) { - console.log("tx", tx); // Broadcast EncodeObject if ((tx.signed as TxRaw).authInfoBytes) { const chainConfig = this.getIBCChainConfig(chain);