Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 38856f7

Browse files
committed
move nostr sync and sub check to post-setup
1 parent 0051b1c commit 38856f7

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

src/state/megaStore.tsx

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,37 +206,22 @@ export const Provider: ParentComponent = (props) => {
206206
state.should_zap_hodl
207207
);
208208

209-
// Sync our nostr profile info
210-
try {
211-
await mutinyWallet.sync_nostr();
212-
} catch (e) {
213-
console.error("error syncing nostr profile", e);
214-
}
215-
216209
// Give other components access to settings via the store
217210
setState({ settings: settings });
218211

219212
// If we get this far then we don't need the password anymore
220213
setState({ needs_password: false });
221214

222-
// Check if we're subscribed and update the timestamp
223-
try {
224-
const timestamp = await mutinyWallet?.check_subscribed();
225-
226-
// Check that timestamp is a number
227-
if (timestamp && !isNaN(Number(timestamp))) {
228-
setState({ subscription_timestamp: Number(timestamp) });
229-
}
230-
} catch (e) {
231-
console.error("error checking subscription", e);
232-
}
233-
234215
// Get balance
216+
console.time("get_balance");
235217
const balance = await mutinyWallet.get_balance();
218+
console.timeEnd("get_balance");
236219

237220
// Get federations
221+
console.time("list_federations");
238222
const federations =
239223
(await mutinyWallet.list_federations()) as MutinyFederationIdentity[];
224+
console.timeEnd("list_federations");
240225

241226
setState({
242227
mutiny_wallet: mutinyWallet,
@@ -255,6 +240,40 @@ export const Provider: ParentComponent = (props) => {
255240
}
256241
}
257242
},
243+
async postSetup(): Promise<void> {
244+
console.time("post_setup");
245+
if (!state.mutiny_wallet) {
246+
console.error(
247+
"Unable to run post setup, no mutiny_wallet is set"
248+
);
249+
setState({
250+
setup_error: new Error(
251+
"Attempted post-setup without a Mutiny Wallet initialized."
252+
)
253+
});
254+
return;
255+
}
256+
257+
// Sync our nostr profile info
258+
try {
259+
await state.mutiny_wallet.sync_nostr();
260+
} catch (e) {
261+
console.error("error syncing nostr profile", e);
262+
}
263+
264+
// Check if we're subscribed and update the timestamp
265+
try {
266+
const timestamp = await state.mutiny_wallet.check_subscribed();
267+
268+
// Check that timestamp is a number
269+
if (timestamp && !isNaN(Number(timestamp))) {
270+
setState({ subscription_timestamp: Number(timestamp) });
271+
}
272+
} catch (e) {
273+
console.error("error checking subscription", e);
274+
}
275+
console.timeEnd("post_setup");
276+
},
258277
setShouldCreateNewWallet(shouldCreateNewWallet: boolean) {
259278
setState({ shouldCreateNewWallet });
260279
},
@@ -509,6 +528,9 @@ export const Provider: ParentComponent = (props) => {
509528
console.warn("setup aborted");
510529
}
511530

531+
// After we have the mutiny wallet we still need to check for subscription and sync nostr
532+
await actions.postSetup();
533+
512534
console.log("node manager setup done");
513535

514536
// Setup an event listener to stop the mutiny wallet when the page unloads

0 commit comments

Comments
 (0)