about summary refs log tree commit diff
path: root/src/state/session
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/session')
-rw-r--r--src/state/session/__tests__/session-test.ts171
-rw-r--r--src/state/session/index.tsx20
-rw-r--r--src/state/session/reducer.ts26
-rw-r--r--src/state/session/types.ts8
4 files changed, 1 insertions, 224 deletions
diff --git a/src/state/session/__tests__/session-test.ts b/src/state/session/__tests__/session-test.ts
index b1886ff84..403785858 100644
--- a/src/state/session/__tests__/session-test.ts
+++ b/src/state/session/__tests__/session-test.ts
@@ -1302,177 +1302,6 @@ describe('session', () => {
     `)
   })
 
-  it('updates current account', () => {
-    let state = getInitialState([])
-
-    const agent1 = new BskyAgent({service: 'https://alice.com'})
-    agent1.session = {
-      did: 'alice-did',
-      handle: 'alice.test',
-      accessJwt: 'alice-access-jwt-1',
-      refreshJwt: 'alice-refresh-jwt-1',
-    }
-    state = run(state, [
-      {
-        type: 'switched-to-account',
-        newAgent: agent1,
-        newAccount: agentToSessionAccountOrThrow(agent1),
-      },
-    ])
-    expect(state.accounts.length).toBe(1)
-    expect(state.accounts[0].accessJwt).toBe('alice-access-jwt-1')
-    expect(state.currentAgentState.did).toBe('alice-did')
-
-    state = run(state, [
-      {
-        type: 'updated-current-account',
-        updatedFields: {
-          email: 'alice@foo.bar',
-          emailConfirmed: false,
-        },
-      },
-    ])
-    expect(state.accounts.length).toBe(1)
-    expect(state.accounts[0].email).toBe('alice@foo.bar')
-    expect(state.accounts[0].emailConfirmed).toBe(false)
-    expect(state.currentAgentState.did).toBe('alice-did')
-    expect(printState(state)).toMatchInlineSnapshot(`
-      {
-        "accounts": [
-          {
-            "accessJwt": "alice-access-jwt-1",
-            "deactivated": false,
-            "did": "alice-did",
-            "email": "alice@foo.bar",
-            "emailAuthFactor": false,
-            "emailConfirmed": false,
-            "handle": "alice.test",
-            "pdsUrl": undefined,
-            "refreshJwt": "alice-refresh-jwt-1",
-            "service": "https://alice.com/",
-          },
-        ],
-        "currentAgentState": {
-          "agent": {
-            "service": "https://alice.com/",
-          },
-          "did": "alice-did",
-        },
-        "needsPersist": true,
-      }
-    `)
-
-    state = run(state, [
-      {
-        type: 'updated-current-account',
-        updatedFields: {
-          handle: 'alice-updated.test',
-        },
-      },
-    ])
-    expect(state.accounts.length).toBe(1)
-    expect(state.accounts[0].handle).toBe('alice-updated.test')
-    expect(state.currentAgentState.did).toBe('alice-did')
-    expect(printState(state)).toMatchInlineSnapshot(`
-      {
-        "accounts": [
-          {
-            "accessJwt": "alice-access-jwt-1",
-            "deactivated": false,
-            "did": "alice-did",
-            "email": "alice@foo.bar",
-            "emailAuthFactor": false,
-            "emailConfirmed": false,
-            "handle": "alice-updated.test",
-            "pdsUrl": undefined,
-            "refreshJwt": "alice-refresh-jwt-1",
-            "service": "https://alice.com/",
-          },
-        ],
-        "currentAgentState": {
-          "agent": {
-            "service": "https://alice.com/",
-          },
-          "did": "alice-did",
-        },
-        "needsPersist": true,
-      }
-    `)
-
-    const agent2 = new BskyAgent({service: 'https://bob.com'})
-    agent2.session = {
-      did: 'bob-did',
-      handle: 'bob.test',
-      accessJwt: 'bob-access-jwt-1',
-      refreshJwt: 'bob-refresh-jwt-1',
-    }
-    state = run(state, [
-      {
-        // Switch to Bob.
-        type: 'switched-to-account',
-        newAgent: agent2,
-        newAccount: agentToSessionAccountOrThrow(agent2),
-      },
-      {
-        // Update Bob.
-        type: 'updated-current-account',
-        updatedFields: {
-          handle: 'bob-updated.test',
-        },
-      },
-      {
-        // Switch back to Alice.
-        type: 'switched-to-account',
-        newAgent: agent1,
-        newAccount: agentToSessionAccountOrThrow(agent1),
-      },
-      {
-        // Update Alice.
-        type: 'updated-current-account',
-        updatedFields: {
-          handle: 'alice-updated-2.test',
-        },
-      },
-    ])
-    expect(printState(state)).toMatchInlineSnapshot(`
-      {
-        "accounts": [
-          {
-            "accessJwt": "alice-access-jwt-1",
-            "deactivated": false,
-            "did": "alice-did",
-            "email": undefined,
-            "emailAuthFactor": false,
-            "emailConfirmed": false,
-            "handle": "alice-updated-2.test",
-            "pdsUrl": undefined,
-            "refreshJwt": "alice-refresh-jwt-1",
-            "service": "https://alice.com/",
-          },
-          {
-            "accessJwt": "bob-access-jwt-1",
-            "deactivated": false,
-            "did": "bob-did",
-            "email": undefined,
-            "emailAuthFactor": false,
-            "emailConfirmed": false,
-            "handle": "bob-updated.test",
-            "pdsUrl": undefined,
-            "refreshJwt": "bob-refresh-jwt-1",
-            "service": "https://bob.com/",
-          },
-        ],
-        "currentAgentState": {
-          "agent": {
-            "service": "https://alice.com/",
-          },
-          "did": "alice-did",
-        },
-        "needsPersist": true,
-      }
-    `)
-  })
-
   it('replaces local accounts with synced accounts', () => {
     let state = getInitialState([])
 
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx
index a8bd90ca1..b5a985e67 100644
--- a/src/state/session/index.tsx
+++ b/src/state/session/index.tsx
@@ -35,7 +35,6 @@ const ApiContext = React.createContext<SessionApiContext>({
   logout: async () => {},
   resumeSession: async () => {},
   removeAccount: () => {},
-  updateCurrentAccount: () => {},
 })
 
 export function Provider({children}: React.PropsWithChildren<{}>) {
@@ -149,15 +148,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
     [cancelPendingTask],
   )
 
-  const updateCurrentAccount = React.useCallback<
-    SessionApiContext['updateCurrentAccount']
-  >(account => {
-    dispatch({
-      type: 'updated-current-account',
-      updatedFields: account,
-    })
-  }, [])
-
   React.useEffect(() => {
     if (state.needsPersist) {
       state.needsPersist = false
@@ -210,16 +200,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
       logout,
       resumeSession,
       removeAccount,
-      updateCurrentAccount,
     }),
-    [
-      createAccount,
-      login,
-      logout,
-      resumeSession,
-      removeAccount,
-      updateCurrentAccount,
-    ],
+    [createAccount, login, logout, resumeSession, removeAccount],
   )
 
   // @ts-ignore
diff --git a/src/state/session/reducer.ts b/src/state/session/reducer.ts
index a14cd8e1c..775a6d038 100644
--- a/src/state/session/reducer.ts
+++ b/src/state/session/reducer.ts
@@ -37,15 +37,6 @@ export type Action =
       newAccount: SessionAccount
     }
   | {
-      type: 'updated-current-account'
-      updatedFields: Partial<
-        Pick<
-          SessionAccount,
-          'handle' | 'email' | 'emailConfirmed' | 'emailAuthFactor'
-        >
-      >
-    }
-  | {
       type: 'removed-account'
       accountDid: string
     }
@@ -134,23 +125,6 @@ export function reducer(state: State, action: Action): State {
         needsPersist: true,
       }
     }
-    case 'updated-current-account': {
-      const {updatedFields} = action
-      return {
-        accounts: state.accounts.map(a => {
-          if (a.did === state.currentAgentState.did) {
-            return {
-              ...a,
-              ...updatedFields,
-            }
-          } else {
-            return a
-          }
-        }),
-        currentAgentState: state.currentAgentState,
-        needsPersist: true,
-      }
-    }
     case 'removed-account': {
       const {accountDid} = action
       return {
diff --git a/src/state/session/types.ts b/src/state/session/types.ts
index b74eeddcb..d43b57cca 100644
--- a/src/state/session/types.ts
+++ b/src/state/session/types.ts
@@ -37,12 +37,4 @@ export type SessionApiContext = {
   logout: (logContext: LogEvents['account:loggedOut']['logContext']) => void
   resumeSession: (account: SessionAccount) => Promise<void>
   removeAccount: (account: SessionAccount) => void
-  updateCurrentAccount: (
-    account: Partial<
-      Pick<
-        SessionAccount,
-        'handle' | 'email' | 'emailConfirmed' | 'emailAuthFactor'
-      >
-    >,
-  ) => void
 }