Skip to content

Commit

Permalink
fiexes + options connection
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertBodziony committed Feb 19, 2024
1 parent 8d5acbf commit f4cd58d
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 278 deletions.
2 changes: 1 addition & 1 deletion sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/wallet-selector-sui": "0.2.7",
"@nightlylabs/nightly-connect-polkadot": "0.0.14",
"@nightlylabs/wallet-selector-polkadot": "0.1.19",
"@nightlylabs/wallet-selector-polkadot": "0.2.0",
"@polkadot/extension-inject": "^0.46.5",
"@polkadot/api": "^10.10.1",
"@solana/web3.js": "^1.77.2",
Expand Down
7 changes: 4 additions & 3 deletions sdk/apps/modal-example/src/routes/aleph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ export default function Polkadot() {
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
},
network: 'AlephZero'
network: 'AlephZero',
persistent: true
},
true, // change this to false to test disabling eager connect
document.getElementById('modalAnchor')
{ initOnConnect: false, disableModal: false, disableEagerConnect: false }
)

adapter.canEagerConnect().then((canEagerConnect: boolean) => {
console.log('canEagerConnect', canEagerConnect)
setEager(canEagerConnect)
})
setAdapter(adapter)
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-base",
"version": "0.2.5",
"version": "0.3.0",
"description": "",
"type": "module",
"exports": {
Expand Down
28 changes: 13 additions & 15 deletions sdk/packages/selector-base/src/persistence.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getSessionIdLocalStorageKey } from '@nightlylabs/nightly-connect-base'
import { ILocalStorage, getStorage } from 'isomorphic-localstorage'
import { AccountWalletType } from './types'
import { ConnectionType } from './types'

let _localStorage: ILocalStorage | null = null

type WalletInfo = {
walletName: string
walletType: AccountWalletType
walletType: ConnectionType
}

export const getLocalStorage = () => {
Expand All @@ -18,34 +18,32 @@ export const getLocalStorage = () => {
}

// recent wallet from standard

export const NIGHTLY_CONNECT_RECENT_WALLET = 'NIGHTLY_CONNECT_RECENT_WALLET_'
export const persistRecentWalletForNetwork = (network: string, walletInfo: WalletInfo) => {
const storage = getLocalStorage()

storage.setItem(
'NIGHTLY_CONNECT_SELECTOR_RECENT_STANDARD_WALLET_' + network,
JSON.stringify(walletInfo)
)
storage.setItem(NIGHTLY_CONNECT_RECENT_WALLET + network, JSON.stringify(walletInfo))
}

export const getRecentWalletForNetwork = (network: string) => {
const storage = getLocalStorage()

const item = storage.getItem('NIGHTLY_CONNECT_SELECTOR_RECENT_STANDARD_WALLET_' + network)

return item
const item = storage.getItem(NIGHTLY_CONNECT_RECENT_WALLET + network)
if (!item) return null
try {
return JSON.parse(item) as WalletInfo
} catch (error) {
console.warn('Error parsing recent wallet from local storage', error)
return null
}
}

export const clearRecentWalletForNetwork = (network: string) => {
const storage = getLocalStorage()

storage.removeItem('NIGHTLY_CONNECT_SELECTOR_RECENT_STANDARD_WALLET_' + network)
storage.removeItem(NIGHTLY_CONNECT_RECENT_WALLET + network)
}

// clearing last nightly connect session id

export const clearSessionIdForNetwork = (network: string) => {
const storage = getLocalStorage()

storage.removeItem(getSessionIdLocalStorageKey(network))
}
12 changes: 9 additions & 3 deletions sdk/packages/selector-base/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export enum ConnectionType {
WalletStandard = 'WalletStandard'
}

export enum AccountWalletType {
Standard = 'Standard',
Relay = 'Relay'
export interface ConnectionOptions {
disableModal?: boolean // default: false
initOnConnect?: boolean // default: false
disableEagerConnect?: boolean // default: false
}
export const defaultConnectionOptions: ConnectionOptions = {
disableModal: false,
initOnConnect: false,
disableEagerConnect: false
}
4 changes: 2 additions & 2 deletions sdk/packages/selector-polkadot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-polkadot",
"version": "0.1.19",
"version": "0.2.0",
"description": "",
"type": "module",
"exports": {
Expand All @@ -25,7 +25,7 @@
"license": "ISC",
"dependencies": {
"@nightlylabs/nightly-connect-polkadot": "^0.0.15",
"@nightlylabs/wallet-selector-base": "^0.2.5",
"@nightlylabs/wallet-selector-base": "^0.3.0",
"@polkadot/extension-inject": "0.46.5",
"@polkadot/api": "10.10.1",
"@wallet-standard/core": "^1.0.3"
Expand Down
Loading

0 comments on commit f4cd58d

Please sign in to comment.