Skip to content

Commit

Permalink
chore: passing appName on webWallet logout
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed May 1, 2024
1 parent 749881f commit ac5db7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
34 changes: 30 additions & 4 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export interface LoginResult {
session: Session
}

export interface LogoutContext {
session: Session
appName: string
}

export interface RestoreArgs {
chain: Checksum256Type | ChainDefinition
actor?: NameType
Expand Down Expand Up @@ -476,6 +481,27 @@ export class SessionKit {
}
}

logoutParams(session: Session | SerializedSession, walletPlugin: WalletPlugin): LogoutContext {
if (session instanceof Session) {
return {
session,
appName: this.appName,
}
} else {
return {
session: new Session({
chain: this.getChainDefinition(session.chain),
permissionLevel: PermissionLevel.from({
actor: session.actor,
permission: session.permission,
}),
walletPlugin,
}),
appName: this.appName,
}
}
}

async logout(session?: Session | SerializedSession) {
if (!this.storage) {
throw new Error('An instance of Storage must be provided to utilize the logout method.')
Expand All @@ -487,7 +513,7 @@ export class SessionKit {
)

if (walletPlugin?.logout) {
await walletPlugin.logout(session)
await walletPlugin.logout(this.logoutParams(session, walletPlugin))
}

const sessions = await this.getSessions()
Expand All @@ -508,10 +534,10 @@ export class SessionKit {
await this.storage.write('sessions', JSON.stringify(other))
}
} else {
await this.storage.remove('sessions')

const sessions = await this.getSessions()

await this.storage.remove('sessions')

if (sessions) {
Promise.all(
sessions.map((s) => {
Expand All @@ -520,7 +546,7 @@ export class SessionKit {
)

if (walletPlugin?.logout) {
return walletPlugin.logout(s)
return walletPlugin.logout(this.logoutParams(s, walletPlugin))
} else {
return Promise.resolve()
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IdentityProof, ResolvedSigningRequest} from '@wharfkit/signing-request'

import {LoginContext} from './login'
import {TransactContext} from './transact'
import {SerializedSession, Session} from './session'
import {LogoutContext} from './kit'

/**
* The static configuration of a [[WalletPlugin]].
Expand Down Expand Up @@ -135,7 +135,7 @@ export interface WalletPlugin {
* @returns A promise that resolves when the wallet plugin logout process is complete.
* @throws An error if the logout could not happen.
*/
logout?(session: Session | SerializedSession): Promise<void>
logout?(context: LogoutContext): Promise<void>

/**
* Serialize the [[WalletPlugin]] ID and data into a plain object.
Expand Down

0 comments on commit ac5db7f

Please sign in to comment.