Skip to content

Commit

Permalink
tickets: Add cspp into ticket purchase (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 authored Oct 23, 2020
1 parent e02ff69 commit 7acd5ed
Show file tree
Hide file tree
Showing 28 changed files with 521 additions and 178 deletions.
29 changes: 27 additions & 2 deletions app/actions/ControlActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,24 @@ export const newPurchaseTicketsAttempt = (
try {
const walletService = sel.walletService(getState());
const dontSignTx = sel.isWatchingOnly(getState());

dispatch({ numTicketsToBuy: numTickets, type: PURCHASETICKETS_ATTEMPT });

const csppReq = {
mixedAccount: sel.getMixedAccount(getState()),
changeAccount: sel.getChangeAccount(getState()),
csppServer: sel.getCsppServer(getState()),
csppPort: sel.getCsppPort(getState()),
mixedAcctBranch: sel.getMixedAccountBranch(getState())
};

const purchaseTicketsResponse = await wallet.purchaseTicketsV3(
walletService,
passphrase,
accountNum,
numTickets,
!dontSignTx,
vsp
vsp,
csppReq
);
if (dontSignTx) {
return dispatch({
Expand Down Expand Up @@ -410,6 +418,23 @@ export const startTicketBuyerV3Attempt = (
vsp
) => (dispatch, getState) => {
const request = new RunTicketBuyerRequest();
const mixedAccount = sel.getMixedAccount(getState());
const changeAccount = sel.getChangeAccount(getState());
const csppServer = sel.getCsppServer(getState());
const csppPort = sel.getCsppPort(getState());
const mixedAcctBranch = sel.getMixedAccountBranch(getState());

if (mixedAccount && changeAccount) {
if (!mixedAccount || !changeAccount || !csppServer || !csppPort || (!mixedAcctBranch && mixedAcctBranch !== 0)) {
throw "missing cspp argument";
}
request.setMixedAccount(mixedAccount);
request.setMixedSplitAccount(mixedAccount);
request.setChangeAccount(changeAccount);
request.setCsppServer(csppServer + ":" + csppPort);
request.setMixedAccountBranch(mixedAcctBranch);
}

request.setBalanceToMaintain(balanceToMaintain);
request.setAccount(account.value);
request.setVotingAccount(account.value);
Expand Down
4 changes: 2 additions & 2 deletions app/components/SideBar/Logo/Logo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Logo = React.memo(
onReduceSideBar,
onExpandSideBar,
isWatchingOnly,
accountMixerRunning,
getRunningIndicator,
peersCount
}) => (
<div
Expand Down Expand Up @@ -43,7 +43,7 @@ const Logo = React.memo(
}>
<div className={style.peersCount}>{peersCount}</div>
</Tooltip>
{accountMixerRunning && (
{getRunningIndicator && (
<Tooltip
text={
<T
Expand Down
4 changes: 2 additions & 2 deletions app/components/SideBar/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SideBar = () => {
expandSideBar,
isWatchingOnly,
sidebarOnBottom,
accountMixerRunning,
getRunningIndicator,
rescanRequest,
onExpandSideBar,
onReduceSideBar,
Expand All @@ -45,7 +45,7 @@ const SideBar = () => {
onReduceSideBar,
onExpandSideBar,
isWatchingOnly,
accountMixerRunning,
getRunningIndicator,
peersCount
}}
/>
Expand Down
4 changes: 2 additions & 2 deletions app/components/SideBar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useSideBar() {
const expandSideBar = useSelector(sel.expandSideBar);
const isWatchingOnly = useSelector(sel.isWatchingOnly);
const sidebarOnBottom = useSelector(sel.sidebarOnBottom);
const accountMixerRunning = useSelector(sel.getAccountMixerRunning);
const getRunningIndicator = useSelector(sel.getRunningIndicator);
const rescanRequest = useSelector(sel.rescanRequest);
const isSPV = useSelector(sel.isSPV);
const peersCount = useSelector(sel.getPeersCount);
Expand All @@ -40,7 +40,7 @@ export function useSideBar() {
expandSideBar,
isWatchingOnly,
sidebarOnBottom,
accountMixerRunning,
getRunningIndicator,
rescanRequest,
onExpandSideBar,
onReduceSideBar,
Expand Down
62 changes: 62 additions & 0 deletions app/components/shared/PrivacyForm/PrivacyForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { FormattedMessage as T } from "react-intl";
import { TextInput, NumericInput } from "inputs";
import { classNames } from "pi-ui";
import style from "./PrivacyForm.module.css";
import { usePrivacyForm } from "./hooks";

const PrivacyForm = ({
className
}) => {
const {
mixedAccountName,
changeAccountName,
csppServer,
csppPort,
mixedAccountBranch
} = usePrivacyForm();

return (
<div className={className ? className : null}>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.account" m="Mixing Account" />:
</div>
<TextInput required disabled value={mixedAccountName} />
</div>
<div className={style.item}>
<div className={style.isRow}>
<div className={""}>
<T id="privacy.mixing.account.branch" m="Account Branch" />:
</div>
<NumericInput value={mixedAccountBranch} disabled />
</div>
</div>
</div>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.change.account" m="Change Account" />:
</div>
<TextInput required disabled value={changeAccountName} />
</div>
</div>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.server" m="Shuffle Server" />:
</div>
<TextInput required disabled value={csppServer} />
</div>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.server.port" m="Shuffle Port" />:
</div>
<TextInput required disabled value={csppPort} />
</div>
</div>
</div>
);
};

export default PrivacyForm;
27 changes: 27 additions & 0 deletions app/components/shared/PrivacyForm/PrivacyForm.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.error {
color: var(--error-text-color);
}

.isRow {
display: flex;
flex-direction: row;
}

.bold {
font-weight: 700;
}
.select {
width: 300px;
}
.item {
padding: 10px;
}
.item.error {
color: red;
}
.area {
margin-left: auto;
}
.row {
margin-bottom: 10px;
}
28 changes: 28 additions & 0 deletions app/components/shared/PrivacyForm/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useSelector } from "react-redux";
import * as sel from "selectors";

export function usePrivacyForm() {
const mixedAccount = useSelector(sel.getMixedAccount);
const changeAccount = useSelector(sel.getChangeAccount);
const csppServer = useSelector(sel.getCsppServer);
const csppPort = useSelector(sel.getCsppPort);
const mixedAccountBranch = useSelector(sel.getMixedAccountBranch);

const accounts = useSelector(sel.sortedAccounts);

const getAccountName = (n) => {
const account = accounts.find(({ accountNumber }) => accountNumber === n);
return account ? account.accountName : null;
};

const mixedAccountName = getAccountName(mixedAccount);
const changeAccountName = getAccountName(changeAccount);

return {
mixedAccountName,
changeAccountName,
csppServer,
csppPort,
mixedAccountBranch
};
}
4 changes: 2 additions & 2 deletions app/components/shared/TxHistory/TxHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const TxHistory = ({
<>
{transactions.map((tx, index) => {
if (limit && index >= limit) return;

const txTimestamp = tx.enterTimestamp
if (!tx) return;
const txTimestamp = tx && tx.enterTimestamp
? tx.enterTimestamp
: tx.timestamp;
// we define the transaction icon by its rowType, so we pass it as a
Expand Down
1 change: 1 addition & 0 deletions app/components/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export { default as TxHistory } from "./TxHistory/TxHistory";
export { default as LoadingError } from "./LoadingError";
export { default as ButtonsToolbar } from "./ButtonsToolbar";
export { default as TabsHeader } from "./TabsHeader/TabsHeader";
export { default as PrivacyForm } from "./PrivacyForm/PrivacyForm";
export * from "./RoutedTabsHeader";
12 changes: 1 addition & 11 deletions app/components/views/AccountsPage/Privacy/Privacy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ const Privacy = ({ isCreateAccountDisabled }) => {
accountMixerRunning,
mixedAccount,
changeAccount,
csppServer,
csppPort,
mixedAccountBranch,
accounts,
accountMixerError,
mixedAccountName,
changeAccountName,
onStartMixerAttempt
} = usePrivacy();

Expand All @@ -23,15 +18,10 @@ const Privacy = ({ isCreateAccountDisabled }) => {
) : (
<PrivacyContent
{...{
mixedAccountName,
accountMixerRunning,
accountMixerError,
csppServer,
csppPort,
changeAccountName,
onStartMixerAttempt,
stopAccountMixer,
mixedAccountBranch
stopAccountMixer
}}
/>
);
Expand Down
65 changes: 11 additions & 54 deletions app/components/views/AccountsPage/Privacy/PrivacyContent.jsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,25 @@
import { FormattedMessage as T } from "react-intl";
import { TextInput, NumericInput } from "inputs";
import { Subtitle } from "shared";
import { Subtitle, PrivacyForm } from "shared";
import { PassphraseModalSwitch, AutoBuyerSwitch } from "buttons";
import "style/Privacy.less";
import { classNames } from "pi-ui";
import style from "./Privacy.module.css";

const PrivacyContent = ({
mixedAccountName,
mixedAccountBranch,
changeAccountName,
csppServer,
csppPort,
accountMixerError,
accountMixerRunning,
stopAccountMixer,
onStartMixerAttempt
}) => (
<>
<Subtitle title={<T id="privacy.subtitle" m="Privacy" />} />
<div className={classNames(style.pageWrapper, style.isColumn)}>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.account" m="Mixing Account" />:
</div>
<TextInput required disabled value={mixedAccountName} />
</div>
<div className={style.item}>
<div className={style.isRow}>
<div className={""}>
<T id="privacy.mixing.account.branch" m="Account Branch" />:
</div>
<NumericInput value={mixedAccountBranch} disabled />
</div>
</div>
</div>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.change.account" m="Change Account" />:
</div>
<TextInput required disabled value={changeAccountName} />
</div>
</div>
<div className={classNames(style.isRow, style.row)}>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.server" m="Shuffle Server" />:
</div>
<TextInput required disabled value={csppServer} />
</div>
<div className={classNames(style.isRow, style.item)}>
<div className={""}>
<T id="privacy.mixing.server.port" m="Shuffle Port" />:
</div>
<TextInput required disabled value={csppPort} />
</div>
</div>
<div className={classNames(style.buttonArea, style.row)}>
{accountMixerRunning ? (
<AutoBuyerSwitch enabled onClick={stopAccountMixer} />
) : (
<PrivacyForm
className={classNames(style.pageWrapper, style.isColumn)}
/>
<div className={classNames(style.buttonArea, style.row)}>
{accountMixerRunning ? (
<AutoBuyerSwitch enabled onClick={stopAccountMixer} />
) : (
<PassphraseModalSwitch
modalTitle={
<T id="privacy.start.mixer.confirmation" m="Start Mixer" />
Expand All @@ -78,11 +36,10 @@ const PrivacyContent = ({
onSubmit={(passaphrase) => onStartMixerAttempt(passaphrase)}
/>
)}
</div>
{accountMixerError && (
<div className={style.error}>{accountMixerError}</div>
)}
</div>
{accountMixerError && (
<div className={style.error}>{accountMixerError}</div>
)}
</>
);

Expand Down
13 changes: 0 additions & 13 deletions app/components/views/AccountsPage/Privacy/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ export function usePrivacy() {
act.createNeededAccounts(passphrase, mixedAccountName, changeAccountName)
);

const getAccountName = (n) => {
const account = accounts.find(({ accountNumber }) => accountNumber === n);
return account ? account.accountName : null;
};

const mixedAccountName = getAccountName(mixedAccount);
const changeAccountName = getAccountName(changeAccount);

const onStartMixerAttempt = (passphrase) => {
const request = {
passphrase,
Expand All @@ -49,13 +41,8 @@ export function usePrivacy() {
accountMixerRunning,
mixedAccount,
changeAccount,
csppServer,
csppPort,
mixedAccountBranch,
accounts,
accountMixerError,
mixedAccountName,
changeAccountName,
onStartMixerAttempt,
createNeededAccounts
};
Expand Down
Loading

0 comments on commit 7acd5ed

Please sign in to comment.