Skip to content

Commit 43c7d05

Browse files
authored
Feature: Add support for injected wallet download URL for unavailable injected wallets (#1754)
* Add ability to pass injected wallet url and display URL if wallet is unavailable and url is available * Cleanup demo * Add other wallet urls for most popular * Add OKX wallet to downloads list, add slide transition for connect modal warning * Add local flag to other transitions to keep the transition scope to that code block destroy/creation
1 parent 910ccc3 commit 43c7d05

File tree

21 files changed

+244
-152
lines changed

21 files changed

+244
-152
lines changed

docs/src/routes/docs/[...4]wallets/[...9]injected/+page.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ const equal = {
153153
provider: window.ethereum
154154
}),
155155
// A list of platforms that this wallet supports
156-
platforms: ['desktop']
156+
platforms: ['desktop'],
157+
/**
158+
* A Url to link users to a download page for the wallet
159+
* to be shown if not installed or available on the browser
160+
*/
161+
externalUrl: 'http://www.CoolEqualWalletDownload.com'
157162
}
158163

159164
const injected = injectedModule({
@@ -172,17 +177,22 @@ You may want to display injected wallets that are not currently available to the
172177

173178
```javascript
174179
const injected = injectedModule({
175-
displayUnavailable: true
180+
// display all unavailable injected wallets
181+
displayUnavailable: true,
182+
||
183+
// display specific unavailable wallets
184+
displayUnavailable: [ProviderLabel.MetaMask, ProviderLabel.Trust]
176185
})
177186
```
178187

179-
This will render every injected wallet as regardless of whether it has been detected in the window, happy days.
180-
Then the issue of the order of wallets displayed becomes apparent when you have 21 injected wallets at the top of the wallets list. To solve this, all injected wallets are sorted alphabetically by default and there is an additional `sort` parameter which receives the final list of wallets and then returns the list to be rendered. This allows for example setting MetaMask and Coinbase first and then just the rest alphabetically:
188+
This can be set to an array top specify which unavailable injected wallets to show or set to true to display all unavailable injected wallets regardless of whether it has been detected in the window, happy days.
189+
Then the issue of the order of wallets displayed becomes apparent when you have 21 injected wallets at the top of the wallets list. To solve this, all injected wallets are sorted **alphabetically** by default and there is an additional `sort` parameter which receives the final list of wallets and then returns the list to be rendered. This allows for example setting MetaMask and Coinbase first and then just the rest alphabetically:
181190

182191
```javascript
183192
const injected = injectedModule({
184-
// display all wallets even if they are unavailable
185-
displayUnavailable: true,
193+
// display specific injected wallets even if they are unavailable
194+
// can also be set to `true` to display all unavailable injected wallets
195+
displayUnavailable: [ProviderLabel.MetaMask, ProviderLabel.Trust],
186196
// do a manual sort of injected wallets so that MetaMask and Coinbase are ordered first
187197
sort: (wallets) => {
188198
const metaMask = wallets.find(({ label }) => label === ProviderLabel.MetaMask)
@@ -203,11 +213,12 @@ const injected = injectedModule({
203213
})
204214
```
205215

206-
You may want to display all wallets, but filter out specific wallets based on their availability. For example I may want to display all unavailable wallets except when Binance and Bitski wallet is unavailable, then don't show them, but if they are available, then do show them. To do this, the filters value has been extended to have a new value: `'unavailable'`, as in; remove this wallet if it is unavailable, even though `displayUnavailable` wallets is set:
216+
You may want to display all unavailable injected wallets, but filter out specific wallets based on their availability. For example I may want to display all unavailable wallets except when Binance and Bitski wallet is unavailable, then don't show them, but if they are available, then do show them. To do this, the filters value has been extended to have a new value: `'unavailable'`, as in; remove this wallet if it is unavailable, even though `displayUnavailable` wallets is set:
207217

208218
```javascript
209219
const injected = injectedModule({
210-
// display all wallets even if they are unavailable
220+
// display specific injected wallets even if they are unavailable
221+
// can also be set to `true` to display all unavailable injected wallets
211222
displayUnavailable: true,
212223
// but only show Binance and Bitski wallet if they are available
213224
filter: {
@@ -234,15 +245,16 @@ const injected = injectedModule({
234245
})
235246
```
236247

237-
If a wallet is selected, but is not available the default error message is: `Please install or enable ${walletName} to continue`. You may want to customise that message, so there is the `walletUnavailableMessage` parameter which is a function that takes the wallet object that is unavailable and returns a string which is the message to display:
248+
If a wallet is selected, but is not available the default error message is: `Oops ${wallet.label} is unavailable! Please <a href="${wallet.externalUrl}" target="_blank">install</a>` if a download link is available for that wallet. If there isn't a download link for that wallet the default is: `Please install or enable ${walletName} to continue`. You may want to customize that message, so there is the `walletUnavailableMessage` parameter which is a function that takes the wallet object that is unavailable and returns a string which is the message to display:
238249

239250
```javascript
240251
const injected = injectedModule({
241252
custom: [
242253
// include custom (not natively supported) injected wallet modules here
243254
],
244-
// display all wallets even if they are unavailable
245-
displayUnavailable: true,
255+
// display specific injected wallets even if they are unavailable
256+
// can also be set to `true` to display all unavailable injected wallets
257+
displayUnavailable: [ProviderLabel.MetaMask, ProviderLabel.Trust],
246258
// but only show Binance and Bitski wallet if they are available
247259
filter: {
248260
[ProviderLabel.Binance]: 'unavailable',
@@ -265,7 +277,10 @@ const injected = injectedModule({
265277
.filter((wallet) => wallet)
266278
)
267279
},
268-
walletUnavailableMessage: (wallet) => `Oops ${wallet.label} is unavailable!`
280+
walletUnavailableMessage: (wallet) =>
281+
wallet.externalUrl
282+
? `Oops ${wallet.label} is unavailable! Please <a href="${wallet.externalUrl}" target="_blank">install</a>`
283+
: `Oops ${wallet.label} is unavailable!`
269284
})
270285
```
271286

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.20.0",
3+
"version": "2.20.1-alpha.1",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/core/src/views/account-center/AcctCenterTriggerLarge.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
</style>
144144

145145
<div
146-
in:fade={{ duration: 250 }}
146+
in:fade|local={{ duration: 250 }}
147147
out:fade={{ duration: 100 }}
148148
class="ac-trigger"
149149
on:click|stopPropagation={toggle}
@@ -187,7 +187,7 @@
187187
: shortenedFirstAddress}
188188
</div>
189189
{#if firstAddressBalance}
190-
<div in:fade class="balance">
190+
<div in:fade|local class="balance">
191191
{firstAddressBalance.length > 7
192192
? firstAddressBalance.slice(0, 7)
193193
: firstAddressBalance}

packages/core/src/views/account-center/SecondaryTokenTable.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<div class="icon-name-container">
7373
{#if token.icon}
7474
{#await token.icon then iconLoaded}
75-
<div in:fade class="icon">
75+
<div in:fade|local class="icon">
7676
{#if isSVG(iconLoaded)}
7777
<!-- render svg string -->
7878
{@html iconLoaded}

packages/core/src/views/account-center/WalletRow.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237

238238
<!-- BALANCE -->
239239
{#if balance}
240-
<div in:fade class="balance">
240+
<div in:fade|local class="balance">
241241
{formatBalance(balance)}
242242
</div>
243243
{/if}
@@ -256,7 +256,7 @@
256256
</div>
257257

258258
{#if showMenu === address}
259-
<ul in:fade class="menu absolute">
259+
<ul in:fade|local class="menu absolute">
260260
<li
261261
on:click|stopPropagation={() => {
262262
showMenu = ''

packages/core/src/views/connect/WalletButton.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
class="wallet-button-styling"
110110
class:connected
111111
{disabled}
112-
in:fade
112+
in:fade|local
113113
on:click={onClick}
114114
>
115115
<div class="wallet-button-container-inner">

packages/core/src/views/notify/Index.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
<li
134134
animate:flip={{ duration: 500 }}
135135
on:click|stopPropagation
136-
in:fly={{ duration: 1200, delay: 300, x, y, easing: elasticOut }}
136+
in:fly|local={{ duration: 1200, delay: 300, x, y, easing: elasticOut }}
137137
out:fade={{ duration: 300, easing: cubicOut }}
138138
class={`bn-notify-li-${position} ${
139139
position.includes('top')

packages/core/src/views/shared/WalletAppBadge.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
{#await icon}
204204
<div class="placeholder-icon" />
205205
{:then iconLoaded}
206-
<div in:fade class="icon flex justify-center items-center">
206+
<div in:fade|local class="icon flex justify-center items-center">
207207
{#if isSVG(iconLoaded)}
208208
<!-- render svg string -->
209209
{@html iconLoaded}

packages/core/src/views/shared/Warning.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
2-
import { fade } from 'svelte/transition'
2+
import { slide } from 'svelte/transition'
33
import infoIcon from '../../icons/info.js'
4+
import { bounceIn, circIn, quadIn } from 'svelte/easing'
45
</script>
56

67
<style>
@@ -25,7 +26,7 @@
2526
2627
</style>
2728

28-
<div in:fade class="container flex justify-between">
29+
<div in:slide|local="{{delay: 50, duration: 500}}" class="container flex justify-between">
2930
<div>
3031
<slot />
3132
</div>

packages/demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"dependencies": {
2727
"@web3-onboard/cede-store": "^2.0.2",
2828
"@web3-onboard/coinbase": "^2.2.3",
29-
"@web3-onboard/core": "^2.20.0",
29+
"@web3-onboard/core": "^2.20.1-alpha.1",
3030
"@web3-onboard/dcent": "^2.2.7",
3131
"@web3-onboard/enkrypt": "^2.0.3",
3232
"@web3-onboard/fortmatic": "^2.0.18",
@@ -35,7 +35,7 @@
3535
"@web3-onboard/gas": "^2.1.7",
3636
"@web3-onboard/gnosis": "^2.1.9",
3737
"@web3-onboard/infinity-wallet": "^2.0.3",
38-
"@web3-onboard/injected-wallets": "^2.9.0",
38+
"@web3-onboard/injected-wallets": "^2.10.0-alpha.1",
3939
"@web3-onboard/keepkey": "^2.3.7",
4040
"@web3-onboard/keystone": "^2.3.7",
4141
"@web3-onboard/ledger": "^2.4.5",

0 commit comments

Comments
 (0)