Skip to content
This repository has been archived by the owner on Dec 19, 2020. It is now read-only.

Commit

Permalink
close button, search, menu, reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Pechalka committed Dec 12, 2018
1 parent c335a9d commit 3bae9fb
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 72 deletions.
7 changes: 5 additions & 2 deletions src/RootRegistry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import connect from 'react-redux/es/connect/connect';
import { Title } from '@cybercongress/ui';
import { addRegistryItem, deleteRegistryItem, getRegistryItemsAsArray } from './redux/rootRegistry';
import { addRegistryItem, deleteRegistryItem, getRegistryItemsAsArray, resetToDefault } from './redux/rootRegistry';

import Button from './components/Button/Button';
import Input from './components/Input/Input';
Expand Down Expand Up @@ -49,7 +49,9 @@ class RootRegistryPage extends Component {
<RootRegistry>

<Title>/Cyb root registry</Title>

<div style={{ paddingBottom: 20 }}>
<Button onClick={this.props.resetToDefault}>RESET TO DEFAULT</Button>
</div>
<div>
<Table>
<thead>
Expand Down Expand Up @@ -94,5 +96,6 @@ export default connect(
{
addRegistryItem,
deleteRegistryItem,
resetToDefault,
},
)(RootRegistryPage);
2 changes: 1 addition & 1 deletion src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Settings extends Component {
<BlockRow>
<SettingRow>
<Button color='green' dura='rr.cyb'>CYB ROOT REGISTRY</Button>
<Button onClick={ resetAllSettings }>RESET ALL SETTINGS</Button>
<Button onClick={ resetAllSettings }>RESET SETTINGS</Button>
</SettingRow>
</BlockRow>
</Block>
Expand Down
11 changes: 11 additions & 0 deletions src/components/AppMenu/AppMenu.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@
text-align: center;
}

.CloseButton {
position: absolute;
right: 15px;
top: 15px;
width: 24px;
height: 24px;
font-size: 0;
border: none;
background: url(./close.svg);
cursor: pointer;
}
4 changes: 4 additions & 0 deletions src/components/AppMenu/AppMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const Bookmarks = ({ items, deleteMenuItem }) => (
</div>
);

export const CloseButton = props => (
<button type='button' { ...props } className='CloseButton'>close</button>
);


export const ReportLinkContainer = ({ children }) => (
<div className='ReportLinkContainer'>
Expand Down
6 changes: 6 additions & 0 deletions src/components/AppMenu/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/containers/Application/AppMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MenuContainer, {
AddMenuItemReject,
ReportLinkContainer,
AddMenuItemContainer,
CloseButton,
} from '../../components/AppMenu/AppMenu';

class AppMenu extends Component {
Expand Down Expand Up @@ -43,6 +44,7 @@ class AppMenu extends Component {

return (
<MenuContainer openMenu={ openMenu }>
<CloseButton onClick={this.props.toggleMenu} />
<LogoLink onClick={ this.clickLogo } />

<Message
Expand Down
2 changes: 2 additions & 0 deletions src/containers/Application/Status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const Status = ({

const cyberContent = cyberNodeStatus !== 'fail' ? (
<div>
<div>euler-dev0</div>
<hr />
<div>{SEARCH_END_POINT}</div>
</div>
) : (
Expand Down
128 changes: 72 additions & 56 deletions src/cyber/Cyber.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ function Cyber(nodeUrl) {

self.search = function (text) {
return new Promise((resolve) => {

saveInIPFS(ipfs, text)
.then(cid => axios({
method: 'get',
url: `${nodeUrl}/search?cid=${cid}`,
})).then((data) => {

const cids = data.data.result.cids;
const links = cids.map(cid => ({ ...cid, hash: cid.Cid }));

Expand All @@ -80,60 +82,61 @@ function Cyber(nodeUrl) {
};


self.link = function (from, to, address = '') {
return Promise.all([
saveInIPFS(ipfs, from),
saveInIPFS(ipfs, to),
]).then(([_from, _to]) => {
return axios({
method: 'get',
url: `${nodeUrl}/account?address=${address}`,
}).then((response) => {
if (!response.data.result) { return false; }

return response.data.result.account;
}).then((account) => {
if (!account) { return; }

const acc = {
address: account.address,
chain_id: chainId, // todo: get from node
account_number: parseInt(account.account_number, 10),
sequence: parseInt(account.sequence, 10),
};
const linkRequest = {
acc,
fromCid: _from,
toCid: _to,
type: 'link',
};

return axios({
method: 'post',
url: `${nodeUrl}/link`,
data: builder.buildAndSignTxRequest(linkRequest, __accounts[address].privateKey, chainId),
}).then(data => {
console.log('Link results: ', data);

const jsonStr = localStorage.getItem('cyb_transactions' + address) || '[]';
const transactions = JSON.parse(jsonStr);

const newItem = {
txHash: data.data.hash,
date: new Date(),
type: 'cyber',
status: 'pending'
};
const _transactions = transactions.concat([newItem]);
function addTransactionLog(address, txHash, status) {
const jsonStr = localStorage.getItem(`cyb_transactions${address}`) || '[]';
const transactions = JSON.parse(jsonStr);

const newItem = {
txHash,
date: new Date(),
type: 'cyber',
status: 'pending',
};
const newTransactions = transactions.concat([newItem]);

localStorage.setItem(`cyb_transactions${address}`, JSON.stringify(newTransactions));
}

self.link = (from, to, address = '') => Promise.all([
saveInIPFS(ipfs, from),
saveInIPFS(ipfs, to),
]).then(([_from, _to]) => axios({
method: 'get',
url: `${nodeUrl}/account?address=${address}`,
}).then((response) => {
if (!response.data.result) { return false; }

return response.data.result.account;
}).then((account) => {
if (!account) { return; }

const acc = {
address: account.address,
chain_id: chainId, // todo: get from node
account_number: parseInt(account.account_number, 10),
sequence: parseInt(account.sequence, 10),
};
const linkRequest = {
acc,
fromCid: _from,
toCid: _to,
type: 'link',
};

localStorage.setItem('cyb_transactions' + address, JSON.stringify(_transactions));
return axios({
method: 'post',
url: `${nodeUrl}/link`,
data: builder.buildAndSignTxRequest(linkRequest, __accounts[address].privateKey, chainId),
}).then(data => {
console.log('Link results: ', data);

}).catch(error => console.log('Cannot link', error));
});
});
addTransactionLog(address, data.data.hash, 'pending');
}).catch(error => {
console.log('Cannot link', error);


};
// addTransactionLog(address, data.data.hash, 'fail');
});
}));

self.claimFunds = function (address, amount) {
return axios({
Expand All @@ -146,12 +149,25 @@ function Cyber(nodeUrl) {

let __setDefaultAddress;

self.getDefaultAddress = function () {
return new Promise((resolve) => {
__setDefaultAddress = resolve;
resolve(defaultAccount);
self.getDefaultAddress = () => new Promise((resolve) => {
__setDefaultAddress = resolve;

axios({
method: 'get',
url: `${nodeUrl}/account?address=${defaultAccount}`,
}).then(response => response.data.result).then((data) => {
let balance = 0;

if (data && data.account && data.account.account_number >= 0) {
balance = data.account.coins[0].amount;
}

resolve({
address: defaultAccount,
balance: +balance,
});
});
};
});

self.setDefaultAccount = function (_address) {
defaultAccount = _address;
Expand Down
13 changes: 4 additions & 9 deletions src/redux/appMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,19 @@ const initState = {
rootDura: '.wiki/wiki/',
subItems: {},
},
{
name: 'Turkish Wiki',
rootDura: '.ewiki/wiki/Anasayfa.html',
subItems: {},
},
{
name: 'history',
rootDura: 'history.cyb',
subItems: {},
},
{
name: 'test',
rootDura: '.test',
name: 'notifications',
rootDura: 'txq.cyb',
subItems: {},
},
{
name: 'txq',
rootDura: 'txq.cyb',
name: 'IPFS Web UI',
rootDura: '.ipfsview',
subItems: {},
},
],
Expand Down
9 changes: 7 additions & 2 deletions src/redux/rootRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const initState = {
protocol: 'ipfs',
},
cyber: {
hash: 'QmXCCZ7gjbQFRSrTGQ1Vuwf7LWVgv3xbS4eruE4uKrqytc',
hash: 'QmWzAybSUkAcnRdD7gz61pmeSGt8XJYyz4jq6bCc4u8bEB',
protocol: 'ipfs',
},
wiki: {
Expand All @@ -23,7 +23,7 @@ const initState = {
protocol: 'ipfs',
},
chaingear: {
hash: 'QmUuQawnPiRoSevE6MzTygA3ePPPtJKgr7qQHsUwEeuxLA',
hash: 'Qmc5omStXHuc9JNmDwE54AH1htsF5JeqsW8Xk3CAy2wquy',
protocol: 'ipfs',
},
dragons: {
Expand Down Expand Up @@ -112,6 +112,11 @@ export const addRegistryItem = (name, hash, protocol) => (dispatch, getState) =>
resolve(registryItems);
});

export const resetToDefault = () => (dispatch) => {
localStorage.removeItem('rootRegistry');
dispatch(init());
};

const saveRootRegistryItemsInLs = () => (dispatch, getState) => {
const registryItems = getState().rootRegistry.items;

Expand Down
2 changes: 0 additions & 2 deletions src/redux/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export const checkStatus = () => (dispatch, getState) => {

export const resetAllSettings = () => (dispatch, getState) => {
localStorage.removeItem('settings');
localStorage.removeItem('rootRegistry');
// localStorage.removeItem('appMenu');
dispatch(init());
dispatch(checkStatus());
};

0 comments on commit 3bae9fb

Please sign in to comment.