Skip to content

Commit

Permalink
Merge pull request #77 from argentlabs/fix/wallets-ordering-and-recon…
Browse files Browse the repository at this point in the history
…nect

Fix/wallets ordering and reconnect
  • Loading branch information
bluecco authored Feb 13, 2024
2 parents cdcbf7a + 191eea0 commit 1e2d1fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/helpers/mapModalWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModalWallet | null>((c) => {
const installed = installedWallets.find((w) => w.id === c.id)
if (installed) {
Expand Down Expand Up @@ -74,4 +83,6 @@ export const mapModalWallets = ({
}
})
.filter((c): c is ModalWallet => c !== null)

return connectors
}
21 changes: 13 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 1e2d1fb

Please sign in to comment.