on master help sign in
refactor: standardize containers
commit955c8174c53f19fa4d8be3c70d736628e3105d7c authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 11 Jun 2019, 14:14 (7 years ago) parentcec0b6d
4 files changed+39−17
src/bridge/store/history.js+8−2 src/bridge/store/network.js+9−4 src/bridge/store/online.js+9−3 src/bridge/store/txnConfirmations.js+13−8
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';
28import { last, includes } from 'lodash';
39
410import { BRIDGE_ERROR } from '../lib/error';
511import { ROUTE_NAMES } from '../lib/routeNames';
612
7−export const HistoryContext = React.createContext(null);
13+export const HistoryContext = createContext(null);
814
915function _useHistory(initialRoutes = []) {
1016 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';
28import * as azimuth from 'azimuth-js';
39import Web3 from 'web3';
410import Maybe from 'folktale/maybe';
511
612import { CONTRACT_ADDRESSES } from '../lib/contracts';
7−
813import { NETWORK_NAMES } from '../lib/network';
914import { isDevelopment } from '../lib/flags';
1015
@@ -72,7 +77,7 @@ function _useNetwork(initialNetworkType = null) {
7277 return { networkType, setNetworkType, web3, contracts };
7378}
7479
75−const NetworkContext = React.createContext(null);
80+const NetworkContext = createContext(null);
7681
7782// provider
7883export function NetworkProvider({ initialNetworkType, children }) {
@@ -89,7 +94,7 @@ export function useNetwork() {
8994
9095// hoc consumer
9196export const withNetwork = Component =>
92− React.forwardRef((props, ref) => {
97+ forwardRef((props, ref) => {
9398 return (
9499 <NetworkContext.Consumer>
95100 {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';
28
39function _useOnline() {
410 const [online, setOnline] = useState(window.navigator.onLine);
@@ -20,7 +26,7 @@ function _useOnline() {
2026 return online;
2127}
2228
23−const OnlineContext = React.createContext(null);
29+const OnlineContext = createContext(null);
2430
2531// provider
2632export function OnlineProvider({ children }) {
@@ -37,7 +43,7 @@ export function useOnline() {
3743
3844// hoc consumer
3945export const withOnline = Component =>
40− React.forwardRef((props, ref) => {
46+ forwardRef((props, ref) => {
4147 return (
4248 <OnlineContext.Consumer>
4349 {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';
22
3−export const TxnConfirmationsContext = React.createContext(null);
3+export const TxnConfirmationsContext = createContext(null);
44
5−export function TxnConfirmationsProvider({ children }) {
5+function _useTxnConfirmations() {
66 const [confirmations, setConfirmations] = useState({});
77
88 const setTxnConfirmations = (txnHash, txnConfirmations) => {
@@ -12,12 +12,17 @@ export function TxnConfirmationsProvider({ children }) {
1212 });
1313 };
1414
15+ return {
16+ txnConfirmations: confirmations,
17+ setTxnConfirmations,
18+ };
19+}
20+
21+export function TxnConfirmationsProvider({ children }) {
22+ const value = _useTxnConfirmations();
23+
1524 return (
16− <TxnConfirmationsContext.Provider
17− value={{
18− txnConfirmations: confirmations,
19− setTxnConfirmations,
20− }}>
25+ <TxnConfirmationsContext.Provider value={value}>
2126 {children}
2227 </TxnConfirmationsContext.Provider>
2328 );