@solana-mobile/wallet-adapter-mobile 2.1.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,119 +1,119 @@
1
- # `@solana-mobile/wallet-adapter-mobile`
2
-
3
- This is a plugin for use with [`@solana/wallet-adapter`](https://github.com/solana-labs/wallet-adapter). It enables apps to use a native wallet app on a mobile device to sign messages and transactions, and to send transactions if the wallet offers support for sending transactions.
4
-
5
- ## Usage
6
-
7
- Users of these libraries do not need to take any extra steps:
8
-
9
- * `@solana/wallet-adapter-react@">=0.15.21"`
10
-
11
- Those libraries automatically bundle the Mobile Wallet Adapter plugin, and enable it when running in a compatible mobile environment.
12
-
13
- ## Advanced usage
14
-
15
- Developers might wish to customize the behavior of this plugin for their app. Specifying the app's name and icon, deciding which address to select in the event the wallet authorizes the app to use more than one, specifying which network cluster to communicate with, and more are made possible by creating an instance of the mobile wallet adapter like this.
16
-
17
- ```typescript
18
- new SolanaMobileWalletAdapter({
19
- addressSelector: createDefaultAddressSelector(),
20
- appIdentity: {
21
- name: 'My app',
22
- uri: 'https://myapp.io',
23
- icon: 'relative/path/to/icon.png',
24
- },
25
- authorizationResultCache: createDefaultAuthorizationResultCache(),
26
- cluster: WalletAdapterNetwork.Devnet,
27
- onWalletNotFound: createDefaultWalletNotFoundHandler(),
28
- });
29
- ```
30
-
31
- Developers who use `@solana/wallet-adapter-react@">=0.15.21"` can supply this custom instance to `WalletProvider` which will use it to override the default one.
32
-
33
- ```typescript
34
- const wallets = useMemo(
35
- () => [
36
- new SolanaMobileWalletAdapter({
37
- addressSelector: createDefaultAddressSelector(),
38
- appIdentity: {
39
- name: 'My app',
40
- uri: 'https://myapp.io',
41
- icon: 'relative/path/to/icon.png',
42
- },
43
- authorizationResultCache: createDefaultAuthorizationResultCache(),
44
- cluster: WalletAdapterNetwork.Devnet,
45
- onWalletNotFound: createDefaultWalletNotFoundHandler(),
46
- }),
47
- ],
48
- [],
49
- );
50
-
51
- return (
52
- <ConnectionProvider endpoint={clusterApiUrl(WalletAdapterNetwork.Devnet)}>
53
- <WalletProvider wallets={wallets}>
54
- <MyApp />
55
- </WalletProvider>
56
- </ConnectionProvider>
57
- )
58
- ```
59
-
60
- For more information about how to use wallet adapter plugins, visit https://github.com/solana-labs/wallet-adapter
61
-
62
- ## Configuration
63
-
64
- ### App identity
65
-
66
- The `AppIdentity` config identifies your app to a native mobile wallet. When someone connects to a wallet for the first time, the wallet may present this information in the on-screen prompt where the ask if the visitor would like to authorize your app for use with their account.
67
-
68
- - `name` &ndash; The plain-language name of your application.
69
- - `uri` &ndash; The uri of your application. This uri may be required to participate in [dApp identity verification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md#dapp-identity-verification) as part of the mobile wallet adapter protocol specification.
70
- - `icon` &ndash; An icon file path, relative to the `uri`.
71
-
72
- ### Address selector
73
-
74
- The Mobile Wallet Adapter specification allows a wallet to authorize a dApp to use one or more addresses. dApps must supply code to select a single address for use in the adapter. That code must conform to the `AddressSelector` interface.
75
-
76
- ```typescript
77
- export interface AddressSelector {
78
- select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
79
- }
80
- ```
81
-
82
- Alternatively, you can use the included `createDefaultAddressSelector()` method to create a selector that always chooses the first address in the list.
83
-
84
- ### Authorization result cache
85
-
86
- The first time that someone authorizes a native wallet app for use with your application, you should cache that authorization for future use. You can supply your own implementation that conforms to the `AuthorizationResultCache` interface.
87
-
88
- ```typescript
89
- export interface AuthorizationResultCache {
90
- clear(): Promise<void>;
91
- get(): Promise<AuthorizationResult | undefined>;
92
- set(authorizationResult: AuthorizationResult): Promise<void>;
93
- }
94
- ```
95
-
96
- Alternatively, you can use the included `createDefaultAuthorizationResultCache()` method to create a cache that reads and writes the adapter's last-obtained `AuthorizationResult` to your browser's local storage, if available.
97
-
98
- ### Cluster
99
-
100
- Each authorization a dApp makes with a wallet is tied to a particular Solana cluster. If a dApp wants to change the cluster on which to transact, it must seek an authorization for that cluster.
101
-
102
- ### Wallet-not-found handler
103
-
104
- When you call `connect()` but no wallet responds within a reasonable amount of time, it is presumed that no compatible wallet is installed. You must supply an `onWalletNotFound` function to handle this case.
105
-
106
- Alternatively, you can use the included `createDefaultWalletNotFoundHandler()` method to create a function that opens the Solana Mobile ecosystem wallets webpage.
107
-
108
- ## Android Chrome Browser Issues
109
- Chrome on Android has a policy of blocking all navigation that does not come from explicit user gestures (click, tap, swipe, keypress). As a result, MWA Intent navigation to a wallet app will be blocked if it does not come from a user gesture.
110
-
111
- You will see an error like:
112
-
113
- ```
114
- Navigation is blocked: solana-wallet:/v1/associate...
115
- ```
116
-
117
- There isn't a way around this on the Android Chrome Browser, but you can write a mobile app if you need this behavior.
118
-
119
-
1
+ # `@solana-mobile/wallet-adapter-mobile`
2
+
3
+ This is a plugin for use with [`@solana/wallet-adapter`](https://github.com/solana-labs/wallet-adapter). It enables apps to use a native wallet app on a mobile device to sign messages and transactions, and to send transactions if the wallet offers support for sending transactions.
4
+
5
+ ## Usage
6
+
7
+ Users of these libraries do not need to take any extra steps:
8
+
9
+ * `@solana/wallet-adapter-react@">=0.15.21"`
10
+
11
+ Those libraries automatically bundle the Mobile Wallet Adapter plugin, and enable it when running in a compatible mobile environment.
12
+
13
+ ## Advanced usage
14
+
15
+ Developers might wish to customize the behavior of this plugin for their app. Specifying the app's name and icon, deciding which address to select in the event the wallet authorizes the app to use more than one, specifying which network cluster to communicate with, and more are made possible by creating an instance of the mobile wallet adapter like this.
16
+
17
+ ```typescript
18
+ new SolanaMobileWalletAdapter({
19
+ addressSelector: createDefaultAddressSelector(),
20
+ appIdentity: {
21
+ name: 'My app',
22
+ uri: 'https://myapp.io',
23
+ icon: 'relative/path/to/icon.png',
24
+ },
25
+ authorizationResultCache: createDefaultAuthorizationResultCache(),
26
+ cluster: WalletAdapterNetwork.Devnet,
27
+ onWalletNotFound: createDefaultWalletNotFoundHandler(),
28
+ });
29
+ ```
30
+
31
+ Developers who use `@solana/wallet-adapter-react@">=0.15.21"` can supply this custom instance to `WalletProvider` which will use it to override the default one.
32
+
33
+ ```typescript
34
+ const wallets = useMemo(
35
+ () => [
36
+ new SolanaMobileWalletAdapter({
37
+ addressSelector: createDefaultAddressSelector(),
38
+ appIdentity: {
39
+ name: 'My app',
40
+ uri: 'https://myapp.io',
41
+ icon: 'relative/path/to/icon.png',
42
+ },
43
+ authorizationResultCache: createDefaultAuthorizationResultCache(),
44
+ cluster: WalletAdapterNetwork.Devnet,
45
+ onWalletNotFound: createDefaultWalletNotFoundHandler(),
46
+ }),
47
+ ],
48
+ [],
49
+ );
50
+
51
+ return (
52
+ <ConnectionProvider endpoint={clusterApiUrl(WalletAdapterNetwork.Devnet)}>
53
+ <WalletProvider wallets={wallets}>
54
+ <MyApp />
55
+ </WalletProvider>
56
+ </ConnectionProvider>
57
+ )
58
+ ```
59
+
60
+ For more information about how to use wallet adapter plugins, visit https://github.com/solana-labs/wallet-adapter
61
+
62
+ ## Configuration
63
+
64
+ ### App identity
65
+
66
+ The `AppIdentity` config identifies your app to a native mobile wallet. When someone connects to a wallet for the first time, the wallet may present this information in the on-screen prompt where the ask if the visitor would like to authorize your app for use with their account.
67
+
68
+ - `name` &ndash; The plain-language name of your application.
69
+ - `uri` &ndash; The uri of your application. This uri may be required to participate in [dApp identity verification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md#dapp-identity-verification) as part of the mobile wallet adapter protocol specification.
70
+ - `icon` &ndash; An icon file path, relative to the `uri`.
71
+
72
+ ### Address selector
73
+
74
+ The Mobile Wallet Adapter specification allows a wallet to authorize a dApp to use one or more addresses. dApps must supply code to select a single address for use in the adapter. That code must conform to the `AddressSelector` interface.
75
+
76
+ ```typescript
77
+ export interface AddressSelector {
78
+ select(addresses: Base64EncodedAddress[]): Promise<Base64EncodedAddress>;
79
+ }
80
+ ```
81
+
82
+ Alternatively, you can use the included `createDefaultAddressSelector()` method to create a selector that always chooses the first address in the list.
83
+
84
+ ### Authorization result cache
85
+
86
+ The first time that someone authorizes a native wallet app for use with your application, you should cache that authorization for future use. You can supply your own implementation that conforms to the `AuthorizationResultCache` interface.
87
+
88
+ ```typescript
89
+ export interface AuthorizationResultCache {
90
+ clear(): Promise<void>;
91
+ get(): Promise<AuthorizationResult | undefined>;
92
+ set(authorizationResult: AuthorizationResult): Promise<void>;
93
+ }
94
+ ```
95
+
96
+ Alternatively, you can use the included `createDefaultAuthorizationResultCache()` method to create a cache that reads and writes the adapter's last-obtained `AuthorizationResult` to your browser's local storage, if available.
97
+
98
+ ### Cluster
99
+
100
+ Each authorization a dApp makes with a wallet is tied to a particular Solana cluster. If a dApp wants to change the cluster on which to transact, it must seek an authorization for that cluster.
101
+
102
+ ### Wallet-not-found handler
103
+
104
+ When you call `connect()` but no wallet responds within a reasonable amount of time, it is presumed that no compatible wallet is installed. You must supply an `onWalletNotFound` function to handle this case.
105
+
106
+ Alternatively, you can use the included `createDefaultWalletNotFoundHandler()` method to create a function that opens the Solana Mobile ecosystem wallets webpage.
107
+
108
+ ## Android Chrome Browser Issues
109
+ Chrome on Android has a policy of blocking all navigation that does not come from explicit user gestures (click, tap, swipe, keypress). As a result, MWA Intent navigation to a wallet app will be blocked if it does not come from a user gesture.
110
+
111
+ You will see an error like:
112
+
113
+ ```
114
+ Navigation is blocked: solana-wallet:/v1/associate...
115
+ ```
116
+
117
+ There isn't a way around this on the Android Chrome Browser, but you can write a mobile app if you need this behavior.
118
+
119
+