Skip to content

Commit 07501af

Browse files
committed
fix(settings): list stored custodial profiles in the account switcher even without an active custodial token
1 parent cffe12c commit 07501af

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

__tests__/screens/settings-screen/multi-account.spec.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ jest.mock("@app/utils/storage/secureStorage", () => ({
2929
}))
3030

3131
const mockSaveProfile = jest.fn()
32+
let mockAppConfigToken = "mock-token-1"
3233

3334
jest.mock("@app/hooks", () => ({
3435
useAppConfig: () => ({
3536
appConfig: {
3637
galoyInstance: {
3738
authUrl: "https://api.blink.sv",
3839
},
39-
token: "mock-token-1",
40+
token: mockAppConfigToken,
4041
},
4142
}),
4243
useSaveSessionProfile: () => ({
@@ -50,6 +51,8 @@ describe("Settings", () => {
5051
beforeEach(() => {
5152
loadLocale("en")
5253
LL = i18nObject("en")
54+
mockAppConfigToken = "mock-token-1"
55+
mockSaveProfile.mockClear()
5356
})
5457

5558
it("Switch account shows user profiles", async () => {
@@ -71,4 +74,20 @@ describe("Settings", () => {
7174
expect(profiles).toEqual(expectedProfiles)
7275
expect(screen.getByTestId(LL.ProfileScreen.addAccount())).toBeTruthy()
7376
})
77+
78+
it("shows stored custodial profiles even with no current token (self-custodial active)", async () => {
79+
mockAppConfigToken = ""
80+
;(KeyStoreWrapper.getSessionProfiles as jest.Mock).mockResolvedValue(expectedProfiles)
81+
82+
render(
83+
<ContextForScreen>
84+
<SwitchAccountComponent />
85+
</ContextForScreen>,
86+
)
87+
88+
await waitFor(() => {
89+
expect(screen.getByText("TestUser")).toBeTruthy()
90+
})
91+
expect(mockSaveProfile).not.toHaveBeenCalled()
92+
})
7493
})

app/screens/settings-screen/account/multi-account/switch-account.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ export const SwitchAccount: React.FC = () => {
3232
const [nextProfileToken, setNextProfileToken] = useState<string>()
3333

3434
useEffect(() => {
35-
if (!currentToken) return
3635
let isMounted = true
3736

3837
const loadProfiles = async () => {
3938
let profilesList = await fetchProfiles(currentToken)
40-
if (profilesList.length === 0) {
39+
if (profilesList.length === 0 && currentToken) {
4140
await saveProfile(currentToken)
4241
profilesList = await fetchProfiles(currentToken)
4342
}

0 commit comments

Comments
 (0)