Skip to content

Commit 3bf582b

Browse files
committed
improve view caching logic
1 parent 5397cdf commit 3bf582b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/pages/WalletPage.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import utxoManagement from 'src/components/settings/utxoManagement.vue'
1111
import sweepPrivateKey from 'src/components/settings/sweepPrivateKey.vue'
1212
import hdAddressesView from 'src/components/settings/hdAddresses.vue'
13-
import { ref, computed, watch } from 'vue'
13+
import { defineComponent, ref, computed, watch } from 'vue'
1414
import { storeToRefs } from 'pinia'
1515
import { DefaultProvider } from 'mainnet-js'
1616
import { waitForInitialized } from 'src/utils/utils'
@@ -37,16 +37,18 @@
3737
3838
DefaultProvider.servers.chipnet = ["wss://chipnet.bch.ninja:50004"];
3939
40-
// The currentView and its viewSpecificProps are computed based on 'store.displayView'
41-
// These view & prop refs are passed to a dynamic component rendering the current view
42-
// This way views can be wrapped with KeepAlive to preserve its state across view changes
43-
// Excluding the settingsMenu bc we want to rerender it when navigating to it
40+
// The currentView and its viewSpecificProps are computed based on 'store.displayView'
41+
// and passed to a dynamic component wrapped in KeepAlive to preserve state.
42+
// KeepAlive stays mounted permanently so the views are cached regardless of navigation.
43+
// Settings View re-renders on navigation, a placeholder component used for the KeepAlive
44+
const emptyView = defineComponent({ render: () => null })
4445
const currentView = computed(() => {
4546
switch (store.displayView) {
4647
case 1: return bchWalletView;
4748
case 2: return myTokensView;
4849
case 3: return historyView;
4950
case 4: return connectDappView;
51+
case 5: return emptyView;
5052
case 6: return createTokensView;
5153
case 7: return utxoManagement;
5254
case 8: return sweepPrivateKey;
@@ -196,7 +198,7 @@
196198
</nav>
197199
</header>
198200
<main style="margin: 20px auto; max-width: 78rem;">
199-
<KeepAlive v-if="store.displayView != 5">
201+
<KeepAlive>
200202
<component :is="currentView" v-bind="viewSpecificProps"/>
201203
</KeepAlive>
202204
<settingsMenu v-if="store.displayView == 5" />

0 commit comments

Comments
 (0)