From bb16693fb05308e9fda67f281567dcdadca189ac Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 16 Mar 2025 13:11:32 +0530 Subject: [PATCH] fix: address country in the component. --- .../account/payments/editAddressModal.svelte | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/routes/(console)/account/payments/editAddressModal.svelte b/src/routes/(console)/account/payments/editAddressModal.svelte index bea14ab0e..ef76e14cd 100644 --- a/src/routes/(console)/account/payments/editAddressModal.svelte +++ b/src/routes/(console)/account/payments/editAddressModal.svelte @@ -22,10 +22,6 @@ onMount(async () => { const countryList = await sdk.forProject.locale.listCountries(); - const locale = await sdk.forProject.locale.get(); - if (locale.countryCode) { - selectedAddress.country = locale.countryCode; - } options = countryList.countries.map((country) => { return { value: country.code, @@ -57,6 +53,21 @@ trackError(e, Submit.BillingAddressCreate); } } + + /** + * This component isn't a modal, so it mounts with its parent. + * On mount, `selectedAddress` can be `null`, so we set the country when the modal shows. + * + * And we only run this if the selected address has no country set, + * which really shouldn't happen, but here we are, playing it safe! + */ + $: if (show && !selectedAddress.country) { + sdk.forProject.locale.get().then((locale) => { + if (locale.countryCode) { + selectedAddress.country = locale.countryCode; + } + }); + }