From 5ece90ef4ba0c9db8891b880273056f535ae3822 Mon Sep 17 00:00:00 2001 From: Alois Date: Wed, 29 Jul 2026 02:37:18 +0200 Subject: [PATCH] (fix): retry when iota is unavailable --- packages/mtp/src/context.tsx | 18 ++++++++++++++---- pnpm-lock.yaml | 16 ++++++++-------- pnpm-workspace.yaml | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/mtp/src/context.tsx b/packages/mtp/src/context.tsx index 124ec6f..97bfeb3 100644 --- a/packages/mtp/src/context.tsx +++ b/packages/mtp/src/context.tsx @@ -435,15 +435,21 @@ export function Provider(props: { const stateSync = new Promise>( (resolve, reject) => { + let unsubscribeStateSync = () => {}; + let unsubscribeNoIota = () => {}; + const cleanupStateSync = () => { + clearTimeout(timeout); + unsubscribeStateSync(); + unsubscribeNoIota(); + }; const timeout = setTimeout(() => { - unsubscribe(); + cleanupStateSync(); reject(new Error("Initial state synchronization timed out")); }, 120_000); - const unsubscribe = activeClient.subscribe( + unsubscribeStateSync = activeClient.subscribe( "ClientStateSync", (message) => { - clearTimeout(timeout); - unsubscribe(); + cleanupStateSync(); try { resolve(validateResponse("ClientStateSync", message)); } catch (error) { @@ -451,6 +457,10 @@ export function Provider(props: { } }, ); + unsubscribeNoIota = activeClient.subscribe("ErrorNoIota", () => { + cleanupStateSync(); + reject(new Error("No Iota is currently connected")); + }); }, ); const [, finalResponse] = await Promise.all([ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ea016d..c058945 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: overrides: '@methanium/ui': https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz - mtp: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz + mtp: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz importers: @@ -16,8 +16,8 @@ importers: specifier: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz version: https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz(@date-fns/tz@1.5.0)(@types/react-dom@19.2.3(@types/react@19.2.17))(@types/react@19.2.17)(date-fns@4.4.0)(react-dom@19.2.7(react@19.2.7))(react-is@19.2.7)(react@19.2.7)(redux@5.0.1)(typescript@6.0.3) mtp: - specifier: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz - version: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz + specifier: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz + version: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz sonner: specifier: ^2.0.7 version: 2.0.7(react-dom@19.2.7(react@19.2.7))(react@19.2.7) @@ -700,8 +700,8 @@ importers: specifier: ^1.14.0 version: 1.23.0(react@19.2.7) mtp: - specifier: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz - version: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz + specifier: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz + version: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz react: specifier: ^19.2.0 version: 19.2.7 @@ -4006,8 +4006,8 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - mtp@https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz: - resolution: {integrity: sha512-WcXHd53aDM0zQfO8eaUnK5tpnRP73GlWjwAMMcstcVAIWrvyFGuINkCRNEkb2RsNk9h57UMhxElCZeBkFrVmCg==, tarball: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz} + mtp@https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz: + resolution: {integrity: sha512-WcXHd53aDM0zQfO8eaUnK5tpnRP73GlWjwAMMcstcVAIWrvyFGuINkCRNEkb2RsNk9h57UMhxElCZeBkFrVmCg==, tarball: https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz} version: 0.2.0 nanoid@3.3.15: @@ -8254,7 +8254,7 @@ snapshots: ms@2.1.3: {} - mtp@https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz: + mtp@https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz: dependencies: yaml: 2.9.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index d0aca66..d8793c9 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -7,4 +7,4 @@ allowBuilds: esbuild: true overrides: "@methanium/ui": "https://git.methanium.net/methanium/ui/releases/download/0.0.10/methanium-ui.tgz" - mtp: "https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-6f673ba/mtp-0.2.0.tgz" + mtp: "https://git.methanium.net/methanium/mtp/releases/download/0.2.0-dev-a692bed/mtp-0.2.0.tgz"