Skip to content

Commit ec07d91

Browse files
committed
Implement Authereum module and add loading state to connect module
1 parent 211d0b4 commit ec07d91

File tree

12 files changed

+637
-31
lines changed

12 files changed

+637
-31
lines changed

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,35 @@
99
],
1010
"types": "./types.d.ts",
1111
"devDependencies": {
12+
"@babel/core": "^7.5.5",
13+
"@babel/preset-env": "^7.5.5",
14+
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
15+
"babel-eslint": "^7.1.1",
16+
"babel-plugin-external-helpers": "^6.18.0",
1217
"rollup": "^1.12.0",
18+
"rollup-plugin-babel": "^4.3.3",
1319
"rollup-plugin-commonjs": "^10.0.0",
1420
"rollup-plugin-img": "^1.1.0",
1521
"rollup-plugin-json": "^4.0.0",
1622
"rollup-plugin-livereload": "^1.0.0",
17-
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
18-
"rollup-plugin-babel": "^4.3.3",
23+
"rollup-plugin-node-globals": "^1.4.0",
1924
"rollup-plugin-node-resolve": "^5.2.0",
2025
"rollup-plugin-svelte": "^5.0.3",
21-
"rollup-plugin-terser": "^4.0.4",
22-
"rollup-plugin-node-globals": "^1.4.0",
23-
"@babel/core": "^7.5.5",
24-
"@babel/preset-env": "^7.5.5",
25-
"babel-eslint": "^7.1.1",
26-
"babel-plugin-external-helpers": "^6.18.0"
26+
"rollup-plugin-terser": "^4.0.4"
2727
},
2828
"dependencies": {
29+
"@portis/web3": "^2.0.0-beta.42",
30+
"@walletconnect/web3-provider": "^1.0.0-beta.36",
31+
"authereum": "^0.0.4-beta.17",
2932
"bignumber.js": "^9.0.0",
3033
"bnc-sdk": "0.1.1",
3134
"bowser": "^2.5.2",
35+
"fortmatic": "^0.8.2",
3236
"ow": "^0.13.2",
3337
"promise-cancelable": "^2.1.1",
3438
"regenerator-runtime": "^0.13.3",
3539
"svelte": "^3.0.0",
36-
"svelte-i18n": "^1.1.2-beta",
37-
"@portis/web3": "^2.0.0-beta.42",
38-
"@walletconnect/web3-provider": "^1.0.0-beta.36",
39-
"fortmatic": "^0.8.2"
40+
"svelte-i18n": "^1.1.2-beta"
4041
},
4142
"scripts": {
4243
"prepare": "rollup -c",

rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export default [
5050
"regenerator-runtime/runtime",
5151
"@portis/web3",
5252
"@walletconnect/web3-provider",
53-
"fortmatic"
53+
"fortmatic",
54+
"authereum"
5455
],
5556
plugins: [
5657
svelte(),

src/components/ModalHeader.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
font-weight: bold;
2929
font-size: 1.33rem;
3030
margin: 0 0 0 0.5rem;
31-
color: #4a4a4a;
3231
}
3332
</style>
3433

src/elements/Spinner.svelte

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<style>
2+
.bn-onboard-loading {
3+
display: inline-block;
4+
position: relative;
5+
width: 2rem;
6+
height: 2rem;
7+
}
8+
.bn-onboard-loading div {
9+
box-sizing: border-box;
10+
display: block;
11+
position: absolute;
12+
width: 2rem;
13+
height: 2rem;
14+
border: 3px solid #4a90e2;
15+
border-radius: 50%;
16+
animation: bn-onboard-loading 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
17+
border-color: #4a90e2 transparent transparent transparent;
18+
}
19+
.bn-onboard-loading div:nth-child(1) {
20+
animation-delay: -0.45s;
21+
}
22+
.bn-onboard-loading div:nth-child(2) {
23+
animation-delay: -0.3s;
24+
}
25+
.bn-onboard-loading div:nth-child(3) {
26+
animation-delay: -0.15s;
27+
}
28+
@keyframes bn-onboard-loading {
29+
0% {
30+
transform: rotate(0deg);
31+
}
32+
100% {
33+
transform: rotate(360deg);
34+
}
35+
}
36+
</style>
37+
38+
<div class="bn-onboard-custom bn-onboard-loading">
39+
<div />
40+
<div />
41+
<div />
42+
<div />
43+
</div>

src/modules/ready/connect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function connect() {
66
description: `This dapp requires access to your wallet, please login and authorize access to your ${wallet.name} accounts to continue.`,
77
eventCode: "loginFail",
88
action: wallet.connect,
9+
loading: wallet.loading,
910
icon: `
1011
<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>
1112
`

src/modules/select/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import coinbase from "./wallets/coinbase"
55
import trust from "./wallets/trust"
66
import portis from "./wallets/portis"
77
import fortmatic from "./wallets/fortmatic"
8+
import authereum from "./wallets/authereum"
9+
810
import { networkName } from "../../utilities"
911

1012
function defaults({
@@ -38,6 +40,9 @@ function defaults({
3840
)
3941
}
4042

43+
desktopModules.push(authereum({ network }))
44+
mobileModules.push(authereum({ network }))
45+
4146
return {
4247
heading: heading || "Select a Wallet",
4348
description:
@@ -58,5 +63,6 @@ export default {
5863
coinbase,
5964
trust,
6065
portis,
61-
fortmatic
66+
fortmatic,
67+
authereum
6268
}
4.47 KB
Loading
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import Authereum from "authereum"
2+
import authereumIcon from "../wallet-icons/authereum.png"
3+
4+
import { networkToId } from "../../../utilities"
5+
6+
function authereum(options) {
7+
if (!options || typeof options !== "object") {
8+
throw new Error(
9+
"An options object is required to initialize fortmatic module"
10+
)
11+
}
12+
13+
const { network } = options
14+
15+
if (!network || typeof network !== "string") {
16+
throw new Error(
17+
"A network of type string is required to initialize fortmatic module"
18+
)
19+
}
20+
21+
return {
22+
name: "Authereum",
23+
iconSrc: authereumIcon,
24+
wallet: () => {
25+
const authereum = new Authereum(network)
26+
const provider = authereum.getProvider()
27+
28+
return {
29+
provider,
30+
interface: {
31+
name: "Authereum",
32+
connect: () => provider.enable(),
33+
loading: () =>
34+
new Promise(resolve => {
35+
authereum.on("openPopup", resolve)
36+
}),
37+
address: {
38+
get: () => authereum.getAccountAddress()
39+
},
40+
network: {
41+
get: () => Promise.resolve(networkToId(network))
42+
},
43+
balance: {
44+
get: async () => {
45+
const loggedIn = await authereum.isAuthenticated()
46+
return loggedIn && authereum.getBalance()
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
55+
export default authereum

src/validation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function validateModal(modal) {
7272
invalidMsg: ow.optional.string,
7373
eventCode: ow.string,
7474
action: ow.optional.function,
75+
loading: ow.optional.function,
7576
button: ow.optional.object.exactShape({
7677
onclick: ow.function,
7778
text: ow.string
@@ -89,6 +90,7 @@ export function validateWalletInterface(walletInterface) {
8990
name: ow.string,
9091
connect: ow.optional.function,
9192
disconnect: ow.optional.function,
93+
loading: ow.optional.function,
9294
address: ow.object
9395
.hasAnyKeys("get", "onChange")
9496
.valuesOfType(ow.function),

src/views/WalletReady.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import Modal from "../components/Modal.svelte";
1212
import ModalHeader from "../components/ModalHeader.svelte";
1313
import Button from "../elements/Button.svelte";
14+
import Spinner from "../elements/Spinner.svelte";
1415
1516
export let modules;
1617
export let walletSelect;
@@ -23,6 +24,7 @@
2324
let pollingInterval;
2425
let checkingModule;
2526
let actionResolved;
27+
let loading;
2628
2729
// recheck modules if below conditions
2830
$: if (!activeModal && !checkingModule) {
@@ -61,6 +63,11 @@
6163
doAction();
6264
}
6365
66+
if (activeModal.loading) {
67+
loading = true;
68+
activeModal.loading().then(() => (loading = false));
69+
}
70+
6471
// poll to automatically to check if condition has been met
6572
pollingInterval = setInterval(async () => {
6673
const invalid = await invalidState(currentModule, get(state));
@@ -199,6 +206,9 @@
199206
{:else}
200207
<div />
201208
{/if}
209+
{#if loading}
210+
<Spinner />
211+
{/if}
202212
<Button onclick={handleExit}>Dismiss</Button>
203213
</div>
204214
</Modal>

0 commit comments

Comments
 (0)