on master help sign in
refactor: standardize containers
955c817Matt Condon (shrugs)
src/bridge/store/history.js+8−2
@@ -1,10 +1,16 @@
1−import React, { forwardRef, useContext, useState, useEffect } from 'react';
1+import React, {
2+ createContext,
3+ forwardRef,
4+ useContext,
5+ useState,
6+ useEffect,
7+} from 'react';
2import { last, includes } from 'lodash';
8import { last, includes } from 'lodash';
3
9
4import { BRIDGE_ERROR } from '../lib/error';
10import { BRIDGE_ERROR } from '../lib/error';
5import { ROUTE_NAMES } from '../lib/routeNames';
11import { ROUTE_NAMES } from '../lib/routeNames';
6
12
7−export const HistoryContext = React.createContext(null);
13+export const HistoryContext = createContext(null);
8
14
9function _useHistory(initialRoutes = []) {
15function _useHistory(initialRoutes = []) {
10 const [history, setHistory] = useState(initialRoutes);
16 const [history, setHistory] = useState(initialRoutes);
src/bridge/store/network.js+9−4
@@ -1,10 +1,15 @@
1−import React, { useContext, useMemo, useState } from 'react';
1+import React, {
2+ createContext,
3+ forwardRef,
4+ useContext,
5+ useMemo,
6+ useState,
7+} from 'react';
2import * as azimuth from 'azimuth-js';
8import * as azimuth from 'azimuth-js';
3import Web3 from 'web3';
9import Web3 from 'web3';
4import Maybe from 'folktale/maybe';
10import Maybe from 'folktale/maybe';
5
11
6import { CONTRACT_ADDRESSES } from '../lib/contracts';
12import { CONTRACT_ADDRESSES } from '../lib/contracts';
7−
8import { NETWORK_NAMES } from '../lib/network';
13import { NETWORK_NAMES } from '../lib/network';
9import { isDevelopment } from '../lib/flags';
14import { isDevelopment } from '../lib/flags';
10
15
@@ -72,7 +77,7 @@ function _useNetwork(initialNetworkType = null) {
72 return { networkType, setNetworkType, web3, contracts };
77 return { networkType, setNetworkType, web3, contracts };
73}
78}
74
79
75−const NetworkContext = React.createContext(null);
80+const NetworkContext = createContext(null);
76
81
77// provider
82// provider
78export function NetworkProvider({ initialNetworkType, children }) {
83export function NetworkProvider({ initialNetworkType, children }) {
@@ -89,7 +94,7 @@ export function useNetwork() {
89
94
90// hoc consumer
95// hoc consumer
91export const withNetwork = Component =>
96export const withNetwork = Component =>
92− React.forwardRef((props, ref) => {
97+ forwardRef((props, ref) => {
93 return (
98 return (
94 <NetworkContext.Consumer>
99 <NetworkContext.Consumer>
95 {value => <Component ref={ref} {...value} {...props} />}
100 {value => <Component ref={ref} {...value} {...props} />}
src/bridge/store/online.js+9−3
@@ -1,4 +1,10 @@
1−import React, { useContext, useEffect, useState } from 'react';
1+import React, {
2+ createContext,
3+ forwardRef,
4+ useContext,
5+ useEffect,
6+ useState,
7+} from 'react';
2
8
3function _useOnline() {
9function _useOnline() {
4 const [online, setOnline] = useState(window.navigator.onLine);
10 const [online, setOnline] = useState(window.navigator.onLine);
@@ -20,7 +26,7 @@ function _useOnline() {
20 return online;
26 return online;
21}
27}
22
28
23−const OnlineContext = React.createContext(null);
29+const OnlineContext = createContext(null);
24
30
25// provider
31// provider
26export function OnlineProvider({ children }) {
32export function OnlineProvider({ children }) {
@@ -37,7 +43,7 @@ export function useOnline() {
37
43
38// hoc consumer
44// hoc consumer
39export const withOnline = Component =>
45export const withOnline = Component =>
40− React.forwardRef((props, ref) => {
46+ forwardRef((props, ref) => {
41 return (
47 return (
42 <OnlineContext.Consumer>
48 <OnlineContext.Consumer>
43 {online => <Component ref={ref} online={online} {...props} />}
49 {online => <Component ref={ref} online={online} {...props} />}
src/bridge/store/txnConfirmations.js+13−8
@@ -1,8 +1,8 @@
1−import React, { forwardRef, useContext, useState } from 'react';
1+import React, { createContext, forwardRef, useContext, useState } from 'react';
2
2
3−export const TxnConfirmationsContext = React.createContext(null);
3+export const TxnConfirmationsContext = createContext(null);
4
4
5−export function TxnConfirmationsProvider({ children }) {
5+function _useTxnConfirmations() {
6 const [confirmations, setConfirmations] = useState({});
6 const [confirmations, setConfirmations] = useState({});
7
7
8 const setTxnConfirmations = (txnHash, txnConfirmations) => {
8 const setTxnConfirmations = (txnHash, txnConfirmations) => {
@@ -12,12 +12,17 @@ export function TxnConfirmationsProvider({ children }) {
12 });
12 });
13 };
13 };
14
14
15+ return {
16+ txnConfirmations: confirmations,
17+ setTxnConfirmations,
18+ };
19+}
20+
21+export function TxnConfirmationsProvider({ children }) {
22+ const value = _useTxnConfirmations();
23+
15 return (
24 return (
16− <TxnConfirmationsContext.Provider
25+ <TxnConfirmationsContext.Provider value={value}>
17− value={{
18− txnConfirmations: confirmations,
19− setTxnConfirmations,
20− }}>
21 {children}
26 {children}
22 </TxnConfirmationsContext.Provider>
27 </TxnConfirmationsContext.Provider>
23 );
28 );