Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { ConfigService } from '../config.service';
import { SimulatedTxResultResponse } from '../cosmos/tx-common.model';
import { TxCommonService } from '../cosmos/tx-common.service';
import { KeplrService } from '../wallets/keplr/keplr.service';
import { CosmosWallet, WalletType } from '../wallets/wallet.model';
import { WalletService } from '../wallets/wallet.service';
import { Dialog } from '@angular/cdk/dialog';
Expand All @@ -30,6 +31,7 @@ export class TxCommonApplicationService {
private readonly walletService: WalletService,
private readonly txCommon: TxCommonService,
private readonly config: ConfigService,
private readonly keplr: KeplrService,
) {}

async getPrerequisiteData() {
Expand Down Expand Up @@ -172,6 +174,15 @@ export class TxCommonApplicationService {
throw Error('Failed to sign!');
}

if (currentCosmosWallet.type === WalletType.keplr) {
console.log('keplr sendTx');
const txHash = await this.keplr.sendTx(signedTxBuilder);
if (!txHash) {
throw Error('Failed to broadcast Tx on Keplr!');
}
return txHash;
}
console.log('NOT keplr sendTx');
txResult = await this.txCommon.announceTx(txBuilder);
txHash = txResult?.tx_response?.txhash;
if (txHash === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StoredWallet, WalletType } from '../wallet.model';
import { IKeplrInfrastructureService } from './keplr.service';
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BroadcastMode } from '@cosmjs/launchpad';
import cosmosclient from '@cosmos-client/core';
import { ChainInfo, Key } from '@keplr-wallet/types';
import { LoadingDialogService } from 'projects/shared/src/lib/components/loading-dialog';
Expand Down Expand Up @@ -270,4 +271,18 @@ export class KeplrInfrastructureService implements IKeplrInfrastructureService {

return txBuilder;
}

async sendTx(txBuilder: cosmosclient.TxBuilder): Promise<string | undefined> {
if (!window.keplr) {
alert('Please install Keplr extension');
return;
}
const chainId = this.configService.configs[0].chainID;
await window.keplr.enable(chainId);
const txByteArray = Uint8Array.from(Buffer.from(txBuilder.txBytes(), 'base64'));
const res = await window.keplr.sendTx(chainId, txByteArray, BroadcastMode.Sync);
console.log(res);
const txHash = Buffer.from(res).toString('hex').toUpperCase();
return txHash;
}
}
5 changes: 5 additions & 0 deletions projects/portal/src/app/models/wallets/keplr/keplr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IKeplrInfrastructureService {
signerBaseAccount: cosmosclient.proto.cosmos.auth.v1beta1.BaseAccount,
) => Promise<cosmosclient.TxBuilder>;
checkWallet: () => Promise<StoredWallet | null | undefined>;
sendTx: (txBuilder: cosmosclient.TxBuilder) => Promise<string | undefined>;
}

@Injectable({
Expand Down Expand Up @@ -42,4 +43,8 @@ export class KeplrService {
async checkWallet(): Promise<StoredWallet | null | undefined> {
return await this.iKeplrInfrastructureService.checkWallet();
}

async sendTx(txBuilder: cosmosclient.TxBuilder): Promise<string | undefined> {
return await this.iKeplrInfrastructureService.sendTx(txBuilder);
}
}