Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated beacon wallet with new event sub #2961

Merged
merged 1 commit into from
May 14, 2024
Merged
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
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 @@ -35,9 +37,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 @@ -62,19 +68,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 @@ -221,11 +225,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
Loading