Skip to content

Commit f596a17

Browse files
Support askForEmail (#308)
1 parent 114d881 commit f596a17

6 files changed

Lines changed: 30 additions & 14 deletions

File tree

packages/0xsequence/tests/browser/mock-wallet/mock-wallet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const main = async () => {
8383
)
8484

8585
// the json-rpc signer via the wallet
86-
const walletRequestHandler = new WalletRequestHandler(undefined, null, networks)
86+
const walletRequestHandler = new WalletRequestHandler(undefined, null, null, networks)
8787

8888
// fake/force an async wallet initialization for the wallet-request handler. This is the behaviour
8989
// of the wallet-webapp, so lets ensure the mock wallet does the same thing too.

packages/0xsequence/tests/browser/mux-transport/mux.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const tests = async () => {
9090
)
9191

9292
// the rpc signer via the wallet
93-
const walletRequestHandler = new WalletRequestHandler(saccount, null, networks)
93+
const walletRequestHandler = new WalletRequestHandler(saccount, null, null, networks)
9494

9595
// register wallet message handler, in this case using the ProxyMessage transport.
9696
const proxyHandler = new ProxyMessageHandler(walletRequestHandler, ch.wallet)

packages/0xsequence/tests/browser/proxy-transport/channel.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Web3Provider, ProxyMessageProvider, WalletSession, WalletRequestHandler, ProxyMessageChannel, ProxyMessageHandler, prefixEIP191Message } from '@0xsequence/provider'
1+
import {
2+
Web3Provider,
3+
ProxyMessageProvider,
4+
WalletSession,
5+
WalletRequestHandler,
6+
ProxyMessageChannel,
7+
ProxyMessageHandler,
8+
prefixEIP191Message
9+
} from '@0xsequence/provider'
210
import { ethers, Wallet as EOAWallet } from 'ethers'
311
import { JsonRpcProvider } from '@ethersproject/providers'
412
import { test, assert } from '../../utils/assert'
@@ -12,7 +20,6 @@ import { testAccounts, getEOAWallet } from '../testutils'
1220
configureLogger({ logLevel: 'DEBUG', silence: false })
1321

1422
export const tests = async () => {
15-
1623
// ProxyMessageChannel object is to be instantiated by the app coordinating
1724
// the channel, ie. such as the mobile application itself.
1825
//
@@ -22,7 +29,7 @@ export const tests = async () => {
2229
// Sending messages to the wallet port will go through channel and get received by the app.
2330
const ch = new ProxyMessageChannel()
2431

25-
ch.app.on('open', (openInfo) => {
32+
ch.app.on('open', openInfo => {
2633
console.log('app, wallet opened.', openInfo)
2734
})
2835
ch.app.on('close', () => {
@@ -68,13 +75,13 @@ export const tests = async () => {
6875
rpcUrl: rpcProvider.connection.url,
6976
provider: rpcProvider,
7077
relayer: relayer,
71-
isDefaultChain: true,
78+
isDefaultChain: true
7279
// isAuthChain: true
7380
}
7481
]
7582

7683
// the rpc signer via the wallet
77-
const walletRequestHandler = new WalletRequestHandler(undefined, null, networks)
84+
const walletRequestHandler = new WalletRequestHandler(undefined, null, null, networks)
7885

7986
// fake/force an async wallet initialization for the wallet-request handler. This is the behaviour
8087
// of the wallet-webapp, so lets ensure the mock wallet does the same thing too.
@@ -86,7 +93,6 @@ export const tests = async () => {
8693
const proxyHandler = new ProxyMessageHandler(walletRequestHandler, ch.wallet)
8794
proxyHandler.register()
8895

89-
9096
//
9197
// App Provider
9298
//
@@ -137,7 +143,6 @@ export const tests = async () => {
137143
'signature match'
138144
)
139145

140-
141146
const chainId = await signer.getChainId()
142147

143148
//
@@ -152,7 +157,6 @@ export const tests = async () => {
152157
// in order to recover the config properly, the subDigest + sig is required.
153158
const subDigest = packMessageData(address, chainId, messageDigest)
154159

155-
156160
//
157161
// Recover config / address
158162
//
@@ -166,5 +170,4 @@ export const tests = async () => {
166170
})
167171

168172
walletProvider.closeWallet()
169-
170173
}

packages/provider/src/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function isSequenceProvider(provider: any): provider is Web3Provider {
9494

9595
export class LocalWeb3Provider extends Web3Provider {
9696
constructor(signer: Signer, networks?: NetworkConfig[]) {
97-
const walletRequestHandler = new WalletRequestHandler(signer, null, networks || [])
97+
const walletRequestHandler = new WalletRequestHandler(signer, null, null, networks || [])
9898
super(walletRequestHandler)
9999
}
100100
}

packages/provider/src/transports/wallet-request-handler.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
4444
private signerReadyCallbacks: Array<() => void> = []
4545

4646
private prompter: WalletUserPrompter | null
47+
private auxDataProvider: AuxDataProvider | null
4748
private mainnetNetworks: NetworkConfig[]
4849
private testnetNetworks: NetworkConfig[]
4950

@@ -57,11 +58,13 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
5758
constructor(
5859
signer: Signer | null | undefined,
5960
prompter: WalletUserPrompter | null,
61+
auxDataProvider: AuxDataProvider | null,
6062
mainnetNetworks: NetworkConfig[],
6163
testnetNetworks: NetworkConfig[] = []
6264
) {
6365
this.signer = signer
6466
this.prompter = prompter
67+
this.auxDataProvider = auxDataProvider
6568
this.mainnetNetworks = mainnetNetworks
6669
this.testnetNetworks = testnetNetworks
6770
}
@@ -152,6 +155,13 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
152155
chainId: ethers.utils.hexlify(await this.getChainId())
153156
}
154157

158+
if (options && options.askForEmail) {
159+
const email = await this.auxDataProvider?.get('email')
160+
if (email) {
161+
connectDetails.email = email
162+
}
163+
}
164+
155165
if (options && options.authorize) {
156166
// Perform ethauth eip712 request and construct the ConnectDetails response
157167
// including the auth proof
@@ -802,6 +812,10 @@ export interface WalletUserPrompter {
802812
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>
803813
}
804814

815+
export interface AuxDataProvider {
816+
get(key: string): Promise<any>
817+
}
818+
805819
const permittedJsonRpcMethods = [
806820
'net_version',
807821
'eth_chainId',

packages/provider/src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ export interface ConnectOptions {
156156
/** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
157157
authorize?: boolean
158158

159-
/** *Currently not used* askForEmail will prompt to give permission to the dapp to access email address */
160-
// TODO: this feature is currently not used as the wallet does not report emails yet
159+
/** askForEmail will prompt to give permission to the dapp to access email address */
161160
askForEmail?: boolean
162161

163162
/** refresh flag will force a full re-connect (ie. disconnect then connect again) */

0 commit comments

Comments
 (0)