Skip to content

Commit

Permalink
Merge branch 'develop' into BLO-1888-Adapt-StarknetKit-to-new-JSON-RP…
Browse files Browse the repository at this point in the history
…C-Wallet-API

* develop:
  chore(release): 1.1.4 [skip ci]
  fix: show installed wallets before not installed wallets
  fix: remove last wallet when user rejects with neverAsk mode
  • Loading branch information
bluecco committed Feb 29, 2024
2 parents bc235b0 + b5854c9 commit b205975
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetkit",
"version": "1.1.3",
"version": "1.1.4",
"repository": "github:argentlabs/starknetkit",
"private": false,
"browser": {
Expand Down
13 changes: 12 additions & 1 deletion src/helpers/mapModalWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 @@ -81,4 +90,6 @@ export const mapModalWallets = ({
}
})
.filter((c): c is ModalWallet => c !== null)

return connectors
}
25 changes: 15 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ export const connect = async ({

const lastWalletId = localStorage.getItem("starknetLastConnectedWallet")
if (modalMode === "neverAsk") {
const connector =
availableConnectors.find((c) => c.id === lastWalletId) ?? null
let connectorData: ConnectorData | null = null
try {
const connector =
availableConnectors.find((c) => c.id === lastWalletId) ?? null
let connectorData: ConnectorData | null = null

if (connector && resultType === "wallet") {
connectorData = await connector.connect()
}
if (connector && resultType === "wallet") {
connectorData = await connector.connect()
}

return {
connector,
wallet: connector?.wallet ?? null,
connectorData,
return {
connector,
wallet: connector?.wallet ?? null,
connectorData,
}
} catch (error) {
removeStarknetLastConnectedWallet()
throw new Error(error as any)
}
}

Expand Down

0 comments on commit b205975

Please sign in to comment.