Skip to content

Commit

Permalink
[DDW-481] Basic UI
Browse files Browse the repository at this point in the history
  • Loading branch information
thedanheller committed Dec 1, 2020
1 parent 0d48fad commit dd7410e
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 4 deletions.
1 change: 1 addition & 0 deletions source/main/cardano/CardanoWalletLauncher.js
Expand Up @@ -59,6 +59,7 @@ export async function CardanoWalletLauncher(walletOpts: WalletOpts): Launcher {
isStaging,
smashUrl,
} = walletOpts;
console.log('smashUrl ------------', smashUrl);
// TODO: Update launcher config to pass number
const syncToleranceSeconds = parseInt(syncTolerance.replace('s', ''), 10);

Expand Down
5 changes: 5 additions & 0 deletions source/renderer/app/Routes.js
Expand Up @@ -8,6 +8,7 @@ import Root from './containers/Root';
import InitialSettingsPage from './containers/profile/InitialSettingsPage';
import Settings from './containers/settings/Settings';
import GeneralSettingsPage from './containers/settings/categories/GeneralSettingsPage';
import StakePoolsSettingsPage from './containers/settings/categories/StakePoolsSettingsPage';
import SupportSettingsPage from './containers/settings/categories/SupportSettingsPage';
import TermsOfUseSettingsPage from './containers/settings/categories/TermsOfUseSettingsPage';
import TermsOfUsePage from './containers/profile/TermsOfUsePage';
Expand Down Expand Up @@ -89,6 +90,10 @@ export const Routes = withRouter(() => (
path={ROUTES.SETTINGS.GENERAL}
component={GeneralSettingsPage}
/>
<Route
path={ROUTES.SETTINGS.STAKE_POOLS}
component={StakePoolsSettingsPage}
/>
<Route
path={ROUTES.SETTINGS.TERMS_OF_USE}
component={TermsOfUseSettingsPage}
Expand Down
5 changes: 5 additions & 0 deletions source/renderer/app/actions/staking-actions.js
Expand Up @@ -4,6 +4,7 @@ import type {
JoinStakePoolRequest,
QuitStakePoolRequest,
} from '../api/staking/types';
import type { SmashServerType } from '../types/stakingTypes';
import type { CsvFileContent } from '../../../common/types/csv-request.types';
// ======= STAKING ACTIONS =======

Expand All @@ -21,6 +22,10 @@ export default class StakingActions {
filenamePrefix: string,
}> = new Action();
requestCSVFileSuccess: Action<any> = new Action();
selectSmashServerType: Action<{
smashServerType: SmashServerType,
}> = new Action();
selectSmashServerUrl: Action<{ smashServerUrl: string }> = new Action();
/* ---------- Redeem ITN Rewards ---------- */
onRedeemStart: Action<any> = new Action();
onConfigurationContinue: Action<{
Expand Down
@@ -0,0 +1,134 @@
// @flow
import React, { Component } from 'react';
import classnames from 'classnames';
import { Select } from 'react-polymorph/lib/components/Select';
import { SelectSkin } from 'react-polymorph/lib/skins/simple/SelectSkin';
import { Input } from 'react-polymorph/lib/components/Input';
import { InputSkin } from 'react-polymorph/lib/skins/simple/InputSkin';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import { submitOnEnter } from '../../../utils/form';
import styles from './StakePoolsSettings.scss';
import {
INTERNAL_SMASH_SERVERS,
SMASH_SERVER_TYPES,
} from '../../../config/stakingConfig';
import type { SmashServerType } from '../../../types/stakingTypes';

const messages = defineMessages({
smashSelectLabel: {
id: 'settings.stakePools.smash.select.label',
defaultMessage: '!!!Off-chain data server (SMASH)',
description:
'smashSelectLabel for the "Smash" selection on the Stake Pools settings page.',
},
smashSelectCustomServer: {
id: 'settings.stakePools.smash.select.placeholder',
defaultMessage: '!!!Custom server',
description:
'smashSelectCustomServer option for the "Smash" selection on the Stake Pools settings page.',
},
smashURLSelectLabel: {
id: 'settings.stakePools.smashUrl.select.label',
defaultMessage: '!!!SMASH server URL',
description:
'smashURLSelectLabel for the "Smash Custom Server" selection on the Stake Pools settings page.',
},
smashUrlSelectPlaceholder: {
id: 'settings.stakePools.smashUrl.select.placeholder',
defaultMessage: '!!!Enter custom server',
description:
'smashUrlSelectPlaceholder for the "Smash Custom Server" selection on the Stake Pools settings page.',
},
});

type Props = {
smashServerType: string,
smashServerUrl?: string,
onSelectSmashServerType: Function,
onSelectSmashServerUrl: Function,
};

@observer
export default class StakePoolsSettings extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};

componentWillUnmount() {
const {
smashServerType,
smashServerUrl,
onSelectSmashServerType,
} = this.props;

if (smashServerType === SMASH_SERVER_TYPES.CUSTOM && !smashServerUrl) {
onSelectSmashServerType({ smashServerType: SMASH_SERVER_TYPES.IOHK });
}
}

handleSubmit = () => {
console.log('handleSubmit');
// if (this.isConfirmDisabled()) {
// return false;
// }

// return this.form.submit({
// onSuccess: (form) => {
// const { onConfirm } = this.props;
// const { passphrase } = form.values();
// onConfirm(passphrase);
// },
// onError: () => null,
// });
};

handleSubmitOnEnter = (event: KeyboardEvent) =>
submitOnEnter(this.handleSubmit, event);

render() {
const {
smashServerType,
smashServerUrl,
onSelectSmashServerType,
onSelectSmashServerUrl,
} = this.props;
const { intl } = this.context;

const smashSelectOptions = [
...INTERNAL_SMASH_SERVERS.map(({ name: label, id: value }) => ({
label,
value,
})),
{
label: intl.formatMessage(messages.smashSelectCustomServer),
value: SMASH_SERVER_TYPES.CUSTOM,
},
];

return (
<div className={styles.component}>
<Select
label={intl.formatMessage(messages.smashSelectLabel)}
value={smashServerType}
options={smashSelectOptions}
onChange={(smashServerType: SmashServerType) => {
onSelectSmashServerType({ smashServerType });
}}
skin={SelectSkin}
className={styles.select}
optionHeight={50}
/>
{smashServerType === SMASH_SERVER_TYPES.CUSTOM && (
<Input
value={smashServerUrl || ''}
label={intl.formatMessage(messages.smashURLSelectLabel)}
placeholder={intl.formatMessage(messages.smashUrlSelectPlaceholder)}
skin={InputSkin}
onKeyPress={this.handleSubmitOnEnter}
/>
)}
</div>
);
}
}
@@ -0,0 +1,7 @@
.component {
:global {
.SimpleFormField_root:not(:first-child) {
margin-top: 20px;
}
}
}
11 changes: 11 additions & 0 deletions source/renderer/app/components/settings/menu/SettingsMenu.js
Expand Up @@ -12,6 +12,11 @@ const messages = defineMessages({
defaultMessage: '!!!General',
description: 'Label for the "General" link in the settings menu.',
},
stakePools: {
id: 'settings.menu.stakePools.link.label',
defaultMessage: '!!!Stake Pools',
description: 'Label for the "Support" link in the settings menu.',
},
support: {
id: 'settings.menu.support.link.label',
defaultMessage: '!!!Support',
Expand Down Expand Up @@ -54,6 +59,12 @@ export default class SettingsMenu extends Component<Props> {
active={isActiveItem(ROUTES.SETTINGS.GENERAL)}
className="general"
/>
<SettingsMenuItem
label={intl.formatMessage(messages.stakePools)}
onClick={() => onItemClick(ROUTES.SETTINGS.STAKE_POOLS)}
active={isActiveItem(ROUTES.SETTINGS.STAKE_POOLS)}
className="stakePools"
/>
{!isFlight && !global.isShelleyTestnet && (
<SettingsMenuItem
label={intl.formatMessage(messages.display)}
Expand Down
25 changes: 24 additions & 1 deletion source/renderer/app/config/stakingConfig.js
@@ -1,5 +1,28 @@
// @flow
import type { RedeemItnRewardsStep } from '../types/stakingTypes';
import type {
RedeemItnRewardsStep,
SmashServerType,
} from '../types/stakingTypes';

// @SMASH TODO: Get CARDANO & IOHK servers URI
export const SMASH_SERVER_TYPES: SmashServerType = {
IOHK: 'iohk',
CARDANO: 'cardano',
CUSTOM: 'custom',
};

export const INTERNAL_SMASH_SERVERS: Array<{
id: SmashServerType,
name: string,
uri: string,
}> = [
{
id: SMASH_SERVER_TYPES.CARDANO,
name: 'Cardano Foundation',
uri: 'https://smash.cardano-mainnet.iohk.io',
},
{ id: SMASH_SERVER_TYPES.IOHK, name: 'IOHK', uri: 'http://smash.iohk.io' },
];

export const RANKING_SLIDER_RATIO = 60;
export const MIN_DELEGATION_FUNDS_LOG = Math.log(10);
Expand Down
@@ -0,0 +1,27 @@
// @flow
import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import StakePoolsSettings from '../../../components/settings/categories/StakePoolsSettings';
import type { InjectedProps } from '../../../types/injectedPropsType';

@inject('stores', 'actions')
@observer
export default class StakePoolsSettingsPage extends Component<InjectedProps> {
static defaultProps = { actions: null, stores: null };

render() {
const { stores, actions } = this.props;
const { smashServerType, smashServerUrl } = stores.staking;
const { selectSmashServerType, selectSmashServerUrl } = actions.staking;
// If `smashServerType` is null, waits for it to be set
if (!smashServerType) return false;
return (
<StakePoolsSettings
smashServerType={smashServerType}
smashServerUrl={smashServerUrl}
onSelectSmashServerType={selectSmashServerType.trigger}
onSelectSmashServerUrl={selectSmashServerUrl.trigger}
/>
);
}
}
7 changes: 6 additions & 1 deletion source/renderer/app/i18n/locales/en-US.json
Expand Up @@ -272,8 +272,13 @@
"settings.display.themeNames.yellow": "Yellow",
"settings.menu.display.link.label": "Themes",
"settings.menu.general.link.label": "General",
"settings.menu.stakePools.link.label": "Stake Pools",
"settings.menu.support.link.label": "Support",
"settings.menu.termsOfUse.link.label": "Terms of service",
"settings.stakePools.smash.select.label": "Off-chain data server (SMASH)",
"settings.stakePools.smash.select.placeholder": "Custom server",
"settings.stakePools.smashUrl.select.label": "SMASH server URL",
"settings.stakePools.smashUrl.select.placeholder": "Enter custom server",
"settings.support.faq.content": "If you are experiencing a problem, please look for guidance using the list of {faqLink} on the support pages. If you can’t find a solution, please submit a support ticket.",
"settings.support.faq.faqLink": "Known Issues",
"settings.support.faq.faqLinkURL": "https://daedaluswallet.io/known-issues/",
Expand Down Expand Up @@ -957,4 +962,4 @@
"wallet.transferFunds.dialog2.sourceWalletAmount.label": "{sourceWalletName} amount",
"wallet.transferFunds.dialog2.title": "Transfer funds",
"wallet.transferFunds.dialog2.total.label": "Total"
}
}
1 change: 1 addition & 0 deletions source/renderer/app/routes-config.js
Expand Up @@ -39,6 +39,7 @@ export const ROUTES = {
SETTINGS: {
ROOT: '/settings',
GENERAL: '/settings/general',
STAKE_POOLS: '/settings/stake-pools',
TERMS_OF_USE: '/settings/terms-of-service',
SUPPORT: '/settings/support',
DISPLAY: '/settings/display',
Expand Down
27 changes: 25 additions & 2 deletions source/renderer/app/stores/StakingStore.js
Expand Up @@ -20,7 +20,6 @@ import type {
RewardForIncentivizedTestnet,
JoinStakePoolRequest,
GetDelegationFeeRequest,
QuitStakePoolRequest,
} from '../api/staking/types';
import Wallet from '../domains/Wallet';
import StakePool from '../domains/StakePool';
Expand All @@ -29,7 +28,10 @@ import LocalizableError from '../i18n/LocalizableError';
import { showSaveDialogChannel } from '../ipc/show-file-dialog-channels';
import REWARDS from '../config/stakingRewards.dummy.json';
import { generateFileNameWithTimestamp } from '../../../common/utils/files';
import type { RedeemItnRewardsStep } from '../types/stakingTypes';
import type {
RedeemItnRewardsStep,
SmashServerType,
} from '../types/stakingTypes';
import type { CsvFileContent } from '../../../common/types/csv-request.types';

export default class StakingStore extends Store {
Expand All @@ -39,6 +41,9 @@ export default class StakingStore extends Store {
@observable selectedDelegationWalletId = null;
@observable stake = INITIAL_DELEGATION_FUNDS;
@observable isRanking = false;
// @SMASH TODO: Leave it null until the API response
@observable smashServerType: ?SmashServerType = 'iohk'; // null;
@observable smashServerUrl: ?string = null;

/* ---------- Redeem ITN Rewards ---------- */
@observable redeemStep: ?RedeemItnRewardsStep = null;
Expand Down Expand Up @@ -87,6 +92,8 @@ export default class StakingStore extends Store {
stakingActions.fakeStakePoolsLoading.listen(this._setFakePoller);
stakingActions.updateDelegatingStake.listen(this._setStake);
stakingActions.rankStakePools.listen(this._rankStakePools);
stakingActions.selectSmashServerType.listen(this._selectSmashServerType);
stakingActions.selectSmashServerUrl.listen(this._selectSmashServerUrl);
stakingActions.selectDelegationWallet.listen(
this._setSelectedDelegationWalletId
);
Expand Down Expand Up @@ -132,6 +139,22 @@ export default class StakingStore extends Store {
this.getStakePoolsData();
};

@action _selectSmashServerType = ({
smashServerType,
}: {
smashServerType: SmashServerType,
}) => {
this.smashServerType = smashServerType;
};

@action _selectSmashServerUrl = ({
smashServerUrl,
}: {
smashServerUrl: string,
}) => {
this.smashServerUrl = smashServerUrl;
};

@action _joinStakePool = async (request: JoinStakePoolRequest) => {
const { walletId, stakePoolId, passphrase } = request;

Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/types/stakingTypes.js
@@ -1,3 +1,4 @@
// @flow

export type RedeemItnRewardsStep = 'configuration' | 'confirmation' | 'result';
export type SmashServerType = 'iohk' | 'cardano' | 'custom';

0 comments on commit dd7410e

Please sign in to comment.