Skip to content

Commit

Permalink
App Logic rewrite for api 0.2 support (#723)
Browse files Browse the repository at this point in the history
* PoS UI

* PoS UI

* PoS UI

* PoS UI

* PoS api

* PoST API

* POS api

* POS api

* POS api

* App Logic rewrite targeting api 0.2

* Delete bug_report.md
  • Loading branch information
IlyaVi committed Apr 7, 2021
1 parent 9270ec3 commit 9e85438
Show file tree
Hide file tree
Showing 119 changed files with 26,612 additions and 8,386 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ ct-libc/
/release
.env
.vscode
/desktop/dist
13 changes: 5 additions & 8 deletions app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from 'react';
import { Provider } from 'react-redux';
import { hot } from 'react-hot-loader/root';
import { Store } from './redux/store';
import store from './redux/store';
import StyledApp from './StyledApp';
import './assets/fonts/SourceCodePro-Regular.ttf';
import './assets/fonts/SourceCodePro-Bold.ttf';

type Props = {
store: Store;
};

const App = ({ store }: Props) => (
const App = () => (
<Provider store={store}>
<StyledApp />
</Provider>
);

export default hot(App);
export default App;
4 changes: 2 additions & 2 deletions app/basicComponents/AutocompleteDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Props = {

const AutocompleteDropdown = (props: Props) => {
const { value } = props;
let inputBlurTimer: number;
let inputBlurTimer: any;
const [isOpen, setIsOpen] = useState(false);
const [list, setList] = useState<Array<any>>([]);
const [isFocus, setIsFocus] = useState(-1);
Expand All @@ -109,7 +109,7 @@ const AutocompleteDropdown = (props: Props) => {
const { data, getItemValue } = props;
// @ts-ignore
const { value } = inputField.current || {};
let list = [];
let list: any = [];

if (value && value.trim()) {
list = data.filter((d) => getItemValue(d).toLowerCase().indexOf(value.trim().toLowerCase()) > -1);
Expand Down
6 changes: 1 addition & 5 deletions app/basicComponents/CustomTimeAgo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const enString = {
wordSeparator: ' '
};

type Props = {
time: number;
};

const CustomTimeAgo = ({ time }: Props) => {
const CustomTimeAgo = ({ time }: { time: string }) => {
const jsDate = new Date(time).getTime();

const formatter = buildFormatter(enString);
Expand Down
4 changes: 2 additions & 2 deletions app/basicComponents/SmallHorizontalPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const Wrapper = styled.img`
right: 0px;
width: 60px;
height: 15px;
transform: ${({ reflection }) => (reflection ? `scale(-1, 1)` : `none`)};
transform: ${({ theme }) => (theme.isDarkMode ? `scale(-1, 1)` : `none`)};
`;

type Props = {
isDarkMode: boolean;
};

const SmallHorizontalPanel = ({ isDarkMode }: Props) => <Wrapper reflection={isDarkMode} src={isDarkMode ? horizontalPanelBlack : horizontalPanelWhite} />;
const SmallHorizontalPanel = ({ isDarkMode }: Props) => <Wrapper src={isDarkMode ? horizontalPanelBlack : horizontalPanelWhite} />;

export default SmallHorizontalPanel;
31 changes: 17 additions & 14 deletions app/components/NetworkStatus/NetworkStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import styled from 'styled-components';
import { NetworkIndicator, ProgressBar } from '../../basicComponents';
import { Status } from '../../types';
import { smColors } from '../../vars';

const ProgressLabel = styled.div`
margin-left: 10px;
text-transform: uppercase;
`;

const Progress = styled.div`
Expand All @@ -14,14 +17,14 @@ const Progress = styled.div`
`;

type Props = {
nodeIndicator: { hasError: boolean; color: string; message: string; statusText: string };
status?: any;
status: Status | null;
error: any;
};

const NetworkStatus = ({ nodeIndicator, status }: Props) => {
const NetworkStatus = ({ status, error }: Props) => {
const getSyncLabelPercentage = (): number => {
if (status && status.syncedLayer && status.currentLayer) {
return Math.round((parseInt(status.syncedLayer) * 100) / parseInt(status.currentLayer));
if (status && status.syncedLayer && status.topLayer) {
return Math.round((status.syncedLayer * 100) / status.topLayer);
}
return 0;
};
Expand All @@ -32,15 +35,15 @@ const NetworkStatus = ({ nodeIndicator, status }: Props) => {
<>
{progress >= 100 ? (
<>
<NetworkIndicator color={nodeIndicator.color} />
<ProgressLabel>{nodeIndicator.statusText}</ProgressLabel>
<NetworkIndicator color={smColors.green} />
<ProgressLabel>synced</ProgressLabel>
</>
) : (
<>
<NetworkIndicator color={nodeIndicator.color} />
<ProgressLabel>{nodeIndicator.statusText}</ProgressLabel>
<NetworkIndicator color={status?.isSynced ? smColors.green : smColors.orange} />
<ProgressLabel>syncing</ProgressLabel>
<ProgressLabel>{getSyncLabelPercentage()}%</ProgressLabel>
<ProgressLabel>{`${status?.syncedLayer || 0} / ${status?.currentLayer || 0}`}</ProgressLabel>
<ProgressLabel>{`${status?.syncedLayer || 0} / ${status?.topLayer || 0}`}</ProgressLabel>
<Progress>
<ProgressBar progress={progress} />
</Progress>
Expand All @@ -50,14 +53,14 @@ const NetworkStatus = ({ nodeIndicator, status }: Props) => {
);
};

const renderStatus = () => (
const renderError = () => (
<>
<NetworkIndicator color={nodeIndicator.color} />
<ProgressLabel>{nodeIndicator.statusText}</ProgressLabel>
<NetworkIndicator color={smColors.red} />
<ProgressLabel>Please restart node</ProgressLabel>
</>
);

return nodeIndicator.hasError ? renderStatus() : renderSyncingStatus();
return error ? renderError() : renderSyncingStatus();
};

export default NetworkStatus;
15 changes: 5 additions & 10 deletions app/components/banners/InfoBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { useSelector } from 'react-redux';
import { Banner } from '../../basicComponents';
import { smColors } from '../../vars';
import { RootState } from '../../types';

const Text = styled.div`
margin: 0 15px;
Expand All @@ -12,13 +10,10 @@ const Text = styled.div`
color: ${smColors.white};
`;

const InfoBanner = () => {
const nodeIndicator = useSelector((state: RootState) => state.node.nodeIndicator);
return (
<Banner margin={'30px 0 30px 0'} color={nodeIndicator.color} visibility={!!nodeIndicator.hasError}>
<Text>{nodeIndicator.message}</Text>
</Banner>
);
};
const InfoBanner = () => (
<Banner margin={'30px 0 30px 0'} color={smColors.red}>
<Text>Offline. Please quit and start the app again.</Text>
</Banner>
);

export default InfoBanner;
8 changes: 5 additions & 3 deletions app/components/contacts/CreateNewContact.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import styled from 'styled-components';
import { addToContacts, updateTransaction } from '../../redux/wallet/actions';
import { addToContacts } from '../../redux/wallet/actions';
import { EnterPasswordModal } from '../settings';
import { Input, Link, ErrorPopup } from '../../basicComponents';
import { smColors } from '../../vars';
import { Contact, RootState } from '../../types';
import { eventsService } from '../../infra/eventsService';

const Wrapper = styled.div<{ isStandalone: boolean }>`
display: flex;
Expand Down Expand Up @@ -80,6 +81,7 @@ const CreateNewContact = ({ isStandalone = false, initialAddress = '', onComplet
const [shouldShowPasswordModal, setShouldShowPasswordModal] = useState(false);

const contacts = useSelector((state: RootState) => state.wallet.contacts);
const currentAccountIndex = useSelector((state: RootState) => state.wallet.currentAccountIndex);
const dispatch = useDispatch();

// static getDerivedStateFromProps(props: Props, prevState: State) {
Expand Down Expand Up @@ -123,8 +125,8 @@ const CreateNewContact = ({ isStandalone = false, initialAddress = '', onComplet
};

const createContact = async ({ password }: { password: string }) => {
await dispatch(addToContacts({ password, contact: { address, nickname } }));
dispatch(updateTransaction({ newData: { address, nickname } }));
await dispatch(await addToContacts({ password, contact: { address, nickname } }));
await eventsService.updateTransaction({ newData: { address, nickname }, accountIndex: currentAccountIndex, txId: '' });
onCompleteAction();
};

Expand Down
22 changes: 11 additions & 11 deletions app/components/node/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const CpuIcon = styled.img`
`;

type Props = {
data: Array<{ company: string; name: string; isGPU: boolean; estimation: string }>;
data: { id: number; model: string; computeApi: string; performance: number }[];
selectedItemIndex: number;
onClick: ({ index }: { index: number }) => void;
style?: any;
Expand Down Expand Up @@ -179,23 +179,23 @@ const Carousel = ({ data, selectedItemIndex, onClick, style }: Props) => {
/>
<OuterWrapper style={style}>
<InnerWrapper leftSlideIndex={carouselState.leftSlideIndex} slidesCount={data.length}>
{data.map((element, index) => (
<SlideWrapper onClick={() => handleSelection({ index })} key={element.name}>
{data.map((provider, index) => (
<SlideWrapper onClick={() => handleSelection({ index })} key={provider.id}>
<SlideUpperPart isSelected={selectedItemIndex === index}>
<TextWrapper>
<Text>{element.company}</Text>
<Text>{element.name}</Text>
<Text>{provider.model}</Text>
{provider.computeApi === '0' && <Text>(UNSPECIFIED)</Text>}
{provider.computeApi === '1' && <Text>(CPU)</Text>}
{provider.computeApi === '2' && <Text>(CUDA)</Text>}
{provider.computeApi === '3' && <Text>(VULCAN)</Text>}
<Text>--</Text>
</TextWrapper>
<TextWrapper>
<Text>~{element.estimation}</Text>
<Text>~{provider.performance} hashes per second</Text>
<Text>TO SAVE DATA</Text>
</TextWrapper>
{element.isGPU ? (
<GpuIcon src={selectedItemIndex === index ? posGpuActive : posGpuGrey} />
) : (
<CpuIcon src={selectedItemIndex === index ? posCpuActive : posCpuGrey} />
)}
{provider.computeApi === '1' && <CpuIcon src={selectedItemIndex === index ? posCpuActive : posCpuGrey} />}
{(provider.computeApi === '2' || provider.computeApi === '3') && <GpuIcon src={selectedItemIndex === index ? posGpuActive : posGpuGrey} />}
</SlideUpperPart>
<SlideMiddlePart />
<SlideLowerPart isSelected={selectedItemIndex === index} />
Expand Down
25 changes: 13 additions & 12 deletions app/components/node/PoSDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,29 @@ const linkStyle = { fontSize: '17px', lineHeight: '19px', marginBottom: 5 };

type Props = {
nextAction: () => void;
folder: string;
setFolder: (folder: string) => void;
freeSpace: number;
setFreeSpace: (freeSpace: number) => void;
commitmentSize: number;
dataDir: string;
setDataDir: (dataDir: string) => void;
freeSpace: string;
setFreeSpace: (freeSpace: string) => void;
minCommitmentSize: string;
status: Status | null;
isDarkMode: boolean;
skipAction: () => void;
};

const PoSDirectory = ({ skipAction, nextAction, folder, setFolder, freeSpace, setFreeSpace, commitmentSize, status, isDarkMode }: Props) => {
// const PoSDirectory = ({ , nextAction, folder, setFolder, freeSpace, setFreeSpace, commitmentSize, status, isDarkMode }: Props) => {
const PoSDirectory = ({ nextAction, skipAction, dataDir, setDataDir, freeSpace, setFreeSpace, minCommitmentSize, status, isDarkMode }: Props) => {
const [hasPermissionError, setHasPermissionError] = useState(false);

const icon = isDarkMode ? posDirectoryWhite : posDirectoryBlack;

const openFolderSelectionDialog = async () => {
const { error, selectedFolder, freeSpace } = await eventsService.selectPostFolder();
const { error, selectedFolder, calculatedFreeSpace } = await eventsService.selectPostFolder();
if (error) {
setHasPermissionError(true);
} else {
setFolder(selectedFolder);
setFreeSpace(formatBytes(freeSpace));
setDataDir(selectedFolder);
setFreeSpace(formatBytes(calculatedFreeSpace));
setHasPermissionError(false);
}
};
Expand All @@ -101,14 +102,14 @@ const PoSDirectory = ({ skipAction, nextAction, folder, setFolder, freeSpace, se
<HeaderIcon src={icon} />
<Header>Proof of space data directory:</Header>
</HeaderWrapper>
<Link onClick={openFolderSelectionDialog} text={folder || 'SELECT DIRECTORY'} style={linkStyle} />
<ErrorText>{hasPermissionError ? `SELECT FOLDER WITH MINIMUM ${commitmentSize} GB FREE TO PROCEED` : ''}</ErrorText>
<Link onClick={openFolderSelectionDialog} text={dataDir || 'SELECT DIRECTORY'} style={linkStyle} />
<ErrorText>{hasPermissionError ? `SELECT FOLDER WITH MINIMUM ${minCommitmentSize} GB FREE TO PROCEED` : ''}</ErrorText>
{!!freeSpace && <FreeSpaceHeader>FREE SPACE...</FreeSpaceHeader>}
<FreeSpace error={hasPermissionError} selected={!!freeSpace}>
{freeSpace ? `${freeSpace} GB` : ''}
</FreeSpace>
</Wrapper>
<PoSFooter skipAction={skipAction} action={nextAction} isDisabled={!folder || hasPermissionError || !status} />
<PoSFooter action={nextAction} skipAction={skipAction} isDisabled={!dataDir || hasPermissionError || !status} />
</>
);
};
Expand Down
61 changes: 0 additions & 61 deletions app/components/node/PoSProcessor.tsx

This file was deleted.

Loading

0 comments on commit 9e85438

Please sign in to comment.