Skip to content

Commit

Permalink
Merge pull request #131 from carboclan/master
Browse files Browse the repository at this point in the history
merge 2 day settings and config for netlify deploy
  • Loading branch information
FSM1 authored Jun 23, 2020
2 parents 68741d8 + f7e379f commit f75258c
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 68 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:honeylemonjs": "yarn wsrun -p @honeylemon/honeylemonjs -c build",
"build:subgraph": "yarn wsrun -p @honeylemon/graph -c build",
"build:webapp": "yarn wsrun -p @honeylemon/webapp -c build",
"start:webapp": "yarn wsrun -p @honeylemon/webapp -c start",
"clean": "rm -rf ./node_modules && rm -rf ./*/node_modules"
},
"workspaces": {
Expand Down
4 changes: 2 additions & 2 deletions packages/honeylemonjs/src/HoneylemonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const TH_DECIMALS = 0; // TH has 6 decimals
const PAYMENT_TOKEN_DECIMALS = 6; // USDT has 6 decimals
const COLLATERAL_TOKEN_DECIMALS = 8; // imBTC has 8 decimals
const SHIFT_PRICE_BY = TH_DECIMALS - PAYMENT_TOKEN_DECIMALS;
const CONTRACT_DURATION = 28; // Days
// const CONTRACT_DURATION = 2; // 2 day for Kovan deployment
// const CONTRACT_DURATION = 28; // Days
const CONTRACT_DURATION = 2; // 2 day for Kovan deployment

class HoneylemonService {
subgraphClient: any;
Expand Down
40 changes: 40 additions & 0 deletions packages/webapp/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
webpack: {
configure: (webpackConfig) => ({
...webpackConfig,
optimization: {
...webpackConfig.optimization,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
drop_console: true,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: 2,
cache: true,
sourceMap: false,
extractComments: false,
}),
],
},
}),
},
};
6 changes: 3 additions & 3 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"dependencies": {
"@0x/utils": "5.4.1",
"@craco/craco": "5.6.4",
"@babel/runtime": "^7.10.2",
"@carboclan/mri": "git+https://github.com/carboclan/mri.git",
"@honeylemon/honeylemonjs": "0.1.0",
"@material-ui/core": "4.9.12",
"@material-ui/icons": "4.9.1",
Expand Down Expand Up @@ -43,8 +43,8 @@
"typescript": "3.9.2"
},
"scripts": {
"start": "react-scripts --max_old_space_size=8192 start",
"build": "react-scripts --max_old_space_size=8192 build",
"start": "craco --max_old_space_size=8192 start",
"build": "craco --max_old_space_size=8192 build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"analyze": "source-map-explorer 'build/static/js/*.js'"
Expand Down
1 change: 0 additions & 1 deletion packages/webapp/src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
declare module 'honeylemon';
declare module 'react-blockies';
declare module '@carboclan/mri';
7 changes: 1 addition & 6 deletions packages/webapp/src/components/ActiveLongPositionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React from 'react';
import { makeStyles, Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography, Grid } from '@material-ui/core';
import { Dialog, DialogTitle, DialogContent, TableRow, Table, TableCell, TableBody } from '@material-ui/core';
import { useHoneylemon } from '../contexts/HoneylemonContext';
import { BigNumber } from '@0x/utils';
import dayjs from 'dayjs';

const useStyles = makeStyles(({ palette }) => ({

}))

interface ActiveLongPositionModalProps {
open: boolean,
onClose(): void,
position: any,
};

const ActiveLongPositionModal: React.SFC<ActiveLongPositionModalProps> = ({ open, onClose, position }) => {
const classes = useStyles();
const { PAYMENT_TOKEN_DECIMALS, PAYMENT_TOKEN_NAME, COLLATERAL_TOKEN_NAME, COLLATERAL_TOKEN_DECIMALS } = useHoneylemon();
return (
<Dialog open={open} onClose={onClose} aria-labelledby="dialog-title" maxWidth='sm' fullWidth>
Expand Down
7 changes: 1 addition & 6 deletions packages/webapp/src/components/ActiveShortPositionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React from 'react';
import { makeStyles, Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography, Grid } from '@material-ui/core';
import { Dialog, DialogTitle, DialogContent, TableRow, Table, TableCell, TableBody } from '@material-ui/core';
import { useHoneylemon } from '../contexts/HoneylemonContext';
import { BigNumber } from '@0x/utils';
import dayjs from 'dayjs';

const useStyles = makeStyles(({ palette }) => ({

}))

interface ActiveShortPositionModalProps {
open: boolean,
onClose(): void,
position: any,
};

const ActiveShortPositionModal: React.SFC<ActiveShortPositionModalProps> = ({ open, onClose, position }) => {
const classes = useStyles();
const { PAYMENT_TOKEN_DECIMALS, PAYMENT_TOKEN_NAME, COLLATERAL_TOKEN_NAME, COLLATERAL_TOKEN_DECIMALS } = useHoneylemon();
return (
<Dialog open={open} onClose={onClose} aria-labelledby="dialog-title" maxWidth='sm' fullWidth>
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function AppWrapper(props: { children: ReactNode }) {
const location = useLocation();
const [open, setOpen] = React.useState(false);
const { isReady, address, network, resetOnboard } = useOnboard();
const { isDsProxyDeployed, dsProxyAddress, deployDSProxyContract, approveToken } = useHoneylemon();
const { isDsProxyDeployed, dsProxyAddress } = useHoneylemon();
const {
collateralTokenBalance,
COLLATERAL_TOKEN_DECIMALS,
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/BuyContractPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const BuyContractPage: React.SFC = () => {
</TableRow>
<TableRow>
<TableCell>Revenue Cap</TableCell>
<TableCell align='right'>{`${((expectedBTCAccrual || 0) * CONTRACT_COLLATERAL_RATIO).toLocaleString(undefined, { maximumFractionDigits: COLLATERAL_TOKEN_DECIMALS })} ${COLLATERAL_TOKEN_NAME}`}</TableCell>
<TableCell align='right'>{`${((expectedBTCAccrual || 0) * CONTRACT_COLLATERAL_RATIO).toLocaleString(undefined, { maximumFractionDigits: 2 })} ${COLLATERAL_TOKEN_NAME}`}</TableCell>
</TableRow>
<TableRow>
<TableCell className={classes.orderSummaryEstimate}>
Expand Down
7 changes: 1 addition & 6 deletions packages/webapp/src/components/ExpiredLongPositionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React from 'react';
import { makeStyles, Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography, Grid } from '@material-ui/core';
import { Dialog, DialogTitle, DialogContent, TableRow, Table, TableCell, TableBody } from '@material-ui/core';
import { useHoneylemon, PositionStatus } from '../contexts/HoneylemonContext';
import { BigNumber } from '@0x/utils';
import dayjs from 'dayjs';

const useStyles = makeStyles(({ palette }) => ({

}))

interface ExpiredLongPositionModalProps {
open: boolean,
onClose(): void,
position: any,
};

const ExpiredLongPositionModal: React.SFC<ExpiredLongPositionModalProps> = ({ open, onClose, position }) => {
const classes = useStyles();
const { PAYMENT_TOKEN_DECIMALS, PAYMENT_TOKEN_NAME, COLLATERAL_TOKEN_NAME, COLLATERAL_TOKEN_DECIMALS } = useHoneylemon();
return (
<Dialog open={open} onClose={onClose} aria-labelledby="dialog-title" maxWidth='sm' fullWidth>
Expand Down
7 changes: 1 addition & 6 deletions packages/webapp/src/components/ExpiredShortPositionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React from 'react';
import { makeStyles, Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography, Grid } from '@material-ui/core';
import { Dialog, DialogTitle, DialogContent, TableRow, Table, TableCell, TableBody } from '@material-ui/core';
import { useHoneylemon, PositionStatus } from '../contexts/HoneylemonContext';
import { BigNumber } from '@0x/utils';
import dayjs from 'dayjs';

const useStyles = makeStyles(({ palette }) => ({

}))

interface ExpiredShortPositionModalProps {
open: boolean,
onClose(): void,
position: any,
};

const ExpiredShortPositionModal: React.SFC<ExpiredShortPositionModalProps> = ({ open, onClose, position }) => {
const classes = useStyles();
const { PAYMENT_TOKEN_DECIMALS, PAYMENT_TOKEN_NAME, COLLATERAL_TOKEN_NAME, COLLATERAL_TOKEN_DECIMALS } = useHoneylemon();
return (
<Dialog open={open} onClose={onClose} aria-labelledby="dialog-title" maxWidth='sm' fullWidth>
Expand Down
4 changes: 1 addition & 3 deletions packages/webapp/src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Link, Button, Typography, makeStyles, Grid, Divider } from '@material-ui/core';
import { Link as RouterLink } from 'react-router-dom';
import { OpenInNew } from '@material-ui/icons';
import { Button, Typography, makeStyles, Grid, Divider } from '@material-ui/core';
import { forwardTo } from '../helpers/history';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/MiningStatsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useStyles = makeStyles(({ palette }) => ({
const MiningStatsPage: React.SFC = () => {
const classes = useStyles();
const {
marketData: { currentMRI, currentBTCSpotPrice, btcDifficultyAdjustmentDate, miningContracts, currentBtcDifficulty },
marketData: { currentMRI, currentBTCSpotPrice, btcDifficultyAdjustmentDate, miningContracts },
PAYMENT_TOKEN_DECIMALS,
orderbook,
btcStats,
Expand Down
8 changes: 7 additions & 1 deletion packages/webapp/src/components/OfferContractPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ const OfferContractPage: React.SFC = () => {
setTxActive(true);
if (hashAmount) {
try {
const order = honeylemonService.createOrder(address, new BigNumber(hashAmount), new BigNumber(CONTRACT_DURATION).multipliedBy(hashPrice));
const order = honeylemonService.createOrder(
address,
new BigNumber(hashAmount),
new BigNumber(CONTRACT_DURATION).multipliedBy(hashPrice),
new BigNumber(Math.round(Date.now() / 1000) + 10 * 24 * 60 * 60)
);

const signedOrder = await honeylemonService.signOrder(order);
await honeylemonService.submitOrder(signedOrder);
setShowOfferModal(false)
Expand Down
7 changes: 1 addition & 6 deletions packages/webapp/src/components/OrderbookModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import React from 'react';
import { makeStyles, Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography } from '@material-ui/core';
import { Dialog, DialogTitle, DialogContent, TableRow, TableHead, Table, TableCell, TableBody, Typography } from '@material-ui/core';
import { useHoneylemon } from '../contexts/HoneylemonContext';

const useStyles = makeStyles(({ palette }) => ({

}))

interface OrderbookModalProps {
open: boolean,
onClose(): void,
};

const OrderbookModal: React.SFC<OrderbookModalProps> = ({ open, onClose }: OrderbookModalProps) => {
const classes = useStyles();
const { orderbook, PAYMENT_TOKEN_DECIMALS } = useHoneylemon();
return (
<Dialog open={open} onClose={onClose} aria-labelledby="dialog-title" maxWidth='sm' fullWidth>
Expand Down
6 changes: 2 additions & 4 deletions packages/webapp/src/components/PortfolioPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ const PorfolioPage: React.SFC = () => {
const previousExpiredShortPositionsCount = usePrevious(expiredShortPositions.length);

useEffect(() => {
let isCancelled = false;
const loadPortfolioData = async () => {
setIsLoading(true);
try {
Expand All @@ -246,7 +245,6 @@ const PorfolioPage: React.SFC = () => {
}
loadPortfolioData()
return () => {
isCancelled = true;
}
}, [address])

Expand Down Expand Up @@ -474,11 +472,11 @@ const PorfolioPage: React.SFC = () => {
<TableBody>
<TableRow>
<TableCell>Long Positions (Remaining Collateral)</TableCell>
<TableCell align='right'>{longCollateralForWithdraw.toLocaleString(undefined, {maximumFractionDigits: COLLATERAL_TOKEN_DECIMALS})} {COLLATERAL_TOKEN_NAME}</TableCell>
<TableCell align='right'>{longCollateralForWithdraw.toLocaleString(undefined, { maximumFractionDigits: COLLATERAL_TOKEN_DECIMALS })} {COLLATERAL_TOKEN_NAME}</TableCell>
</TableRow>
<TableRow>
<TableCell>Short Positions (Earnings)</TableCell>
<TableCell align='right'>{shortCollateralForWithdraw.toLocaleString(undefined, {maximumFractionDigits: COLLATERAL_TOKEN_DECIMALS})} {COLLATERAL_TOKEN_NAME}</TableCell>
<TableCell align='right'>{shortCollateralForWithdraw.toLocaleString(undefined, { maximumFractionDigits: COLLATERAL_TOKEN_DECIMALS })} {COLLATERAL_TOKEN_NAME}</TableCell>
</TableRow>
</TableBody>
</Table>
Expand Down
11 changes: 2 additions & 9 deletions packages/webapp/src/contexts/HoneylemonContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ethers } from 'ethers';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { BigNumber } from "@0x/utils";
const { getBtcData } = require('@carboclan/mri');

dayjs.extend(utc);

Expand Down Expand Up @@ -60,7 +59,6 @@ export type HoneylemonContext = {
currentMRI: number;
currentBTCSpotPrice: number;
btcDifficultyAdjustmentDate: Date;
currentBtcDifficulty: number;
}
portfolioData: {
openOrdersMetadata: Array<OpenOrderMetadata>;
Expand Down Expand Up @@ -130,7 +128,6 @@ const HoneylemonProvider = ({ children }: HoneylemonProviderProps) => {
const [miningContracts, setMiningContracts] = useState<Array<any>>([]);
const [currentMRI, setCurrentMRI] = useState(0);
const [currentBTCSpotPrice, setCurrentBTCSpotPrice] = useState(0);
const [currentBtcDifficulty, setCurrentBtcDifficulty] = useState(0);
const [btcDifficultyAdjustmentDate, setBtcDifficultyAdjustmentDate] = useState(new Date());
const [btcStats, setBtcStats] = useState<any>(undefined);
const [openOrdersMetadata, setOpenOrdersMetadata] = useState<Array<OpenOrderMetadata>>([]);
Expand Down Expand Up @@ -368,13 +365,10 @@ const HoneylemonProvider = ({ children }: HoneylemonProviderProps) => {
const marketDataApiUrl = process.env.REACT_APP_MARKET_DATA_API_URL;
if (marketDataApiUrl) {
const { contracts } = await (await fetch(`${marketDataApiUrl}/blockchain/agg?coin=BTC`)).json();
const { data } = await (await fetch(`${marketDataApiUrl}/coinmarketcap/v1/cryptocurrency/quotes/latest?symbol=BTC`)).json();
const stats = await (await fetch(`${marketDataApiUrl}/blockchain/stats`)).json();
const { mri, difficulty } = await getBtcData(dayjs().utc().format('YYYYMMDD'), 1, false);
setMiningContracts(contracts);
setCurrentBTCSpotPrice(data?.BTC?.quote?.USD?.price);
setCurrentMRI(mri);
setCurrentBtcDifficulty(difficulty);
setCurrentBTCSpotPrice(stats.quote?.price);
setCurrentMRI(Number(new BigNumber(stats.mri).shiftedBy(-COLLATERAL_TOKEN_DECIMALS).toString()));
setBtcStats(stats);
}
} catch (error) {
Expand Down Expand Up @@ -509,7 +503,6 @@ const HoneylemonProvider = ({ children }: HoneylemonProviderProps) => {
currentBTCSpotPrice,
currentMRI,
btcDifficultyAdjustmentDate,
currentBtcDifficulty,
},
portfolioData: {
activeLongPositions,
Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1465,13 +1465,6 @@
lodash "^4.17.13"
to-fast-properties "^2.0.0"

"@carboclan/mri@git+https://github.com/carboclan/mri.git":
version "0.0.1"
resolved "git+https://github.com/carboclan/mri.git#17769aa1f96ed03b26cea618691e3bb83ca39637"
dependencies:
axios "^0.19.2"
moment "^2.24.0"

"@chaitanyapotti/random-id@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@chaitanyapotti/random-id/-/random-id-1.0.3.tgz#f52f647cfe9f79fc7723ea2b01b0ad3889204002"
Expand Down Expand Up @@ -14134,11 +14127,6 @@ move-concurrently@^1.0.1:
rimraf "^2.5.4"
run-queue "^1.0.3"

[email protected]:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a"
integrity sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down

0 comments on commit f75258c

Please sign in to comment.