|
23 | 23 | authenticationStore, |
24 | 24 | isAuthenticatedStore, |
25 | 25 | } from "$lib/stores/authentication.store"; |
26 | | - import { throwCanisterError } from "$lib/utils/utils"; |
| 26 | + import { throwCanisterError, waitFor } from "$lib/utils/utils"; |
27 | 27 | import type { |
28 | 28 | AccountInfo, |
29 | 29 | AccountNumber, |
|
32 | 32 | import { slide, fade, scale } from "svelte/transition"; |
33 | 33 | import Dialog from "$lib/components/ui/Dialog.svelte"; |
34 | 34 | import EditAccount from "$lib/components/views/EditAccount.svelte"; |
| 35 | + import ProgressRing from "$lib/components/ui/ProgressRing.svelte"; |
35 | 36 |
|
36 | 37 | const PRIMARY_ACCOUNT_NUMBER = undefined; |
37 | 38 | const MAX_ACCOUNTS = 5; |
|
75 | 76 | accounts?.map((account) => account.name[0] ?? primaryAccountName) ?? [], |
76 | 77 | ); |
77 | 78 | const authLastUsedFlow = new AuthLastUsedFlow(); |
| 79 | + const selectedIdentityNumber = $derived( |
| 80 | + $lastUsedIdentitiesStore.selected!.identityNumber, |
| 81 | + ); |
78 | 82 | // Initialize the flow every time the identity changes |
79 | 83 | $effect(() => { |
80 | | - authLastUsedFlow.init([$lastUsedIdentitiesStore.selected!.identityNumber]); |
| 84 | + authLastUsedFlow.init([selectedIdentityNumber]); |
81 | 85 | }); |
82 | 86 |
|
83 | 87 | const handleContinueDefault = async () => { |
|
286 | 290 | </div> |
287 | 291 | {/snippet} |
288 | 292 |
|
289 | | -{#snippet accountList()} |
| 293 | +{#snippet accountList(accounts: AccountInfo[])} |
290 | 294 | <div class="col-start-1 row-start-1" out:fade={{ duration: 100 }}> |
291 | 295 | <div class="!min-h-18" out:slide={{ axis: "y", duration: 300 }}> |
292 | | - {#if nonNullish(accounts)} |
293 | | - <div class="!min-h-18" in:slide={{ axis: "y", duration: 300 }}> |
294 | | - <div class="flex flex-col gap-2 pb-6" in:fade={{ duration: 300 }}> |
295 | | - <ul class="contents" aria-label={$t`Choose an account`}> |
296 | | - {#each accounts as account (account.account_number[0])} |
297 | | - <li class="contents"> |
298 | | - {@render accountListItem(account)} |
299 | | - </li> |
300 | | - {/each} |
301 | | - </ul> |
302 | | - <Tooltip |
303 | | - label={$t`Limit reached`} |
304 | | - description={$plural(MAX_ACCOUNTS, { |
305 | | - one: `You have reached the maximum of # account for a single app.`, |
306 | | - other: `You have reached the maximum of # accounts for a single app.`, |
307 | | - })} |
308 | | - direction="up" |
309 | | - align="center" |
310 | | - hidden={!isAccountLimitReached} |
311 | | - > |
312 | | - <div class="mt-3 shrink-0"> |
313 | | - <Button |
314 | | - onclick={() => (isCreateAccountDialogVisible = true)} |
315 | | - variant="tertiary" |
316 | | - disabled={isAccountLimitReached} |
317 | | - class="w-full" |
318 | | - > |
319 | | - <PlusIcon class="size-5" /> |
320 | | - {$t`Add another account`} |
321 | | - </Button> |
322 | | - </div> |
323 | | - </Tooltip> |
324 | | - </div> |
| 296 | + <div class="!min-h-18" in:slide={{ axis: "y", duration: 300 }}> |
| 297 | + <div class="flex flex-col gap-2 pb-6" in:fade={{ duration: 300 }}> |
| 298 | + <ul class="contents" aria-label={$t`Choose an account`}> |
| 299 | + {#each accounts as account (account.account_number[0])} |
| 300 | + <li class="contents"> |
| 301 | + {@render accountListItem(account)} |
| 302 | + </li> |
| 303 | + {/each} |
| 304 | + </ul> |
| 305 | + <Tooltip |
| 306 | + label={$t`Limit reached`} |
| 307 | + description={$plural(MAX_ACCOUNTS, { |
| 308 | + one: `You have reached the maximum of # account for a single app.`, |
| 309 | + other: `You have reached the maximum of # accounts for a single app.`, |
| 310 | + })} |
| 311 | + direction="up" |
| 312 | + align="center" |
| 313 | + hidden={!isAccountLimitReached} |
| 314 | + > |
| 315 | + <div class="mt-3 shrink-0"> |
| 316 | + <Button |
| 317 | + onclick={() => (isCreateAccountDialogVisible = true)} |
| 318 | + variant="tertiary" |
| 319 | + disabled={isAccountLimitReached} |
| 320 | + class="w-full" |
| 321 | + > |
| 322 | + <PlusIcon class="size-5" /> |
| 323 | + {$t`Add another account`} |
| 324 | + </Button> |
| 325 | + </div> |
| 326 | + </Tooltip> |
325 | 327 | </div> |
326 | | - {/if} |
| 328 | + </div> |
327 | 329 | </div> |
328 | 330 | </div> |
329 | 331 | {/snippet} |
|
348 | 350 | {$t`with your Internet Identity`} |
349 | 351 | </p> |
350 | 352 | <div class="grid"> |
351 | | - {#if isMultipleAccountsEnabled} |
352 | | - {@render accountList()} |
| 353 | + <!-- Nested if/else conditions breaks transitions, so they've been flattened here--> |
| 354 | + {#if isMultipleAccountsEnabled && $isAuthenticatedStore && nonNullish(accounts)} |
| 355 | + {@render accountList(accounts)} |
| 356 | + {:else if isMultipleAccountsEnabled && $isAuthenticatedStore} |
| 357 | + <!-- Display the progress ring if loading accounts takes longer than usual. |
| 358 | + |
| 359 | + This may happen the first time a user enables multiple accounts, |
| 360 | + as authentication might require an update call in case OpenID is used. --> |
| 361 | + <div |
| 362 | + class="col-start-1 row-start-1 flex min-h-18 items-center justify-center pb-6" |
| 363 | + in:fade={{ duration: 100, delay: 300 }} |
| 364 | + out:fade={{ duration: 100 }} |
| 365 | + > |
| 366 | + <ProgressRing class="text-fg-tertiary size-8" /> |
| 367 | + </div> |
353 | 368 | {:else} |
354 | 369 | {@render continueDefault()} |
355 | 370 | {/if} |
|
0 commit comments