Skip to content

Commit ca9b9f9

Browse files
authored
230 bug become provider refresh error (#232)
## Goal The goal of this PR is to use the persistent state to keep the dropdowns populated on refresh, resolving the bug. Closes #230 ## Discussion To recreate the bug on main: - go to become a provider - select network and address - see create msa or enter provider name - reload page - dropdowns are cleared, but create msa/enter provider name persists - if you go to the values in the store, you'll see that the selected user values are there (which is why we still see the create msa option), but the dropdowns aren't accessing those values. ## Checklist - [ ] PR Self-Review and Commenting - [ ] Docs updated - [ ] Tests added ## Demo https://github.com/user-attachments/assets/68603d11-8234-446c-a297-1795b13d2c7f
1 parent bcd40e3 commit ca9b9f9

File tree

5 files changed

+62
-30
lines changed

5 files changed

+62
-30
lines changed

src/components/atoms/DropDownMenu.svelte

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
placeholder?: string;
1010
onChange?: (() => void) | undefined;
1111
formatter?: (value: T) => string;
12+
getKey?: (item: T) => string;
1213
isLoading?: boolean;
1314
disabled?: boolean;
1415
[key: string]: unknown;
@@ -18,36 +19,37 @@
1819
label,
1920
id = '',
2021
options,
21-
value = $bindable(null),
22+
value = $bindable<T | null>(null),
2223
placeholder = '',
2324
onChange = undefined,
2425
formatter = (value: T) => value.toString(),
26+
getKey = (item: T) => item.toString(),
2527
isLoading = false,
2628
disabled = false,
2729
...rest
2830
}: Props = $props();
2931
</script>
3032

31-
<div class="column freq-select gap-f8 w-full max-w-[460px]">
33+
<div class="column freq-select gap-f8">
3234
<label class="font-bold" for={id}>{label}</label>
33-
<select
34-
{...rest}
35-
{id}
36-
bind:value
37-
onchange={onChange}
38-
data-test-id={id}
39-
class="mt-f8 pr-f32 outline-gray3 hover:outline-teal focus-visible:outline-gray3 disabled:outline-gray3 disabled:hover:outline-gray3 disabled:focus-visible:outline-gray3 relative m-0 cursor-pointer rounded-md bg-white p-2 align-middle outline focus-visible:outline
40-
active:outline
41-
disabled:cursor-not-allowed"
42-
disabled={isLoading || disabled}
43-
>
44-
<option class="text-gray3" value={null} disabled>{placeholder}</option>
45-
{#each options as option}
46-
<option value={option}>{formatter(option)}</option>
47-
{/each}
48-
</select>
49-
{#if isLoading}
50-
<LoadingIcon />
51-
{/if}
52-
<div class="select-arrow"></div>
35+
<div class="gap-f12 flex flex-row items-center">
36+
<select
37+
{...rest}
38+
{id}
39+
bind:value
40+
onchange={onChange}
41+
data-test-id={id}
42+
class="mt-f8 pr-f32 outline-gray3 hover:outline-teal focus-visible:outline-gray3 disabled:outline-gray3 disabled:hover:outline-gray3 disabled:focus-visible:outline-gray3 relative m-0 w-full max-w-[420px] cursor-pointer rounded-md bg-white p-2 align-middle outline focus-visible:outline active:outline disabled:cursor-not-allowed"
43+
disabled={isLoading || disabled}
44+
>
45+
<option class="text-gray3" value={null} disabled>{placeholder}</option>
46+
{#each options as option}
47+
<option value={option}>{formatter(option)}</option>
48+
{/each}
49+
</select>
50+
{#if isLoading}
51+
<LoadingIcon />
52+
{/if}
53+
<div class="select-arrow"></div>
54+
</div>
5355
</div>

src/components/features/BecomeProviderNextSteps/CreateProvider.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@
7070
<form id="create-provider" class="column gap-f16">
7171
<div>
7272
<label for="providerNameCB" class="label block">Provider name</label>
73-
<input id="providerNameCB" class="" required placeholder="Short name" maxlength={16} bind:value={newProviderName} />
73+
<input
74+
id="providerNameCB"
75+
type="text"
76+
required
77+
placeholder="Short name"
78+
maxlength={16}
79+
bind:value={newProviderName}
80+
/>
7481
</div>
7582
<div class="flex items-end justify-between">
7683
<Button

src/components/features/BecomeProviderNextSteps/RequestToBeProvider.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@
5959
<form class="column">
6060
<div>
6161
<label for="providerNameRtB" class="label mb-3.5 block">Provider name</label>
62-
<input id="providerNameRtB" required placeholder="Short name" maxlength={16} bind:value={newProviderName} />
62+
<input
63+
type="text"
64+
id="providerNameRtB"
65+
required
66+
placeholder="Short name"
67+
maxlength={16}
68+
bind:value={newProviderName}
69+
/>
6370
</div>
6471
<div class="flex w-[350px] justify-between">
6572
<button

src/components/features/LoginForm/LoginForm.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
let { onConnect = () => {}, onCancel = undefined }: Props = $props();
1515
1616
// Get the matching account object safely
17-
let newUser: Account | undefined = $state($providerAccountsStore.get($user.address));
17+
let newUser: Account | null = $state($providerAccountsStore.get($user.address) ?? null);
1818
1919
// Derive whether we can connect
2020
const canConnect = $derived.by(() => {
21-
console.log(newUser);
21+
console.log('Selected new user: ', newUser);
2222
return newUser?.network != null && $providerAccountsStore.size > 0 && newUser?.address !== '';
2323
});
2424

src/components/features/SelectNetworkAndAccount/SelectNetworkAndAccount.svelte

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import { createApi } from '$lib/polkadotApi';
1212
1313
interface Props {
14-
newUser: Account | undefined;
14+
newUser: Account | null;
1515
accounts: Accounts;
1616
accountSelectorTitle?: string;
1717
accountSelectorPlaceholder?: string;
@@ -30,8 +30,8 @@
3030
let thisWeb3Enable: typeof web3Enable;
3131
let thisWeb3Accounts: typeof web3Accounts;
3232
33-
let selectedAccount: Account | null = $state(null);
34-
let selectedNetwork: NetworkInfo | null = $state(null);
33+
let selectedAccount: Account | null = $state(newUser);
34+
let selectedNetwork: NetworkInfo | null = $state(newUser?.network ?? null);
3535
let customNetwork: string = $state('');
3636
let isCustomNetwork: boolean = $state(false);
3737
let isLoading: boolean = $state(false);
@@ -111,14 +111,30 @@
111111
}
112112
}
113113
114+
function findMatchingAccount(): Account | null {
115+
for (const account of accounts.values()) {
116+
if (JSON.stringify(account) === JSON.stringify(selectedAccount)) return account;
117+
}
118+
return null;
119+
}
120+
121+
$effect(() => {
122+
if (accounts && selectedAccount) {
123+
const match = findMatchingAccount();
124+
if (match && match !== selectedAccount) {
125+
selectedAccount = match;
126+
}
127+
}
128+
});
129+
114130
const resetState = () => {
115131
selectedNetwork = null;
116132
selectedAccount = null;
117133
isCustomNetwork = false;
118134
connectedToEndpoint = false;
119135
networkErrorMsg = '';
120136
controlKeysErrorMsg = '';
121-
newUser = undefined;
137+
newUser = null;
122138
};
123139
</script>
124140

0 commit comments

Comments
 (0)