Skip to content

Commit

Permalink
add aptos selected wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
LukassF committed May 15, 2024
1 parent 763c971 commit 48d3a50
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 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-polkadot": "0.0.15",
"@nightlylabs/nightly-connect-solana": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/wallet-selector-aptos": "0.1.1",
"@nightlylabs/wallet-selector-aptos": "0.1.2",
"@nightlylabs/wallet-selector-base": "^0.4.1",
"@nightlylabs/wallet-selector-polkadot": "0.2.6",
"@nightlylabs/wallet-selector-solana": "0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion sdk/packages/selector-aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-aptos",
"version": "0.1.1",
"version": "0.1.2",
"description": "",
"type": "module",
"exports": {
Expand Down
38 changes: 37 additions & 1 deletion sdk/packages/selector-aptos/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ConnectionType,
defaultConnectionOptions,
getRecentWalletForNetwork,
ISelectedWallet,
isMobileBrowser,
IWalletListItem,
logoBase64,
Expand Down Expand Up @@ -69,6 +70,8 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
private _detectionIntervalId: NodeJS.Timeout | undefined
private _maxNumberOfChecks = 10

private _selectedWallet: ISelectedWallet | undefined = undefined

get walletsList() {
return this._walletsList
}
Expand All @@ -80,6 +83,10 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
}
}

get selectedWallet() {
return this._selectedWallet
}

get sessionId() {
return this._app?.sessionId
}
Expand Down Expand Up @@ -180,6 +187,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
adapter.disconnect()
return
}
adapter.setSelectedWallet({ isRemote: true })
adapter._accountInfo = accountInfo
adapter._networkInfo = networkInfo
adapter.connected = true
Expand Down Expand Up @@ -261,6 +269,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
adapter.disconnect()
return
}
adapter.setSelectedWallet({ isRemote: true })
adapter._accountInfo = accountInfo
adapter._networkInfo = networkInfo
adapter.connected = true
Expand Down Expand Up @@ -350,6 +359,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
const { accountInfo, networkInfo } = deserializeConnectData(
this._app.base.clientMetadata
)
this.setSelectedWallet({ isRemote: true })
this._accountInfo = accountInfo
this._networkInfo = networkInfo
this.connected = true
Expand Down Expand Up @@ -405,7 +415,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
this.disconnect()
return
}

this.setSelectedWallet({ isRemote: true })
this._accountInfo = accountInfo
this._networkInfo = networkInfo
this.connected = true
Expand Down Expand Up @@ -529,6 +539,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
clearSessionIdForNetwork(APTOS_NETWORK)
// Refresh app session
this._app = await AppAptos.build(this._appInitData)
this._selectedWallet = undefined

// Add event listener for userConnected
this._app.on('userConnected', async (accountInfo, networkInfo) => {
Expand All @@ -545,6 +556,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
this.disconnect()
return
}
this.setSelectedWallet({ isRemote: true })
this._accountInfo = accountInfo
this._networkInfo = networkInfo
this.connected = true
Expand Down Expand Up @@ -703,6 +715,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
}

const wallet = this.walletsList.find((w) => w.name === walletName)
this.setSelectedWallet({ wallet })

if (!this._app) {
throw new Error('Wallet not ready')
Expand Down Expand Up @@ -769,6 +782,7 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
}

const wallet = this.walletsList.find((w) => w.name === walletName)
this.setSelectedWallet({ wallet })

if (typeof wallet?.standardWallet === 'undefined') {
if (this._modal) {
Expand Down Expand Up @@ -856,4 +870,26 @@ export class NightlyConnectAptosAdapter extends EventEmitter<AptosAdapterEvents>
)
}, 500)
}

setSelectedWallet = ({
wallet,
isRemote = false
}: {
wallet?: IWalletListItem
isRemote?: boolean
}) => {
if (!wallet) {
// Connecting to the nightly mobile app
wallet = this.walletsList.find((wallet) => wallet.name === 'Nightly')
}

if (wallet) {
this._selectedWallet = {
name: wallet.name,
image: wallet.image,
homepage: wallet.homepage,
walletType: isRemote ? 'mobile' : wallet.walletType
}
}
}
}
2 changes: 1 addition & 1 deletion sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48d3a50

Please sign in to comment.