Skip to content

Commit 7521603

Browse files
committed
Add modules to onboard library and re-structure exports
1 parent 25fb542 commit 7521603

27 files changed

+3376
-148
lines changed

package-lock.json

Lines changed: 2763 additions & 144 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
"promise-cancelable": "^2.1.1",
3333
"regenerator-runtime": "^0.13.3",
3434
"svelte": "^3.0.0",
35-
"svelte-i18n": "^1.1.2-beta"
35+
"svelte-i18n": "^1.1.2-beta",
36+
"@portis/web3": "^2.0.0-beta.42",
37+
"@walletconnect/web3-provider": "^1.0.0-beta.36",
38+
"fortmatic": "^0.8.2"
3639
},
3740
"scripts": {
3841
"prepare": "rollup -c",

rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import babel from "rollup-plugin-babel"
44
import commonjs from "rollup-plugin-commonjs"
55
import globals from "rollup-plugin-node-globals"
66
import json from "rollup-plugin-json"
7+
import image from "rollup-plugin-img"
78
import builtins from "rollup-plugin-node-builtins"
89
import { terser } from "rollup-plugin-terser"
910

@@ -17,6 +18,7 @@ export default [
1718
esModule: false
1819
},
1920
plugins: [
21+
image(),
2022
json(),
2123
svelte(),
2224
resolve({
@@ -45,11 +47,15 @@ export default [
4547
"svelte/internal",
4648
"svelte/transition",
4749
"promise-cancelable",
48-
"regenerator-runtime/runtime"
50+
"regenerator-runtime/runtime",
51+
"@portis/web3",
52+
"@walletconnect/web3-provider",
53+
"fortmatic"
4954
],
5055
plugins: [
5156
svelte(),
5257
json(),
58+
image(),
5359
commonjs(),
5460
babel({ exclude: "node_modules/**" })
5561
],

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import "regenerator-runtime/runtime"
2-
32
import { get } from "svelte/store"
43

4+
import modules from "./modules"
5+
56
import Onboard from "./views/Onboard.svelte"
67

78
import {
@@ -117,4 +118,7 @@ function init(initialization) {
117118
return { walletSelect, walletReady, config, getState }
118119
}
119120

120-
export default init
121+
export default {
122+
init,
123+
modules
124+
}

src/modules/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import select from "./select"
2+
import ready from "./ready"
3+
4+
export default {
5+
select,
6+
ready
7+
}

src/modules/ready/balance.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function balance(minimum) {
2+
return ({ balance, BigNumber }) => {
3+
// if balance is less than minimum (compare < 1)
4+
if (BigNumber(balance).lte(BigNumber(minimum || 0))) {
5+
return {
6+
heading: "Get Some ETH",
7+
description: `Your current account has less than the necessary minimum balance of ${BigNumber(
8+
minimum
9+
)
10+
.div(BigNumber("1000000000000000000"))
11+
.toString()} ETH.`,
12+
eventCode: "nsfFail",
13+
icon: `
14+
<svg height="18" viewBox="0 0 429 695" width="18" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor" fill-rule="evenodd"><path d="m0 394 213 126.228516 214-126.228516-214 301z"/><path d="m0 353.962264 213.5-353.962264 213.5 353.962264-213.5 126.037736z"/></g></svg>
15+
`
16+
}
17+
}
18+
}
19+
}
20+
21+
export default balance

src/modules/ready/connect.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function connect() {
2+
return ({ wallet, address }) => {
3+
if (!address) {
4+
return {
5+
heading: "Login and Authorize Your Wallet",
6+
description: `This dapp requires access to your wallet, please login and authorize access to your ${wallet.name} accounts to continue.`,
7+
eventCode: "loginFail",
8+
action: wallet.connect,
9+
icon: `
10+
<svg height="14" viewBox="0 0 18 14" width="18" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path d="m10.29375 4.05351563c0-.04921875 0-.09140625 0-.13007813 0-1.0546875 0-2.109375 0-3.1640625 0-.43945312.3480469-.76992188.7804688-.7453125.2003906.01054688.3585937.10546875.4992187.24609375.5800781.58359375 1.1566406 1.16367188 1.7367187 1.74023438 1.4695313 1.46953125 2.9390625 2.93906249 4.4050782 4.40859375.1335937.13359375.2425781.27421875.2707031.46757812.0351562.20742188-.0246094.421875-.1652344.58007813-.0246094.028125-.0492187.05273437-.0738281.08085937-2.0601563 2.06367188-4.1203125 4.1238281-6.1804688 6.1875-.2109375.2109375-.4570312.3023438-.7453125.2179688-.2707031-.0808594-.4464843-.2707032-.5132812-.5484375-.0140625-.0738282-.0175781-.1441407-.0140625-.2179688 0-1.0335937 0-2.0707031 0-3.1042969 0-.0386719 0-.08085935 0-.13359372h-5.06953125c-.49570313 0-.80507813-.309375-.80507813-.80859375 0-1.42382813 0-2.84414063 0-4.26796875 0-.49570313.30585938-.8015625.8015625-.8015625h4.93593748z"/><path d="m5.69882812 13.978125h-4.01132812c-.928125 0-1.6875-.8753906-1.6875-1.9511719v-10.06171872c0-1.07578125.75585938-1.95117188 1.6875-1.95117188h4.01132812c.34101563 0 .61523438.31992188.61523438.71015625 0 .39023438-.27421875.71015625-.61523438.71015625h-4.01132812c-.253125 0-.45703125.23554688-.45703125.52734375v10.06171875c0 .2917969.20390625.5273437.45703125.5273437h4.01132812c.34101563 0 .61523438.3199219.61523438.7101563s-.27773438.7171875-.61523438.7171875z"/></g></svg>
11+
`
12+
}
13+
}
14+
}
15+
}
16+
17+
export default connect

src/modules/ready/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import connect from "./connect"
2+
import network from "./network"
3+
import balance from "./balance"
4+
5+
function init(options) {
6+
if (!options || typeof options !== "object") {
7+
throw new Error("initModules must be called with a valid option object")
8+
}
9+
10+
const { networkId, minimumBalance } = options
11+
12+
if (!networkId || typeof networkId !== "number") {
13+
throw new Error(
14+
"initModules must be called with a property of networkId that is of type Number"
15+
)
16+
}
17+
18+
return [connect(), network(networkId), balance(minimumBalance || "0")]
19+
}
20+
21+
export default {
22+
init,
23+
connect,
24+
network,
25+
balance
26+
}

src/modules/ready/network.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { networkName } from "../../utilities"
2+
3+
function network(correctNetwork) {
4+
if (!correctNetwork || typeof correctNetwork !== "number") {
5+
throw new Error(
6+
"Network module must be called with a property of value that is of type Number"
7+
)
8+
}
9+
10+
return ({ network, walletSelect, exit }) => {
11+
if (network != (correctNetwork || "1")) {
12+
return {
13+
heading: "You Must Change Networks",
14+
description: `Blockchain applications have different networks they can work on. Think of this like making sure you're on Netflix vs Hulu to watch your favorite show. We've detected that you need to switch your wallet's network from <b>${networkName(
15+
Number(network)
16+
)}</b> to <b>${networkName(
17+
Number(correctNetwork)
18+
)} network</b> for this Dapp. <br><br> <i>*Some wallets may not support changing networks. If you can not change networks in your wallet you may consider switching to a different wallet.</i>`,
19+
eventCode: "networkFail",
20+
button: {
21+
onclick: () => {
22+
exit()
23+
walletSelect()
24+
},
25+
text: "Switch Wallet"
26+
},
27+
icon: `
28+
<svg height="18" viewBox="0 0 18 18" width="18" xmlns="http://www.w3.org/2000/svg"><path d="m13.375 28c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.619875 0-1.125.504-1.125 1.125s.505125 1.125 1.125 1.125 1.125-.504 1.125-1.125-.505125-1.125-1.125-1.125zm0-6.75c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.619875 0-1.125.505125-1.125 1.125s.505125 1.125 1.125 1.125 1.125-.505125 1.125-1.125-.505125-1.125-1.125-1.125zm11.25 4.5c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.621 0-1.125.505125-1.125 1.125s.504 1.125 1.125 1.125 1.125-.505125 1.125-1.125-.504-1.125-1.125-1.125zm-11.25 10.117125h-.014625c-.615375-.007875-1.110375-.50175-1.110375-1.117125 0-1.35675.898875-3.375 3.375-3.375h6.75c.50625-.0135 1.125-.219375 1.125-1.125v-1.125c0-.621.502875-1.125 1.125-1.125s1.125.504 1.125 1.125v1.125c0 2.476125-2.01825 3.375-3.375 3.375h-6.75c-.905625 0-1.1115.61875-1.125 1.1385-.01575.610875-.51525 1.103625-1.125 1.103625zm0 1.132875c-.621 0-1.125-.502875-1.125-1.125v-6.75c0-.621.504-1.125 1.125-1.125s1.125.504 1.125 1.125v6.75c0 .622125-.504 1.125-1.125 1.125z" fill="currentColor" transform="translate(-10 -10)"/></svg>
29+
`
30+
}
31+
}
32+
}
33+
}
34+
35+
export default network

src/modules/select/content.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export const extensionInstallMessage = ({ currentWallet, selectedWallet }) => {
2+
if (currentWallet) {
3+
return `
4+
<p style="font-size: 0.889rem; font-family: Helvetica Neue; margin: 0.889rem 0;">
5+
We have detected that you already have
6+
<b>${currentWallet}</b>
7+
installed. If you would prefer to use
8+
<b>${selectedWallet}</b>
9+
instead, then click below to install.
10+
</p>
11+
<p style="font-size: 0.889rem; font-family: Helvetica Neue; margin: 0.889rem 0;">
12+
<b>Tip:</b>
13+
If you already have ${selectedWallet} installed, check your
14+
browser extension settings to make sure that you have it enabled
15+
and that you have disabled any other browser extension wallets.
16+
<span
17+
class="bn-onboard-clickable"
18+
style="color: #4a90e2;"
19+
onclick="window.location.reload();">
20+
Then refresh the page.
21+
</span>
22+
</p>
23+
`
24+
} else {
25+
return `
26+
<p style="font-size: 0.889rem; font-family: Helvetica Neue; margin: 0.889rem 0;">
27+
You'll need to install <b>${selectedWallet}</b> to continue. Install
28+
the extension and then
29+
<span
30+
class="bn-clickable"
31+
style="color: #4a90e2;"
32+
onclick={window.location.reload();}>
33+
refresh the page.
34+
</span>
35+
</p>
36+
`
37+
}
38+
}
39+
40+
export const mobileWalletInstallMessage = ({ selectedWallet }) => {
41+
return `
42+
<p style="font-size: 0.889rem;">
43+
You'll need to install <b>${selectedWallet}</b> to continue. Click below to install and then load this Dapp with <b>${selectedWallet}</b>.
44+
</p>
45+
`
46+
}

0 commit comments

Comments
 (0)