diff --git a/package.json b/package.json index 1a0eee3..b8922fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "1.1.3", + "version": "1.1.4", "repository": "github:argentlabs/starknetkit", "private": false, "browser": { diff --git a/src/helpers/mapModalWallets.ts b/src/helpers/mapModalWallets.ts index 5b53336..9764b0d 100644 --- a/src/helpers/mapModalWallets.ts +++ b/src/helpers/mapModalWallets.ts @@ -25,7 +25,16 @@ export const mapModalWallets = ({ return [] } - return availableConnectors + const allInstalledWallets = installedWallets.map((w) => + availableConnectors.find((c) => c.id === w.id), + ) + + const orderedByInstall = [ + ...availableConnectors.filter((c) => allInstalledWallets.includes(c)), + ...availableConnectors.filter((c) => !allInstalledWallets.includes(c)), + ] + + const connectors = orderedByInstall .map((c) => { const installed = installedWallets.find((w) => w.id === c.id) if (installed) { @@ -74,4 +83,6 @@ export const mapModalWallets = ({ } }) .filter((c): c is ModalWallet => c !== null) + + return connectors } diff --git a/src/main.ts b/src/main.ts index c7218ae..c7807c4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,17 +48,22 @@ export const connect = async ({ const lastWalletId = localStorage.getItem("starknetLastConnectedWallet") if (modalMode === "neverAsk") { - const connector = availableConnectors.find((c) => c.id === lastWalletId) + try { + const connector = availableConnectors.find((c) => c.id === lastWalletId) - if (resultType === "wallet") { - await connector?.connect() - } + if (resultType === "wallet") { + await connector?.connect() + } - selectedConnector = connector ?? null + selectedConnector = connector ?? null - return { - connector, - wallet: connector?.wallet ?? null, + return { + connector, + wallet: connector?.wallet ?? null, + } + } catch (error) { + removeStarknetLastConnectedWallet() + throw new Error(error) } }