From 8e501e5e61961313f7aae2bc43cfa2c9381a6de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 27 Jun 2019 09:53:16 +0200 Subject: [PATCH 1/5] Store Bity.com transaction in localStorage --- src/components/History.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/History.js b/src/components/History.js index 3b008d4db..ab367026a 100644 --- a/src/components/History.js +++ b/src/components/History.js @@ -11,6 +11,7 @@ import { OutlineButton } from 'rimble-ui' import Transaction from "ethereumjs-tx"; import EthUtil from 'ethereumjs-util'; import EthCrypto from 'eth-crypto'; +import { getOrder } from "../services/bity"; const CONFIG = getConfig(); From cd14b332e51d8bc840fada143a82ae41fc63bbb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 3 Jul 2019 16:59:56 +0200 Subject: [PATCH 2/5] services/core => services/ethgasstation --- src/components/Bity.js | 4 ++-- src/components/Exchange.js | 14 +++++++------- src/services/core.js | 19 ------------------- src/services/ethgasstation.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 28 deletions(-) delete mode 100644 src/services/core.js create mode 100644 src/services/ethgasstation.js diff --git a/src/components/Bity.js b/src/components/Bity.js index b72b162ec..54787e450 100644 --- a/src/components/Bity.js +++ b/src/components/Bity.js @@ -7,7 +7,7 @@ import { format } from "@tammo/react-iban"; import styled from "styled-components"; import { isValid } from "iban"; import { placeOrder, getOrder, getEstimate } from "../services/bity"; -import { gasPrice } from "../services/core"; +import { price } from "../services/ethgasstation"; const P = styled.p` color: gray; @@ -152,7 +152,7 @@ class Bity extends Component { if (metaAccount) { let gwei; try { - gwei = await gasPrice(); + gwei = await price(); } catch (err) { changeAlert( "warning", diff --git a/src/components/Exchange.js b/src/components/Exchange.js index 00d27aa39..0b51b8111 100644 --- a/src/components/Exchange.js +++ b/src/components/Exchange.js @@ -19,7 +19,7 @@ import { bi, add, divide } from 'jsbi-utils'; import getConfig from "../config"; import { PrimaryButton, BorderButton } from "./Buttons"; import bityLogo from '../assets/bity.png'; -import { gasPrice } from "../services/core"; +import { price } from "../services/ethgasstation"; const CONFIG = getConfig(); const BN = Web3.utils.BN @@ -311,7 +311,7 @@ export default class Exchange extends React.Component { let gwei; try { - gwei = await gasPrice(); + gwei = await price(); } catch(err) { console.log("Error getting gas price",err) } @@ -375,7 +375,7 @@ export default class Exchange extends React.Component { async depositDai(destination, amount, message, cb) { let gwei try { - gwei = await gasPrice(); + gwei = await price(); } catch(err) { console.log("Error getting gas price",err) } @@ -565,7 +565,7 @@ export default class Exchange extends React.Component { let gwei; try { - gwei = await gasPrice(); + gwei = await price(); } catch(err) { // TODO: Propagate error to user console.log("Error getting gas price",err) @@ -630,7 +630,7 @@ export default class Exchange extends React.Component { if(this.state.mainnetMetaAccount){ //send funds using metaaccount on mainnet - gasPrice() + price() .catch((err)=>{ console.log("Error getting gas price",err) }) @@ -1159,7 +1159,7 @@ export default class Exchange extends React.Component { if(this.state.mainnetMetaAccount){ //send funds using metaaccount on mainnet - gasPrice() + price() .catch((err)=>{ console.log("Error getting gas price",err) }) @@ -1514,7 +1514,7 @@ export default class Exchange extends React.Component { ml={2} onClick={() => { console.log("Getting gas price...") - gasPrice() + price() .catch((err)=>{ console.log("Error getting gas price",err) }) diff --git a/src/services/core.js b/src/services/core.js deleted file mode 100644 index fdedf7748..000000000 --- a/src/services/core.js +++ /dev/null @@ -1,19 +0,0 @@ -import getConfig from "../config"; - -const CONFIG = getConfig(); - -export function gasPrice() { - return fetch('https://ethgasstation.info/json/ethgasAPI.json', { - mode: 'cors', - method: 'get', - }) - .then(r => r.json()) - .then((response)=>{ - if(response.average > 0 && response.average < 200){ - const avg = response.average + (response.average*CONFIG.ROOTCHAIN.GAS.BOOST_BY) - return Math.round(avg * 100) / 1000; - } - - return Promise.reject('Average out of range (0–200)'); - }); -} diff --git a/src/services/ethgasstation.js b/src/services/ethgasstation.js new file mode 100644 index 000000000..b03cc52cd --- /dev/null +++ b/src/services/ethgasstation.js @@ -0,0 +1,31 @@ +// @format +import getConfig from "../config"; + +const CONFIG = getConfig(); +const API = "https://ethgasstation.info/json/ethgasAPI.json"; + +function get() { + return fetch(API, { + mode: "cors", + method: "get" + }).then(r => r.json()); +} + +// NOTE: Both price() and time() currently default to average. In the future, +// these function could be adjusted to feature "fast" and "safe" too. +// NOTE2: Both functions can throw and should be try-catch'ed. +export async function price() { + const { average } = await get(); + if (average > 0 && average < 200) { + const avg = average + average * CONFIG.ROOTCHAIN.GAS.BOOST_BY; + return Math.round(avg * 100) / 1000; + } + return Promise.reject("Average out of range (0–200)"); +} + +export async function time() { + // NOTE: avgWait is returned from ethgasstation in minutes (double) + const { avgWait } = await get(); + // We convert minutes to milliseconds + return avgWait * 60 * 1000; +} From cb06cef37e594f28485353fdcc2ed9f968e24460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 3 Jul 2019 17:40:09 +0200 Subject: [PATCH 3/5] Make dynamic --- src/components/Loader.js | 76 ++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/src/components/Loader.js b/src/components/Loader.js index eb92da0c7..1dea5e125 100644 --- a/src/components/Loader.js +++ b/src/components/Loader.js @@ -1,32 +1,80 @@ -import React, { Component } from 'react'; -let interval +// @format +import React, { Component } from "react"; +import { time } from "../services/ethgasstation"; + +let interval; +const RATE = { + PERCENT: 3, + EACH: 250 +}; + class Loader extends Component { constructor(props) { super(props); + this.state = { - percent: 5, + progress: 0, + rate: { + percent: RATE.PERCENT, + each: RATE.EACH + } }; + + this.progress = this.progress.bind(this); } - componentDidMount(){ - interval = setInterval(this.loadMore.bind(this),250) + + async componentDidMount() { + const { network } = this.props; + + let t; + if (network === "ROOT_CHAIN") { + t = await time(); + } else if (network === "SIDE_CHAIN") { + t = 1000; //ms + throw new Error("Network not yet supported"); + } else { + // 8ms was Loader's default value. + t = 8333; // ms + } + + const rate = { + // NOTE: We "round" the result of "each"'s calculation + each: parseInt(t / 100 / RATE.PERCENT, 10), + percent: RATE.PERCENT + }; + this.setState({ rate }, () => { + console.log(rate.each); + interval = setInterval(this.progress, rate.each); + }); } - componentWillUnmount(){ - clearInterval(interval) + + componentWillUnmount() { + clearInterval(interval); } - loadMore(){ - let newPercent = this.state.percent+3 - if(newPercent>100) newPercent=100 - this.setState({percent:newPercent}) + + progress() { + const { rate, progress } = this.state; + + let newProgress = progress + rate.percent; + if (newProgress > 100) { + newProgress = 100; + } + this.setState({ progress: newProgress }); } + render() { + const { progress } = this.state; return (
- +
-
+
- ) + ); } } export default Loader; From 22dc470eb5f2638a77bd2b8764d40b8de0294418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 3 Jul 2019 18:14:00 +0200 Subject: [PATCH 4/5] Integrate new --- src/App.js | 16 ++++++++++++++++ src/components/Bity.js | 2 +- src/components/History.js | 1 - src/components/Loader.js | 14 +++++++++----- src/components/SendToAddress.js | 2 +- src/components/WithdrawFromPrivate.js | 2 +- src/config.js | 9 ++++++--- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index 9c67b05fd..51b0a9cd6 100644 --- a/src/App.js +++ b/src/App.js @@ -864,6 +864,22 @@ export default class App extends Component { ) } + if (view.includes("loader_")) { + const network = view.replace("loader_"); + return ( +
+
+ + +
+ +
+ ); + } + const sendByScan = ( { - console.log(rate.each); interval = setInterval(this.progress, rate.each); }); } @@ -58,15 +59,18 @@ class Loader extends Component { let newProgress = progress + rate.percent; if (newProgress > 100) { newProgress = 100; + clearInterval(interval); } this.setState({ progress: newProgress }); } render() { const { progress } = this.state; + const { loaderImage } = this.props; + return (
- +
{window.scrollTo(0,0)},60) console.log("web3",this.props.web3) diff --git a/src/components/WithdrawFromPrivate.js b/src/components/WithdrawFromPrivate.js index c5a3a8b2f..3b476dbbf 100644 --- a/src/components/WithdrawFromPrivate.js +++ b/src/components/WithdrawFromPrivate.js @@ -70,7 +70,7 @@ export default class SendToAddress extends React.Component { if(this.state.canWithdraw){ console.log("SWITCH TO LOADER VIEW...") - this.props.changeView('loader') + this.props.changeView('loader_SIDECHAIN') setTimeout(()=>{window.scrollTo(0,0)},60) //console.log("metaAccount",this.state.metaAccount,"amount",this.props.web3.utils.toWei(amount,'ether')) diff --git a/src/config.js b/src/config.js index 32684d507..06e8a316b 100644 --- a/src/config.js +++ b/src/config.js @@ -22,7 +22,8 @@ const configs = [ // is dependent on how often blocks are submitted to the network. // Ultimately, we want to remove this value from the code base somehow. EXIT: 160000, - DEPOSIT: 330000 + DEPOSIT: 330000, + TX: 1000, } }, ROOTCHAIN: { @@ -57,7 +58,8 @@ const configs = [ // is dependent on how often blocks are submitted to the network. // Ultimately, we want to remove this value from the code base somehow. EXIT: 160000, - DEPOSIT: 330000 + DEPOSIT: 330000, + TX: 1000, } }, ROOTCHAIN: { @@ -92,7 +94,8 @@ const configs = [ // is dependent on how often blocks are submitted to the network. // Ultimately, we want to remove this value from the code base somehow. EXIT: 160000, - DEPOSIT: 330000 + DEPOSIT: 330000, + TX: 1000, } }, ROOTCHAIN: { From df2e069914ddadbe2f3183763b43aec4dedce8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 5 Jul 2019 16:22:05 +0200 Subject: [PATCH 5/5] Alt text for burner-wallet logo --- src/components/Loader.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/Loader.js b/src/components/Loader.js index f920eb406..d48a00cba 100644 --- a/src/components/Loader.js +++ b/src/components/Loader.js @@ -70,7 +70,11 @@ class Loader extends Component { return (
- + Burner Wallet Logo