Skip to content

Commit

Permalink
Feat/sdk disconnect (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
rustin01 authored Aug 6, 2024
1 parent dd6169b commit fa72eea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 5 additions & 1 deletion apps/wallet/src/stores/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GetMnemonicResult, UpdateMnemonicInput } from "../apis/models";
import { AES, enc, MD5 } from "crypto-js";
import { HIBIT_ENV } from "../utils/env";
import { getChainByChainId } from "../utils/chain";
import authManager from "../utils/auth";

const SESSION_CONFIG_KEY = 'hibitIdSessionConfig'

Expand Down Expand Up @@ -116,12 +117,15 @@ export class HibitIdSession {
}
}

public disconnect = () => {
public disconnect = async () => {
this.auth = null
this.wallet = null
this._account = null
this._mnemonic = null
this._password = null
if (RUNTIME_ENV === RuntimeEnv.SDK) {
await authManager.logout()
}
}

public switchChain = async (chain: ChainInfo) => {
Expand Down
6 changes: 6 additions & 0 deletions apps/wallet/src/utils/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { IAuthenticateProvider } from "./types";
import { TelegramAuthenticateProvider } from "./providers/telegram";
import { AuthenticatorType } from "@deland-labs/hibit-id-sdk";
import { prOidc } from "../oidc";
import { RUNTIME_ENV } from "../runtime";
import { RuntimeEnv } from "../basicEnums";
import rpcManager from "../../stores/rpc";

const HIBIT_ID_WEB = import.meta.env.VITE_HIBIT_ID_WEB

Expand Down Expand Up @@ -36,6 +39,9 @@ export class AuthManager {
if (!oidc.isUserLoggedIn) {
return;
}
if (RUNTIME_ENV === RuntimeEnv.SDK) {
rpcManager.notifyAccountsChanged(null)
}
await oidc.logout({
redirectTo: 'specific url',
url: HIBIT_ID_WEB,
Expand Down
10 changes: 2 additions & 8 deletions apps/wallet/src/utils/auth/providers/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export class TelegramAuthenticateProvider implements IAuthenticateProvider {
public authenticate: (launchParams?: any) => Promise<any> = async (launchParams?: string) => {
// mini app
if (launchParams) {
// const query = location.hash.slice(1)
// window.location.href = `${AUTH_SERVER_URL}Telegram/Login?${query}`
sessionStorage.removeItem('telegram-apps/launch-params')
// sessionStorage.removeItem('telegram-apps/launch-params')
window.location.href = `${AUTH_SERVER_URL}Telegram/Login?tgWebAppData=${encodeURIComponent(launchParams)}&returnUrl=${encodeURIComponent(`${location.origin}/oidc-login`)}`
return
}
Expand All @@ -44,12 +42,8 @@ export class TelegramAuthenticateProvider implements IAuthenticateProvider {
reject(new Error('Telegram login failed'))
return
}
// const userData: any = { ...data }
// delete userData.hash
// delete userData.auth_date
// const queryValue = `user=${encodeURIComponent(JSON.stringify(userData))}&auth_date=${data.auth_date}&hash=${data.hash}`
const queryValue = objToQuery(data)
sessionStorage.removeItem('telegram-apps/launch-params')
// sessionStorage.removeItem('telegram-apps/launch-params')
window.location.href = `${AUTH_SERVER_URL}Telegram/WebLogin?${queryValue}&returnUrl=${encodeURIComponent(`${location.origin}/oidc-login`)}`
resolve(true)
},
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/lib/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class HibitIdWallet {
if (this._hasSession) {
this.showIframe()
}
// this._iframe!.show({ fullscreen: true, style: {} })
const res = await this._rpc!.call<ConnectResponse>(HibitIdExposeRPCMethod.CONNECT, {
chainId,
})
Expand All @@ -62,7 +61,6 @@ export class HibitIdWallet {
this._iframe!.hide()
this._controller?.setOpen(false)
this._connected = true
// this._controller = new HibitIdController(this.toggleIframe)
console.log('[hibit id connected]')

return {
Expand Down

0 comments on commit fa72eea

Please sign in to comment.