Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Aug 17, 2022
1 parent b87be9c commit d962b6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 0 additions & 5 deletions core/src/clients/bridges/IBCBridge/IBCBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 19 additions & 7 deletions wallet-keplr/src/KeplrWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -82,9 +83,14 @@ export class KeplrWalletProvider extends CosmosWalletProvider {
): Promise<OfflineSigner & OfflineDirectSigner> {
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}`);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand Down Expand Up @@ -318,7 +331,6 @@ export class KeplrWalletProvider extends CosmosWalletProvider {
}

async broadcast(chain: Chain, tx: NativeDexSignedTransaction<EncodeObject>) {
console.log("tx", tx);
// Broadcast EncodeObject
if ((tx.signed as TxRaw).authInfoBytes) {
const chainConfig = this.getIBCChainConfig(chain);
Expand Down

0 comments on commit d962b6d

Please sign in to comment.