Skip to content

Commit

Permalink
Migrate to dpos-offline@v3 #230
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiaszCudnik committed Jun 18, 2019
1 parent 32ae7cf commit c64cd17
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 150 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -22,7 +22,6 @@
"classnames": "^2.2.6",
"delay": "^4.1.0",
"downshift": "^3.1.7",
"dpos-api-wrapper": "^1.3.2",
"dpos-ledger-api": "^3.0.1",
"dpos-offline": "^3.0.2",
"inobounce": "^0.1.6",
Expand Down
34 changes: 22 additions & 12 deletions src/components/DelegateVoteComponent.tsx
Expand Up @@ -8,7 +8,7 @@ import {
} from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import * as classNames from 'classnames';
import { Delegate } from 'dpos-api-wrapper';
import { Delegate, DelegateInfos } from 'risejs/dist/es5/types/beans';
import { observer } from 'mobx-react';
import * as React from 'react';
import { defineMessages, InjectedIntlProps, injectIntl } from 'react-intl';
Expand Down Expand Up @@ -76,7 +76,11 @@ const styles = (theme: Theme) =>

interface Props extends WithStyles<typeof styles> {
onSubmit: (delegate: Delegate, addVote: boolean) => void;
delegate: Delegate | null;
delegate:
| Delegate & {
infos: DelegateInfos;
}
| null;
hasVote: boolean;
isLoading: boolean;
}
Expand Down Expand Up @@ -140,7 +144,7 @@ class DelegateVoteComponent extends React.Component<DecoratedProps> {
if (delegate) {
onSubmit(delegate, !hasVote);
}
}
};

render() {
const { intl, classes, delegate, hasVote, isLoading } = this.props;
Expand All @@ -151,15 +155,21 @@ class DelegateVoteComponent extends React.Component<DecoratedProps> {
? {
username: delegate.username,
address: delegate.address,
rank: intl.formatNumber(delegate.rank),
uptime: intl.formatNumber(delegate.productivity / 100, {
style: 'percent',
maximumFractionDigits: 2
}),
approval: intl.formatNumber(delegate.approval / 100, {
style: 'percent',
maximumFractionDigits: 2
})
rank: intl.formatNumber(delegate.infos.rankV2),
uptime: intl.formatNumber(
parseInt(delegate.infos.productivity, 10) / 100,
{
style: 'percent',
maximumFractionDigits: 2
}
),
approval: intl.formatNumber(
parseInt(delegate.infos.approval, 10) / 100,
{
style: 'percent',
maximumFractionDigits: 2
}
)
}
: {
username: 'N/A',
Expand Down
2 changes: 1 addition & 1 deletion src/components/TxDetailsExpansionPanel.tsx
Expand Up @@ -20,7 +20,7 @@ import PersonAddIcon from '@material-ui/icons/PersonAdd';
import LinkIcon from '@material-ui/icons/Link';
import ContentCopyIcon from 'mdi-material-ui/ContentCopy';
import * as classNames from 'classnames';
import { TransactionType } from 'dpos-api-wrapper';
import { TransactionType } from 'risejs/dist/es5/types/beans';
import * as moment from 'moment/min/moment-with-locales';
import * as React from 'react';
import { defineMessages, InjectedIntlProps, injectIntl } from 'react-intl';
Expand Down
22 changes: 15 additions & 7 deletions src/components/content/VoteDelegateDialogContent.tsx
Expand Up @@ -8,7 +8,7 @@ import {
WithStyles,
withStyles
} from '@material-ui/core/styles';
import { Delegate } from 'dpos-api-wrapper';
import { Delegate, DelegateInfos } from 'risejs/dist/es5/types/beans';
import { range } from 'lodash';
import * as React from 'react';
import { ReactEventHandler } from 'react';
Expand Down Expand Up @@ -64,13 +64,21 @@ const messages = defineMessages({

type SuggestionsContent = {
kind: 'suggestions';
delegates: Delegate[];
delegates: Array<
Delegate & {
infos: DelegateInfos;
}
>;
};

type ResultsContent = {
kind: 'search-results';
query: string;
delegates: Delegate[];
delegates: Array<
Delegate & {
infos: DelegateInfos;
}
>;
};

type ErrorContent = {
Expand All @@ -88,7 +96,7 @@ interface Props extends BaseProps, ICloseInterruptFormProps {
// TODO rename to onSubmit
onSelect: (delegate: Delegate) => void;
isLoading: boolean;
votedDelegate: null | Delegate;
votedDelegate: Delegate | null;
voteFee: RawAmount;
content: Content;
}
Expand All @@ -103,7 +111,7 @@ class VoteDelegateDialogContent extends React.Component<DecoratedProps> {
const { onQueryChange, onFormChanged } = this.props;
onQueryChange(query);
onFormChanged(Boolean(query));
}
};

componentWillMount() {
const { intl } = this.props;
Expand Down Expand Up @@ -142,7 +150,7 @@ class VoteDelegateDialogContent extends React.Component<DecoratedProps> {
id="vote-delegate-dialog-content.insufficient-funds-error"
description="Error about not having enough funds to vote for a delegate"
defaultMessage={
'You don\'t have enough funds in your account to pay the' +
"You don't have enough funds in your account to pay the" +
' network fee of {fee} for casting a vote for a delegate!'
}
values={{
Expand Down Expand Up @@ -208,7 +216,7 @@ class VoteDelegateDialogContent extends React.Component<DecoratedProps> {
const delegate = content.delegates[n] || null;
const hasVote =
delegate && votedDelegate
? delegate.publicKey === votedDelegate.publicKey
? delegate.forgingPK === votedDelegate.forgingPK
: false;
return (
<Grid
Expand Down
24 changes: 14 additions & 10 deletions src/containers/wallet/VoteDelegateDialog.tsx
@@ -1,4 +1,4 @@
import { Delegate } from 'dpos-api-wrapper';
import { Delegate, DelegateInfos } from 'risejs/dist/es5/types/beans';
import { throttle, sampleSize } from 'lodash';
import { reaction, IReactionDisposer, observe, Lambda } from 'mobx';
import { inject, observer } from 'mobx-react';
Expand Down Expand Up @@ -36,7 +36,11 @@ interface State extends ICloseInterruptControllerState {
search: {
isLoading: boolean;
query: string;
delegates: Delegate[];
delegates: Array<
Delegate & {
infos: DelegateInfos;
}
>;
};
transaction: null | {
add: string[];
Expand Down Expand Up @@ -145,7 +149,7 @@ class VoteDelegateDialog extends React.Component<Props, State>
delegates: match ? [match] : []
}
});
}
};

handleClose = (ev: React.SyntheticEvent<{}>) => {
// @ts-ignore
Expand All @@ -160,18 +164,18 @@ class VoteDelegateDialog extends React.Component<Props, State>
const { store, navigateBackLink } = this.injected;
store.navigateTo(navigateBackLink);
return false;
}
};

handleFormChanged = (changed: boolean) => {
this.setState({ formChanged: changed });
}
};

handleNavigateBack = (ev: React.SyntheticEvent<{}>) => {
this.setState({
step: 'vote',
transaction: null
});
}
};

handleQueryChange = (query: string) => {
this.setState({ query });
Expand All @@ -180,7 +184,7 @@ class VoteDelegateDialog extends React.Component<Props, State>
} else {
this.suggestDelegates();
}
}
};

handleSelectDelegate = (delegate: Delegate) => {
const { account } = this.injected;
Expand All @@ -195,7 +199,7 @@ class VoteDelegateDialog extends React.Component<Props, State>
let addNames = [];

const isRemoveTx =
votedDelegate && votedDelegate.publicKey === delegate.publicKey;
votedDelegate && votedDelegate.forgingPK === delegate.forgingPK;
if (votedDelegate) {
removeNames.push(votedDelegate.username);
}
Expand All @@ -211,7 +215,7 @@ class VoteDelegateDialog extends React.Component<Props, State>
delegate
}
});
}
};

suggestDelegates() {
const { walletStore } = this.injected;
Expand All @@ -237,7 +241,7 @@ class VoteDelegateDialog extends React.Component<Props, State>
} else {
throw new Error('Invalid internal state');
}
}
};

resetState() {
this.setState({
Expand Down
2 changes: 1 addition & 1 deletion src/stores/account.ts
@@ -1,5 +1,5 @@
import * as assert from 'assert';
import { Delegate } from 'dpos-api-wrapper';
import { Delegate } from 'risejs/dist/es5/types/beans';
import { action, observable, runInAction } from 'mobx';
import * as lstore from 'store';
import { TConfig } from './index';
Expand Down
17 changes: 10 additions & 7 deletions src/stores/fixtures.ts
Expand Up @@ -132,7 +132,7 @@ export const serverTransactionsUnconfirmed = {
blockId: '8968901776605570983',
type: 0,
timestamp: 73261827,
senderPublicKey:
senderPubData:
'491e09b538aa8d44a613bc5d23e2b6a4f93126b89c8fb8766016708af519fded',
senderId: '5932278668828702947R',
recipientId: '5399275477602875017R',
Expand Down Expand Up @@ -161,7 +161,7 @@ export const serverTransactionsConfirmed = {
blockId: '12571019205669775789',
type: 3,
timestamp: 76189352,
senderPublicKey:
senderPubData:
'023bab3e17365565d7a796291f8d3bb6878a3083ea520fbd163db713d51b44f9',
senderId: '5932278668828702947R',
recipientId: '5932278668828702947R',
Expand All @@ -187,7 +187,7 @@ export const serverTransactionsConfirmed = {
blockId: '8968901776605570982',
type: 0,
timestamp: 73261826,
senderPublicKey:
senderPubData:
'491e09b538aa8d44a613bc5d23e2b6a4f93126b89c8fb8766016708af519fded',
senderId: '5932278668828702947R',
recipientId: '5399275477602875017R',
Expand All @@ -209,7 +209,7 @@ export const serverTransactionsConfirmed = {
blockId: '15315325139361767746',
type: 1,
timestamp: 73261262,
senderPublicKey:
senderPubData:
'491e09b538aa8d44a613bc5d23e2b6a4f93126b89c8fb8766016708af519fded',
senderId: '5932278668828702947R',
recipientId: null,
Expand All @@ -235,7 +235,7 @@ export const serverTransactionsConfirmed = {
blockId: '2652299302775213052',
type: 0,
timestamp: 73261232,
senderPublicKey:
senderPubData:
'491e09b538aa8d44a613bc5d23e2b6a4f93126b89c8fb8766016708af519fded',
senderId: '5932278668828702947R',
recipientId: '2655711995542512317R',
Expand All @@ -256,7 +256,7 @@ export const serverTransactionsConfirmed = {
blockId: '1577621231331325441',
type: 0,
timestamp: 73260039,
senderPublicKey:
senderPubData:
'1db1a4d79853b86f438ad647743775788ed3f4f75ff698ecb2155e711e1137fe',
senderId: '4221970229545791184R',
recipientId: '5932278668828702947R',
Expand All @@ -273,6 +273,7 @@ export const serverTransactionsConfirmed = {
]
};

// TODO add `infos`
export const serverDelegatesSearch = {
success: true,
delegates: [
Expand Down Expand Up @@ -391,6 +392,7 @@ export const serverDelegatesSearch = {
]
};

//TODO add `infos`
export const serverAccountsDelegates = {
success: true,
delegates: [
Expand All @@ -410,6 +412,7 @@ export const serverAccountsDelegates = {
]
};

//TODO add `infos`
export const serverDelegatesGetByPublicKey = {
success: true,
delegate: {
Expand Down Expand Up @@ -439,7 +442,7 @@ export const serverTransactionDelegates = {
blockId: '5037878439790225029',
type: 3,
timestamp: 69547438,
senderPublicKey:
senderPubData:
'023bab3e17365565d7a796291f8d3bb6878a3083ea520fbd163db713d51b44f9',
senderId: '2655711995542512317R',
recipientId: '2655711995542512317R',
Expand Down
2 changes: 1 addition & 1 deletion src/stores/ledger.ts
Expand Up @@ -7,7 +7,7 @@ import {
LedgerAccount as DposAccount
} from 'dpos-ledger-api';
import { CommHandler } from 'dpos-ledger-api/dist/es5/commHandler';
import { Rise } from 'dpos-offline';
import { RiseV2 as Rise } from 'dpos-offline';
import { observable, runInAction, action } from 'mobx';
import * as React from 'react';
import { As } from 'type-tagger';
Expand Down
8 changes: 5 additions & 3 deletions src/stores/transactions.test.ts
Expand Up @@ -14,7 +14,9 @@ import {
import TransactionsStore, { Transaction } from './transactions';
import WalletStore, { parseTransactionsResponse } from './wallet';
import * as sinon from 'sinon';
import { TransactionType } from 'risejs';
import {
TransactionType,
} from 'risejs/dist/es5/types/beans';

let stubs: sinon.SinonStub[];

Expand Down Expand Up @@ -102,7 +104,7 @@ describe('TransactionsStore', () => {
senderId: '2655711995542512317R',
type: 0,
amount: 100000000,
senderPublicKey:
senderPubData:
'023bab3e17365565d7a796291f8d3bb6878a3083ea520fbd163db713d51b44f9',
requesterPublicKey: null,
timestamp: 1548772228000,
Expand Down Expand Up @@ -167,7 +169,7 @@ describe('Transaction class', () => {
'relays',
'receivedAt',
'type',
'senderPublicKey',
'senderPubData',
'requesterPublicKey',
'asset',
'recipientId',
Expand Down
6 changes: 3 additions & 3 deletions src/stores/transactions.ts
Expand Up @@ -2,7 +2,7 @@ import { groupBy } from 'lodash';
import { computed, observable, runInAction, action } from 'mobx';
import * as moment from 'moment/min/moment-with-locales';
import { defineMessages } from 'react-intl';
import { TransactionType } from 'risejs';
import { TransactionType } from 'risejs/dist/es5/types/beans';
import * as lstore from 'store';
import { RawAmount } from '../utils/amounts';
import { TConfig } from './index';
Expand Down Expand Up @@ -204,7 +204,7 @@ export class Transaction {
recipientId?: string;
recipientPublicKey?: string;
senderId: string;
senderPublicKey: string;
senderPubData: string;
signature: string;
// TODO
// tslint:disable-next-line:no-any
Expand Down Expand Up @@ -238,7 +238,7 @@ export class Transaction {
'receivedAt',
'type',
'amount',
'senderPublicKey',
'senderPubData',
'requesterPublicKey',
'timestamp',
'asset',
Expand Down

0 comments on commit c64cd17

Please sign in to comment.