Skip to content

Commit

Permalink
chore: add getAccount method
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalavedra committed Jul 26, 2024
1 parent a8e4d26 commit 8bbc20e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/

# build folders
dist/
docs/
sdk/scripts/

# test configs
Expand Down
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfort/openfort-js",
"version": "0.8.2",
"version": "0.8.3",
"author": "Openfort (https://www.openfort.xyz)",
"bugs": "https://github.com/openfort-xyz/openfort-js/issues",
"repository": "openfort-xyz/openfort-js.git",
Expand Down
20 changes: 17 additions & 3 deletions sdk/src/openfort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ShieldAuthentication } from './iframe/types';
import { SignerManager } from './manager/signer';
import { OpenfortError, OpenfortErrorType } from './errors/openfortError';
import {
AccountType, Auth,
AccountType, CurrentAccount, Auth,
AuthPlayerResponse,
AuthResponse, EmbeddedState,
InitAuthResponse,
Expand Down Expand Up @@ -252,10 +252,12 @@ export class Openfort {
* @returns An AuthResponse object containing authentication details.
*/
public async signUpWithEmailPassword(
{ email, password, ecosystemGame }: { email: string; password: string, ecosystemGame?: string },
{
email, password, options, ecosystemGame,
}: { email: string; password: string, options?: { data: { name: string } }, ecosystemGame?: string },
): Promise<AuthResponse> {
const previousAuth = Authentication.fromStorage(this.storage);
const result = await this.authManager.signupEmailPassword(email, password, ecosystemGame);
const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
if (previousAuth && previousAuth.player !== result.player.id) {
this.logout();
}
Expand Down Expand Up @@ -569,6 +571,18 @@ export class Openfort {
return result.data;
}

public async getAccount(): Promise<CurrentAccount> {
const account = Account.fromStorage(this.storage);
if (!account) {
throw new OpenfortError('No signer configured', OpenfortErrorType.MISSING_SIGNER_ERROR);
}
return {
chainId: account.chainId,
address: account.address,
accountType: account.type as AccountType,
};
}

// eslint-disable-next-line class-methods-use-this
private get backendApiClients(): BackendApiClients {
const configuration = Configuration.fromStorage();
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export type SessionKey = {
isRegistered: boolean;
};

export type CurrentAccount = {
address: string;
accountType: AccountType;
chainId: number
};

export enum AccountType {
UPGRADEABLE_V4 = 'Upgradeable_v04',
MANAGED_V4 = 'Managed_v04',
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const VERSION = '0.8.2';
export const VERSION = '0.8.3';
export const PACKAGE = '@openfort/openfort-js';

0 comments on commit 8bbc20e

Please sign in to comment.