From 9f304638344745eb36d2fd2f33c08cb6bf832c55 Mon Sep 17 00:00:00 2001 From: Gerhard Steenkamp Date: Thu, 22 Feb 2024 14:53:46 +0200 Subject: [PATCH] reload tokens and nfts when switching safes --- src/plugins/oSnap/Create.vue | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/oSnap/Create.vue b/src/plugins/oSnap/Create.vue index 0b04cb28..2ad6aa17 100644 --- a/src/plugins/oSnap/Create.vue +++ b/src/plugins/oSnap/Create.vue @@ -199,8 +199,9 @@ const update = (newPluginData: OsnapPluginData) => { emit('update', { key: 'oSnap', form: newPluginData }); }; -watch(newPluginData, async () => { +async function loadBalancesAndCollectibles() { if (!newPluginData.value.safe?.safeAddress) return; + isLoading.value = true; tokens.value = await fetchBalances( newPluginData.value.safe.network, newPluginData.value.safe.safeAddress @@ -209,20 +210,26 @@ watch(newPluginData, async () => { newPluginData.value.safe.network, newPluginData.value.safe.safeAddress ); -}); + + isLoading.value = false; +} + +watch( + () => [ + newPluginData.value.safe?.safeAddress, + newPluginData.value.safe?.network + ], + async () => { + await loadBalancesAndCollectibles(); + update(newPluginData.value); + } +); onMounted(async () => { isLoading.value = true; safes.value = await createOsnapEnabledSafes(); newPluginData.value.safe = cloneDeep(safes.value[0]); - tokens.value = await fetchBalances( - newPluginData.value.safe.network, - newPluginData.value.safe.safeAddress - ); - collectables.value = await fetchCollectibles( - newPluginData.value.safe.network, - newPluginData.value.safe.safeAddress - ); + await loadBalancesAndCollectibles(); update(newPluginData.value); isLoading.value = false; });