Skip to content

Commit 3f32a22

Browse files
1.25.0-0.5.2: [refactor] Adds autoselect for gnosis wallet (#555)
* Adds autoselect for gnosis safe * Fix icon * Move logic out of wallet module
1 parent 0c9c037 commit 3f32a22

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.25.0-0.4.2",
3+
"version": "1.25.0-0.5.2",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
const gnosisWalletIcon = `
2-
<svg class="gnosis-logo" viewBox="0 0 2000 2000" enable-background="new 0 0 2000 2000" width="40" height="40">
3-
<g fill="#00a6c4">
4-
<path d="m1809.4 500l-73.6 73.6c58.5 92 76.9 207.4 36.8 317.7-66.9 187.3-274.2 286-463.2 219.1-26.8-10-51.8-21.7-73.6-36.8l-235.8 235.8-205.7-207.4c-95.3 63.5-217.4 81.9-332.8 41.8-194-70.2-294.3-282.6-224.1-474.9 10-30.1 25.1-56.9 41.8-81.9l-88.6-88.6-16.7 28.4c-92 150.5-142.1 324.4-142.1 503.3-1.7 533.4 433.1 969.9 966.5 969.9h1.7c533.4 0 966.6-433.1 968.2-966.6 0-177.3-48.5-351.2-140.5-503.3l-18.3-30.1"/>
5-
<path d="m388 695.7c-25.1 33.4-40.1 75.3-40.1 120.4 0 108.7 88.6 197.3 197.3 197.3 45.2 0 87-15.1 120.4-41.8l-277.6-275.9"/>
6-
<path d="m1356.2 954.8c31.8 21.7 68.6 33.4 110.4 33.4 108.7 0 197.3-88.6 197.3-197.3 0-40.1-11.7-78.6-33.4-110.4l-274.3 274.3"/>
7-
<path d="m1003.3 1162.2l-799.3-802.7 31.8-33.4c197.3-209 466.5-326.1 755.8-326.1h1.7c292.6 0 573.6 125.4 769.2 342.8l30.1 33.4-789.3 786m-668.8-802.7l668.9 670.6 660.5-657.2c-177.3-177.2-418.1-279.3-668.9-279.3h-1.7c-249.2 0-481.6 93.7-658.8 265.9"/>
8-
</g>
9-
</svg>`
2+
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 440 440">
3+
<path d="M220,9.82C103.92,9.82,9.82,103.92,9.82,220S103.92,430.18,220,430.18,430.18,336.08,430.18,220,336.08,9.82,220,9.82ZM373.83,231.47H276.3a59.41,59.41,0,1,1,.45-20.67h97.08a10.34,10.34,0,1,1,0,20.67Z"/>
4+
</svg>
5+
`
106

117
export default gnosisWalletIcon

src/modules/select/wallets/gnosis.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ import type { SafeInfo } from '@gnosis.pm/safe-apps-sdk'
33
import { CommonWalletOptions, Helpers, WalletModule } from '../../../interfaces'
44
import gnosisWalletIcon from '../wallet-icons/icon-gnosis'
55

6-
const getSafe = (sdk: SafeAppsSDK): Promise<SafeInfo | undefined> => {
7-
return Promise.race([
6+
const getSafe = (sdk: SafeAppsSDK): Promise<SafeInfo | undefined> =>
7+
Promise.race([
88
sdk.getSafeInfo(),
99
// Timeout need as this method hangs until it can find the safe info
1010
new Promise<undefined>(resolve => setTimeout(resolve, 200))
1111
])
12-
}
12+
13+
/**
14+
* Checks to see if we are are within a Safe App context. If we are it executes
15+
* the callback function which self-selects this wallet.
16+
* @param selectWallet - A callback function which can call the `walletSelect` method
17+
* with the Gnosis wallet name.
18+
*/
19+
export const checkGnosisSafeContext = async (selectWallet: () => void) =>
20+
!!(await getSafe(new (await import('@gnosis.pm/safe-apps-sdk')).default())) &&
21+
selectWallet()
1322

1423
function gnosis(options: CommonWalletOptions): WalletModule {
1524
const { preferred, label, iconSrc, svg, networkId } = options
@@ -18,7 +27,7 @@ function gnosis(options: CommonWalletOptions): WalletModule {
1827
const link = `https://${network}gnosis-safe.io/app`
1928

2029
return {
21-
name: label || 'Gnosis Safe Wallet',
30+
name: label || 'Gnosis Safe',
2231
iconSrc,
2332
svg: svg || gnosisWalletIcon,
2433
wallet: async ({ createModernProviderInterface }: Helpers) => {

src/onboard.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from './stores'
1818

1919
import { getDeviceInfo } from './utilities'
20-
import { validateInit, validateConfig } from './validation'
20+
import { validateInit, validateConfig, isWalletInit } from './validation'
2121

2222
import { version } from '../package.json'
2323

@@ -27,7 +27,8 @@ import {
2727
API,
2828
ConfigOptions,
2929
UserState,
30-
Wallet
30+
Wallet,
31+
WalletInitOptions
3132
} from './interfaces'
3233

3334
import initializeModules from './modules'
@@ -241,6 +242,24 @@ function init(initialization: Initialization): API {
241242
return get(state)
242243
}
243244

245+
// Find the Gnosis wallet from the wallet init options. Ignore it
246+
// if it is a wallet module. We need to get the wallet init first
247+
// in order to determine the wallet name: `walletName` or `label`.
248+
const {
249+
// If label is undefined set it to 'Gnosis Safe'
250+
label: gnosisWalletName = 'Gnosis Safe'
251+
} = initialization.walletSelect?.wallets?.find(
252+
wallet => isWalletInit(wallet) && wallet.walletName === 'gnosis'
253+
) as WalletInitOptions
254+
255+
if (gnosisWalletName) {
256+
import(
257+
'./modules/select/wallets/gnosis'
258+
).then(({ checkGnosisSafeContext }) =>
259+
checkGnosisSafeContext(() => walletSelect(gnosisWalletName))
260+
)
261+
}
262+
244263
return {
245264
walletSelect,
246265
walletCheck,

0 commit comments

Comments
 (0)