Skip to content

Commit 2d6c47c

Browse files
Merge pull request #64 from OpenFuturePlatform/key-management
Ip Filter
2 parents 8907ae4 + a2ce0f5 commit 2d6c47c

16 files changed

Lines changed: 165 additions & 133 deletions

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ dependencies {
5959
// Utils
6060
implementation('commons-io:commons-io:2.8.0')
6161
implementation 'org.apache.commons:commons-lang3:3.6'
62-
implementation group: 'commons-net', name: 'commons-net', version: '3.6'
63-
6462

6563
// Test
6664
testImplementation('org.springframework.boot:spring-boot-starter-test')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {apiDelete, apiGet, apiPost} from "./apiRequest";
2+
import {getGatewayApplicationWalletsPath} from "../utils/apiPathes";
3+
import {FETCH_GATEWAY_APPLICATION_WALLET} from "./types";
4+
import {parseApiError} from "../utils/parseApiError";
5+
6+
export const getGatewayApplicationWallet = (gatewayId) => async dispatch => {
7+
const wallets = await dispatch(apiGet(getGatewayApplicationWalletsPath(gatewayId), {}));
8+
dispatch({ type: FETCH_GATEWAY_APPLICATION_WALLET, payload: {gatewayId, wallets} });
9+
};
10+
11+
export const generateGatewayApplicationWallet = (wallet, blockchain) => async (dispatch) => {
12+
await dispatch(apiPost(getGatewayApplicationWalletsPath(), {applicationId: wallet.applicationId, webHook: wallet.webHook, blockchainType: blockchain.blockchain}));
13+
dispatch(getGatewayApplicationWallet(wallet.applicationId));
14+
};
15+
16+
export const removeGatewayApplicationWallet = (gatewayId, address) => async dispatch => {
17+
try {
18+
await dispatch(apiDelete( getGatewayApplicationWalletsPath()+"?applicationId="+gatewayId+"&address="+address, {}));
19+
await dispatch(getGatewayApplicationWallet(gatewayId));
20+
} catch (e) {
21+
throw parseApiError(e);
22+
}
23+
};

frontend/src/actions/gateways.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SHOW_MODAL
1010
} from "./types";
1111
import {parseApiError} from "../utils/parseApiError";
12+
import {getGatewayApplicationWallet} from "./gateway-wallet";
1213

1314

1415
export const fetchGatewayApplications = (offset = 0, limit = 10) => async dispatch => {
@@ -31,14 +32,14 @@ export const saveGatewayApplication = formValues => async (dispatch) => {
3132
await dispatch(apiPost(getGatewayApplicationsPath(), formValues));
3233
};
3334

34-
export const fetchGatewayApplicationDetails = (id) => async dispatch => {
35+
export const fetchGatewayApplicationDetailsFromApi = (id) => async dispatch => {
3536
dispatch({ type: SET_GATEWAY_APPLICATION_SET, payload: { id, loading: true } });
3637

3738
try {
3839
const gateway = await dispatch(apiGet(getGatewayApplicationsPath(id)));
39-
const wallets = await dispatch(getGatewayApplicationWallet(id));
40+
4041
const error = '';
41-
const payload = { id, gateway, wallets, error, loading: false };
42+
const payload = { id, gateway, error, loading: false };
4243
dispatch({ type: SET_GATEWAY_APPLICATION_SET, payload });
4344

4445
} catch (e) {
@@ -50,6 +51,11 @@ export const fetchGatewayApplicationDetails = (id) => async dispatch => {
5051
}
5152
};
5253

54+
export const fetchGatewayApplicationDetails = (id) => async dispatch => {
55+
dispatch(fetchGatewayApplicationDetailsFromApi(id));
56+
dispatch(getGatewayApplicationWallet(id));
57+
};
58+
5359
export const removeGatewayApplication = (id) => async dispatch => {
5460
try {
5561
await dispatch(apiDelete(getGatewayApplicationsPath()+"?id="+id, {}));
@@ -59,23 +65,3 @@ export const removeGatewayApplication = (id) => async dispatch => {
5965
}
6066
};
6167

62-
export const getGatewayApplicationWallet = (gatewayId) => async dispatch => {
63-
const wallets = await dispatch(apiGet(getGatewayApplicationWalletsPath(gatewayId), {}));
64-
const error = '';
65-
dispatch({ type: SET_GATEWAY_APPLICATION_SET, payload: {gatewayId, wallets, error, loading: false} });
66-
return wallets;
67-
};
68-
69-
export const generateGatewayApplicationWallet = (wallet, blockchain) => async (dispatch) => {
70-
await dispatch(apiPost(getGatewayApplicationWalletsPath(), {applicationId: wallet.applicationId, webHook: wallet.webHook, blockchainType: blockchain.blockchain}));
71-
dispatch(fetchGatewayApplicationDetails(wallet.applicationId))
72-
};
73-
74-
export const removeGatewayApplicationWallet = (gatewayId, address) => async dispatch => {
75-
try {
76-
await dispatch(apiDelete( getGatewayApplicationWalletsPath()+"?applicationId="+gatewayId+"&address="+address, {}));
77-
await dispatch(fetchGatewayApplicationDetails(gatewayId))
78-
} catch (e) {
79-
throw parseApiError(e);
80-
}
81-
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, {Component} from "react";
2+
import {Button, Divider, Dropdown, Input, Modal} from "semantic-ui-react";
3+
4+
import {withVisible} from "../components-ui/withVisible";
5+
import {withSaving} from "../components-ui/withSaving";
6+
import styled from "styled-components";
7+
import {t} from "../utils/messageTexts";
8+
import {Datepicker} from "../components-ui/Datepicker";
9+
10+
11+
const KeyGenerateContainer = styled.div`
12+
overflow: hidden;
13+
padding-bottom: 15px;
14+
`;
15+
16+
class GatewayApplicationKeyGenerateComponent extends Component {
17+
state = {
18+
expiredDate: null,
19+
gatewayId : null
20+
};
21+
22+
onShow = () => {
23+
const { onShow, gateway } = this.props;
24+
25+
this.setState({gatewayId: gateway.id });
26+
27+
onShow();
28+
};
29+
30+
onBackgroundClick = e => {
31+
const { onHide, isSaving } = this.props;
32+
const target = e.target;
33+
if (isSaving || !target.classList.contains('modals')) {
34+
return;
35+
}
36+
onHide();
37+
};
38+
39+
onSubmit = async () => {
40+
const { submitWithSaving } = this.props;
41+
const { expiredDate, gatewayId } = this.state;
42+
this.setState({ isSaving: true });
43+
44+
submitWithSaving({ expiredDate: expiredDate, gatewayId: gatewayId });
45+
};
46+
47+
render() {
48+
const { isVisible, onHide, isSaving } = this.props;
49+
50+
return (
51+
<KeyGenerateContainer>
52+
<Button primary type="button" floated="right" onClick={this.onShow}>
53+
Generate New Key
54+
</Button>
55+
<Modal size="tiny" open={isVisible} onClose={this.onBackgroundClick}>
56+
<Modal.Header>Generate Application Key</Modal.Header>
57+
<Modal.Content>
58+
<Datepicker date={this.state.expiredDate} onChange={expiredDate => this.setState({ expiredDate })} />
59+
</Modal.Content>
60+
<Modal.Actions>
61+
<Button negative disabled={isSaving} onClick={onHide}>
62+
Cancel
63+
</Button>
64+
<Button
65+
positive
66+
loading={isSaving}
67+
icon="checkmark"
68+
labelPosition="right"
69+
content="Generate"
70+
onClick={this.onSubmit}
71+
/>
72+
</Modal.Actions>
73+
</Modal>
74+
</KeyGenerateContainer>
75+
);
76+
}
77+
}
78+
79+
export const GatewayKeyGenerate = withVisible(withSaving(GatewayApplicationKeyGenerateComponent));

frontend/src/components/GatewayApplicationList.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {ProjectPagination} from '../components-ui/ProjectPagination';
55
import {GATEWAY_LIMIT} from '../const';
66
import {
77
fetchGatewayApplications,
8-
getGatewayApplicationWallet,
98
removeGatewayApplication
109
} from "../actions/gateways";
1110
import {GatewayApplicationRemove} from "./GatewayApplicationRemove";
@@ -26,8 +25,6 @@ class GatewayApplicationList extends Component {
2625
this.props.removeGatewayApplication(gateway.id);
2726
}
2827

29-
onFetchWallet = gateway => this.props.getGatewayApplicationWallet(gateway.id)
30-
3128
renderApplications() {
3229
const gateways = this.props.gateways;
3330

@@ -81,7 +78,6 @@ export default connect(
8178
mapStateToProps,
8279
{
8380
fetchGatewayApplications,
84-
removeGatewayApplication,
85-
getGatewayApplicationWallet
81+
removeGatewayApplication
8682
}
8783
)(GatewayApplicationList);

frontend/src/components/GatewayApplicationWallet.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {connect} from "react-redux";
66

77
import {Table} from "../components-ui/Table";
88
import {WalletGenerate} from "./GatewayApplicationWalletGenerate";
9-
import {generateGatewayApplicationWallet, removeGatewayApplicationWallet} from "../actions/gateways";
9+
import {
10+
generateGatewayApplicationWallet,
11+
getGatewayApplicationWallet,
12+
removeGatewayApplicationWallet
13+
} from "../actions/gateway-wallet";
1014

1115
import {getGatewayWalletSelector} from "../selectors/getGatewayWalletsSelector";
1216

@@ -54,13 +58,13 @@ class GatewayApplicationWalletComponent extends React.Component {
5458
render() {
5559
const { wallets, gateway } = this.props;
5660

57-
const columns = getColumns(wallets, this.onRemoveWallet);
61+
const columns = getColumns(wallets.list, this.onRemoveWallet);
5862
const noDataText = 'No Wallet exist'
5963
return (
6064
<div className="table-with-add">
6165
<WalletGenerate gateway={gateway} onSubmit={this.onGenerateWallet} />
6266
<Segment attached styles={{ padding: 0 }}>
63-
<Table data={wallets} columns={columns} noDataText={noDataText} />
67+
<Table data={wallets.list} columns={columns} noDataText={noDataText} />
6468
</Segment>
6569
</div>
6670
);
@@ -78,4 +82,4 @@ export const GatewayApplicationWallet = connect(
7882
generateGatewayApplicationWallet,
7983
removeGatewayApplicationWallet
8084
}
81-
)(GatewayApplicationWalletComponent);
85+
)(GatewayApplicationWalletComponent);

frontend/src/components/GatewayApplicationWalletGenerate.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, {Component} from "react";
22
import {Button, Divider, Dropdown, Input, Modal} from "semantic-ui-react";
3-
import {Datepicker} from "../components-ui/Datepicker";
4-
import {TransactionError} from "../components-ui/TransactionError";
3+
54
import {withVisible} from "../components-ui/withVisible";
65
import {withSaving} from "../components-ui/withSaving";
76
import styled from "styled-components";
87
import {t} from "../utils/messageTexts";
9-
import {toChecksumAddress} from "../utils/toChecksumAddress";
108

119

1210
const WalletGenerateContainer = styled.div`
@@ -93,4 +91,4 @@ class WalletGenerateComponent extends Component {
9391
}
9492
}
9593

96-
export const WalletGenerate = withVisible(withSaving(WalletGenerateComponent));
94+
export const WalletGenerate = withVisible(withSaving(WalletGenerateComponent));

frontend/src/components/Header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class Header extends Component {
3030
<Dropdown.Item text='Open' as={Link} to={'/scaffolds/open'}/>
3131
</Dropdown.Menu>
3232
</Dropdown>
33-
<Link className="item" to={'/keys'}>
33+
{/*<Link className="item" to={'/keys'}>
3434
Key Management
35-
</Link>
35+
</Link>*/}
3636
<Link className="item" to={'/applications'}>
3737
Applications
3838
</Link>
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import {
2-
SET_GATEWAY_APPLICATION_SET,
2+
FETCH_GATEWAY_APPLICATION_WALLET,
3+
SET_GATEWAY_APPLICATION_SET,
34
} from "../actions/types";
45

6+
const gatewayWalletReducer = (state = {}, action) => {
7+
switch (action.type) {
8+
case FETCH_GATEWAY_APPLICATION_WALLET:
9+
const list = action.payload.wallets;
10+
return { ...state, list};
11+
default:
12+
return state;
13+
}
14+
}
15+
516
export default function(state = {}, action) {
617
switch (action.type) {
718
case SET_GATEWAY_APPLICATION_SET: {
@@ -10,7 +21,13 @@ export default function(state = {}, action) {
1021
const gatewaySet = action.payload;
1122
return { ...state, [gatewayId]: { ...oldGatewaySet, ...gatewaySet } };
1223
}
24+
case FETCH_GATEWAY_APPLICATION_WALLET: {
25+
const gatewayId = action.payload.gatewayId;
26+
const oldGatewaySet = state[gatewayId] || {};
27+
const wallets = gatewayWalletReducer(oldGatewaySet.wallets, action);
28+
return { ...state, [gatewayId]: { ...oldGatewaySet, wallets } };
29+
}
1330
default:
1431
return state;
1532
}
16-
}
33+
}

frontend/src/scenes/GatewayApplicationForm.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {connect} from 'react-redux';
44
import {Field, getFormValues, reduxForm} from 'redux-form';
55
import {withRouter} from 'react-router-dom';
66
import {Button, Grid} from 'semantic-ui-react';
7-
import {DropdownField} from 'react-semantic-redux-form';
87
import {asyncValidate, validate, warn} from '../utils/validation';
9-
import ScaffoldActionField from '../components-ui/inputs/ActionField';
108
import ScaffoldField from '../components-ui/inputs/Field';
119
import {fetchGatewayApplications, saveGatewayApplication} from "../actions/gateways";
1210

0 commit comments

Comments
 (0)