Skip to content

Commit 463e2a7

Browse files
authored
1.26.2-0.1.0: [enhancement] - SSR Support (#570)
* Return stubbed API if not running within a browser * Increment version * Increment version
1 parent 71eeb8f commit 463e2a7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
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.26.1-0.1.0",
3+
"version": "1.26.1-0.2.0",
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",

src/onboard.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,27 @@ import initializeModules from './modules'
3636
let onboard: any
3737

3838
function init(initialization: Initialization): API {
39+
if (typeof window === 'undefined') {
40+
console.warn(
41+
'Onboard.js must be run in a browser environment. If you are utilizing server side rendering you can ignore this warning.'
42+
)
43+
44+
const stubbedAPI = {
45+
walletSelect: () => Promise.resolve(false),
46+
walletCheck: () => Promise.resolve(false),
47+
walletReset: () => {},
48+
config: () => {},
49+
getState: () => get(state),
50+
accountSelect: () => Promise.resolve(false)
51+
}
52+
53+
return stubbedAPI
54+
}
55+
3956
if (onboard) {
40-
console.warn('onboard has already been initialized')
57+
console.warn(
58+
'Initializing Onboard and destroying previously initialized instance.'
59+
)
4160
onboard.$destroy()
4261
}
4362

0 commit comments

Comments
 (0)