Skip to content

Commit

Permalink
Bug: toggleTestnet was cyclically called (#401)
Browse files Browse the repository at this point in the history
* Remove the cyclic calls to toggleTestnet

* add @vueuse/core package

* apply duddino's review
  • Loading branch information
panleone authored Sep 30, 2024
1 parent 1cda0e4 commit ca90cb4
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
95 changes: 95 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@noble/hashes": "^1.1.5",
"@noble/secp256k1": "^1.7.0",
"@popperjs/core": "^2.11.6",
"@vueuse/core": "^11.1.0",
"base32": "^0.0.7",
"bech32": "^2.0.0",
"biginteger": "^1.0.3",
Expand Down
22 changes: 16 additions & 6 deletions scripts/composables/use_settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getEventEmitter } from '../event_bus.js';
import { ref, watch } from 'vue';
import { watchIgnorable } from '@vueuse/core';

import {
nDisplayDecimals,
fAdvancedMode,
Expand All @@ -16,8 +18,21 @@ export function useSettings() {
const debug = ref(rawDebug);
const isTestnet = ref(cChainParams.current === cChainParams.testnet);

const { ignoreUpdates: ignoreTestnetWatch } = watchIgnorable(
isTestnet,
async () => {
await toggleTestnet(isTestnet.value);
isTestnet.value = cChainParams.current === cChainParams.testnet;
}
);

getEventEmitter().on('toggle-network', () => {
isTestnet.value = cChainParams.current === cChainParams.testnet;
// At the moment the only emitter of this event is the function toggleTestnet
// Therefore we can safely ignore the watch.
// TODO: change as we finish the VUE rewriting
ignoreTestnetWatch(() => {
isTestnet.value = cChainParams.current === cChainParams.testnet;
});
});

getEventEmitter().on('toggle-debug', () => {
Expand All @@ -28,11 +43,6 @@ export function useSettings() {
toggleDebug(debug.value);
});

watch(isTestnet, async () => {
await toggleTestnet(isTestnet.value);
isTestnet.value = cChainParams.current === cChainParams.testnet;
});

getEventEmitter().on('advanced-mode', (fAdvancedMode) => {
advancedMode.value = fAdvancedMode;
});
Expand Down

0 comments on commit ca90cb4

Please sign in to comment.