Skip to content

Commit

Permalink
2958 eventsub (#2960)
Browse files Browse the repository at this point in the history
* updated taquito-beacon-wallet to use eventsub

* removed comments

* removed console log

* trigger ci build
  • Loading branch information
dsawali authored May 14, 2024
1 parent 5b9e302 commit 72a4d60
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/taquito-beacon-wallet/src/taquito-beacon-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
PermissionScope,
getDAppClientInstance,
SigningType,
AccountInfo,
BeaconEvent,
} from '@airgap/beacon-dapp';
import { BeaconWalletNotInitialized, MissingRequiredScopes } from './errors';
import toBuffer from 'typedarray-to-buffer';
Expand All @@ -32,9 +34,13 @@ export { BeaconWalletNotInitialized, MissingRequiredScopes } from './errors';

export class BeaconWallet implements WalletProvider {
public client: DAppClient;
public account: AccountInfo | undefined;

constructor(options: DAppClientOptions) {
this.client = getDAppClientInstance(options);
this.client.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (data) => {
this.account = data;
});
}

private validateRequiredScopesOrFail(
Expand All @@ -59,19 +65,17 @@ export class BeaconWallet implements WalletProvider {
}

async getPKH() {
const account = await this.client.getActiveAccount();
if (!account) {
if (!this.account) {
throw new BeaconWalletNotInitialized();
}
return account.address;
return this.account.address;
}

async getPK() {
const account = await this.client.getActiveAccount();
if (!account) {
if (!this.account) {
throw new BeaconWalletNotInitialized();
}
return account.publicKey ?? '';
return this.account.publicKey ?? '';
}

async mapTransferParamsToWalletParams(params: () => Promise<WalletTransferParams>) {
Expand Down Expand Up @@ -167,11 +171,10 @@ export class BeaconWallet implements WalletProvider {
}

async sendOperations(params: any[]) {
const account = await this.client.getActiveAccount();
if (!account) {
if (!this.account) {
throw new BeaconWalletNotInitialized();
}
const permissions = account.scopes;
const permissions = this.account.scopes;
this.validateRequiredScopesOrFail(permissions, [PermissionScope.OPERATION_REQUEST]);

const { transactionHash } = await this.client.requestOperation({ operationDetails: params });
Expand Down

0 comments on commit 72a4d60

Please sign in to comment.