Skip to content

Commit

Permalink
resolve conflicts with MA for voting reg
Browse files Browse the repository at this point in the history
  • Loading branch information
ashisherc committed Jan 18, 2021
1 parent f2a0543 commit 646c0b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 193 deletions.
16 changes: 8 additions & 8 deletions app/components/wallet/voting/VotingRegTxDialog.js
Expand Up @@ -21,17 +21,18 @@ import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import SpendingPasswordInput from '../../widgets/forms/SpendingPasswordInput';
import AmountInputSkin from '../skins/AmountInputSkin';
import { NumericInput } from 'react-polymorph/lib/components/NumericInput';
import {
MultiToken,
} from '../../../api/common/lib/MultiToken';
import { ProgressInfo } from '../../../stores/ada/VotingStore';
import ProgressStepBlock from './ProgressStepBlock';
import WarningBox from '../../widgets/WarningBox';
import { getTokenName, genFormatTokenAmount, } from '../../../stores/stateless/tokenHelpers';
import { calcMaxBeforeDot, } from '../../../utils/validations';
import type {
TokenLookupKey,
} from '../../../api/common/lib/MultiToken';
import type { TokenRow, } from '../../../api/ada/lib/storage/database/primitives/tables';
import { getTokenName, genFormatTokenAmount, } from '../../../stores/stateless/tokenHelpers';

import WarningBox from '../../widgets/WarningBox';
import {
MultiToken,
} from '../../../api/common/lib/MultiToken';

const messages = defineMessages({
line1: {
Expand Down Expand Up @@ -154,8 +155,7 @@ export default class VotingRegTxDialog extends Component<Props> {
// note: we purposely don't put "total" since it doesn't really make sense here
// since the fee is unrelated to the amount you're about to stake
total=""
value={new BigNumber(0).toFormat(tokenInfo.Metadata.numberOfDecimals)
}
value={new BigNumber(0).toFormat(tokenInfo.Metadata.numberOfDecimals)}
skin={AmountInputSkin}
classicTheme={this.props.classicTheme}
/>
Expand Down
178 changes: 10 additions & 168 deletions app/containers/wallet/VotingPage.js
Expand Up @@ -6,22 +6,9 @@ import { computed } from 'mobx';
import { intlShape } from 'react-intl';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import type { InjectedOrGenerated } from '../../types/injectedPropsType';
import Dialog from '../../components/widgets/Dialog';
import DialogCloseButton from '../../components/widgets/DialogCloseButton';
import ErrorBlock from '../../components/widgets/ErrorBlock';
import AnnotatedLoader from '../../components/transfer/AnnotatedLoader';
import type { CreateVotingRegTxFunc } from '../../api/ada/index';
import { SelectedExplorer } from '../../domain/SelectedExplorer';
import LocalizableError from '../../i18n/LocalizableError';
import { PublicDeriver } from '../../api/ada/lib/storage/models/PublicDeriver/index';
import VotingRegTxDialog from '../../components/wallet/voting/VotingRegTxDialog';
import VotingRegSuccessDialog from '../../components/wallet/voting/VotingRegSuccessDialog';
import { WalletTypeOption } from '../../api/ada/lib/storage/models/ConceptualWallet/interfaces';
import { genLookupOrFail } from '../../stores/stateless/tokenHelpers';
import type { TokenInfoMap } from '../../stores/toplevel/TokenInfoStore';

import SpendingPasswordInput from '../../components/widgets/forms/SpendingPasswordInput';
import ReactToolboxMobxForm from '../../utils/ReactToolboxMobxForm';
import Voting from '../../components/wallet/voting/Voting';
import VotingRegistrationDialogContainer from './dialogs/voting/VotingRegistrationDialogContainer';
import type { GeneratedData as VotingRegistrationDialogContainerData } from './dialogs/voting/VotingRegistrationDialogContainer';

export type GeneratedData = typeof VotingPage.prototype.generated;
type Props = {|
Expand All @@ -41,99 +28,13 @@ export default class VotingPage extends Component<Props> {
};

render(): Node {
const qrCodeBackgroundColor = document.documentElement
? document.documentElement.style.getPropertyValue('--theme-receive-qr-code-background-color')
: 'transparent';
const qrCodeForegroundColor = document.documentElement
? document.documentElement.style.getPropertyValue('--theme-receive-qr-code-foreground-color')
: '#000';

const buttonClasses = classnames([
'primary',
// styles.nextButton,
]);
const { intl } = this.context;
return (
<div>
{this.getDialog()}
<SpendingPasswordInput
classicTheme={false}
setForm={form => this.setSpendingPasswordForm(form)}
isSubmitting={false}
/>
<Button
className={buttonClasses}
label={intl.formatMessage(globalMessages.nextButtonLabel)}
onMouseUp={this._vote}
skin={ButtonSkin}
/>
<div>
{this.generated.stores.voting.encryptedKey !== null ? (
<QRCode
value={this.generated.stores.voting.encryptedKey}
bgColor={qrCodeBackgroundColor}
fgColor={qrCodeForegroundColor}
size={152}
/>
) : (
''
)}
</div>
</div>
);
}

getDialog: void => void | Node = () => {
const { intl } = this.context;
const { votingRegTransaction } = this.generated.stores.substores.ada;
const votingRegTx = votingRegTransaction.createVotingRegTx.result;

const selectedWallet = this.generated.stores.wallets.selected;
if (selectedWallet == null) {
return null;
}

const showSignDialog =
this.generated.stores.wallets.sendMoneyRequest.isExecuting ||
!this.generated.stores.wallets.sendMoneyRequest.wasExecuted ||
this.generated.stores.wallets.sendMoneyRequest.error != null;

if (votingRegTransaction.createVotingRegTx.isExecuting) {
return (
<Dialog
title={intl.formatMessage(globalMessages.processingLabel)}
closeOnOverlayClick={false}
>
<AnnotatedLoader
title={intl.formatMessage(globalMessages.processingLabel)}
details={intl.formatMessage(globalMessages.txGeneration)}
/>
</Dialog>
);
}

if (votingRegTransaction.createVotingRegTx.error != null) {
return this._errorDialog(votingRegTransaction.createVotingRegTx.error);
}
if (votingRegTx != null && showSignDialog) {
return (
<VotingRegTxDialog
staleTx={votingRegTransaction.isStale}
transactionFee={votingRegTx.fee()}
isSubmitting={this.generated.stores.wallets.sendMoneyRequest.isExecuting}
isHardware={
selectedWallet.getParent().getWalletType() === WalletTypeOption.HARDWARE_WALLET
}
getTokenInfo={genLookupOrFail(this.generated.stores.tokenInfoStore.tokenInfo)}
onCancel={this.cancel}
onSubmit={({ password }) =>
this.generated.actions.ada.votingTransaction.signTransaction.trigger({
password,
publicDeriver: selectedWallet,
})
}
classicTheme={this.generated.stores.profile.isClassicTheme}
error={this.generated.stores.wallets.sendMoneyRequest.error}
const { uiDialogs } = this.generated.stores;
let activeDialog = null;
if (uiDialogs.isOpen(VotingRegistrationDialogContainer)) {
activeDialog = (
<VotingRegistrationDialogContainer
{...this.generated.VotingRegistrationDialogProps}
onClose={this.onClose}
/>
);
}
Expand Down Expand Up @@ -161,32 +62,6 @@ export default class VotingPage extends Component<Props> {
|},
|},
stores: {|
transactions: {| hasAnyPending: boolean |},
explorers: {|
selectedExplorer: Map<number, SelectedExplorer>,
|},
voting: {|
encryptedKey: ?string,
|},
profile: {|
isClassicTheme: boolean,
currentLocale: string,
|},
tokenInfoStore: {|
tokenInfo: TokenInfoMap,
|},
substores: {|
ada: {|
votingRegTransaction: {|
createVotingRegTx: {|
error: ?LocalizableError,
isExecuting: boolean,
result: ?PromisslessReturnType<CreateVotingRegTxFunc>,
|},
isStale: boolean,
|},
|},
|},
uiDialogs: {|
getParam: <T>(number | string) => T,
isOpen: any => boolean,
Expand All @@ -213,39 +88,6 @@ export default class VotingPage extends Component<Props> {
},
},
stores: {
explorers: {
selectedExplorer: stores.explorers.selectedExplorer,
},
wallets: {
selected: stores.wallets.selected,
sendMoneyRequest: {
error: stores.wallets.sendMoneyRequest.error,
isExecuting: stores.wallets.sendMoneyRequest.isExecuting,
wasExecuted: stores.wallets.sendMoneyRequest.wasExecuted,
},
},
profile: {
isClassicTheme: stores.profile.isClassicTheme,
currentLocale: stores.profile.currentLocale,
},
tokenInfoStore: {
tokenInfo: stores.tokenInfoStore.tokenInfo,
},
transactions: {
hasAnyPending: stores.transactions.hasAnyPending,
},
substores: {
ada: {
votingRegTransaction: {
isStale: votingStore.isStale,
createVotingRegTx: {
result: votingStore.createVotingRegTx.result,
error: votingStore.createVotingRegTx.error,
isExecuting: votingStore.createVotingRegTx.isExecuting,
},
},
},
},
uiDialogs: {
isOpen: stores.uiDialogs.isOpen,
getParam: stores.uiDialogs.getParam,
Expand Down
35 changes: 18 additions & 17 deletions app/containers/wallet/dialogs/voting/TransactionDialogContainer.js
Expand Up @@ -3,16 +3,17 @@ import type { Node } from 'react';
import React, { Component } from 'react';
import { observer, } from 'mobx-react';
import { computed, } from 'mobx';
import { defineMessages, intlShape } from 'react-intl';
import { intlShape } from 'react-intl';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import { getApiForNetwork, getApiMeta } from '../../../../api/common/utils';
import type { InjectedOrGenerated } from '../../../../types/injectedPropsType';
import VotingRegTxDialog from '../../../../components/wallet/voting/VotingRegTxDialog';
import { WalletTypeOption } from '../../../../api/ada/lib/storage/models/ConceptualWallet/interfaces';
import LocalizableError from '../../../../i18n/LocalizableError';
import { PublicDeriver } from '../../../../api/ada/lib/storage/models/PublicDeriver/index';
import type { CreateVotingRegTxFunc } from '../../../../api/ada/index';
import { ProgressInfo } from '../../../../stores/ada/VotingStore';
import type { TokenInfoMap } from '../../../../stores/toplevel/TokenInfoStore';
import { genLookupOrFail } from '../../../../stores/stateless/tokenHelpers';

export type GeneratedData = typeof TransactionDialogContainer.prototype.generated;

Expand All @@ -34,24 +35,23 @@ export default class TransactionDialogContainer extends Component<Props> {
const { submit, cancel, goBack } = this.props;
const selectedWallet = this.generated.stores.wallets.selected;
if (selectedWallet == null) {
throw new Error(`${nameof(TransactionDialogContainer)} no wallet selected`);
return null;
}
const networkInfo = selectedWallet.getParent().getNetworkInfo();
const apiMeta = getApiMeta(getApiForNetwork(networkInfo))?.meta;
if (apiMeta == null) throw new Error(`${nameof(TransactionDialogContainer)} no API selected`);
const { votingRegTransaction, votingStore } = this.generated.stores.substores.ada;
const votingRegTx = votingRegTransaction.createVotingRegTx.result;

const { votingRegTransactionStore, votingStore } = this.generated.stores.substores.ada;
const votingRegTx = votingRegTransactionStore.createVotingRegTx.result;

if (votingRegTx != null) {
return (
<VotingRegTxDialog
progressInfo={votingStore.progressInfo}
staleTx={votingRegTransaction.isStale}
transactionFee={votingRegTx.fee(true)}
staleTx={votingRegTransactionStore.isStale}
transactionFee={votingRegTx.fee()}
isSubmitting={this.generated.stores.wallets.sendMoneyRequest.isExecuting}
isHardware={
selectedWallet.getParent().getWalletType() === WalletTypeOption.HARDWARE_WALLET
}
getTokenInfo={genLookupOrFail(this.generated.stores.tokenInfoStore.tokenInfo)}
onCancel={cancel}
goBack={goBack}
onSubmit={async ({ password }) => {
Expand All @@ -64,11 +64,6 @@ export default class TransactionDialogContainer extends Component<Props> {
}
classicTheme={this.props.classicTheme}
error={this.generated.stores.wallets.sendMoneyRequest.error}
meta={{
decimalPlaces: apiMeta.decimalPlaces.toNumber(),
totalSupply: apiMeta.totalSupply,
ticker: apiMeta.primaryTicker,
}}
/>
);
}
Expand All @@ -94,7 +89,7 @@ export default class TransactionDialogContainer extends Component<Props> {
votingStore: {|
progressInfo: ProgressInfo,
|},
votingRegTransaction: {|
votingRegTransactionStore: {|
createVotingRegTx: {|
error: ?LocalizableError,
isExecuting: boolean,
Expand All @@ -112,6 +107,9 @@ export default class TransactionDialogContainer extends Component<Props> {
|},
selected: null | PublicDeriver<>,
|},
tokenInfoStore: {|
tokenInfo: TokenInfoMap,
|},
|},
|} {
if (this.props.generated !== undefined) {
Expand All @@ -134,6 +132,9 @@ export default class TransactionDialogContainer extends Component<Props> {
},
},
stores: {
tokenInfoStore: {
tokenInfo: stores.tokenInfoStore.tokenInfo,
},
wallets: {
selected: stores.wallets.selected,
sendMoneyRequest: {
Expand All @@ -147,7 +148,7 @@ export default class TransactionDialogContainer extends Component<Props> {
votingStore: {
progressInfo: stores.substores.ada.votingStore.progressInfo,
},
votingRegTransaction: {
votingRegTransactionStore: {
isStale: votingStore.isStale,
createVotingRegTx: {
result: votingStore.createVotingRegTx.result,
Expand Down

0 comments on commit 646c0b8

Please sign in to comment.