Skip to content

Commit

Permalink
[DDW-481] Fix URL error and add Direct and None options
Browse files Browse the repository at this point in the history
  • Loading branch information
thedanheller committed Jan 11, 2021
1 parent ad089c8 commit ed6cca0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
7 changes: 7 additions & 0 deletions source/renderer/app/api/api.js
Expand Up @@ -99,6 +99,7 @@ import { filterLogData } from '../../../common/utils/logging';
import { LOVELACES_PER_ADA } from '../config/numbersConfig';
import {
SMASH_SERVER_STATUSES,
SMASH_SERVERS_LIST,
DELEGATION_DEPOSIT,
MIN_REWARDS_REDEMPTION_RECEIVER_BALANCE,
REWARDS_REDEMPTION_FEE_CALCULATION_AMOUNT,
Expand Down Expand Up @@ -1699,6 +1700,12 @@ export default class AdaApi {

checkSmashServerIsValid = async (url: string): Promise<boolean> => {
try {
if (
url === SMASH_SERVERS_LIST.direct.url ||
url === SMASH_SERVERS_LIST.none.url
) {
return true;
}
const {
health,
}: CheckSmashServerHealthApiResponse = await checkSmashServerHealth(
Expand Down
Expand Up @@ -96,7 +96,7 @@ export default class StakePoolsSettings extends Component<Props, State> {
}

handleSubmit = (url: string) => {
if (isValidUrl(url || '')) {
if (this.handleIsValid(url)) {
this.setState({
editingSmashServerUrl: url,
});
Expand All @@ -116,7 +116,11 @@ export default class StakePoolsSettings extends Component<Props, State> {
});
};

handleIsValid = (url: string) => url === '' || isValidUrl(url);
handleIsValid = (url: string) =>
url === '' ||
isValidUrl(url) ||
url === SMASH_SERVERS_LIST.direct.url ||
url === SMASH_SERVERS_LIST.none.url;

render() {
const { smashServerUrlError, isLoading } = this.props;
Expand Down
17 changes: 13 additions & 4 deletions source/renderer/app/config/stakingConfig.js
Expand Up @@ -22,14 +22,21 @@ export const SMASH_SERVERS_LIST: {
? 'https://smash.cardano-testnet.iohkdev.io'
: 'https://smash.cardano-mainnet.iohk.io',
},
// @SMASH TODO - remove it!
testingKnown: {
name: 'Testing Known Server',
url: 'https://test-known.com',
},
// adaPools: {
// name: 'AdaPools',
// url: 'https://smash.adapools.org',
// },
// Metadata is fetched directly in URLs registered on chain,
direct: {
name: 'Direct',
url: 'direct',
},
// Metadata is not fetched at all,
none: {
name: 'None',
url: 'none',
},
};

// @SMASH TODO - remove testing server
Expand All @@ -40,6 +47,8 @@ export const SMASH_SERVER_TYPES: {
ADA_POOLS: 'adaPools',
TESTING_KNOWN: 'testingKnown',
CUSTOM: 'custom',
DIRECT: 'direct',
NONE: 'none',
};

export const SMASH_SERVER_STATUSES: {
Expand Down
Expand Up @@ -9,21 +9,25 @@ import type { InjectedProps } from '../../../types/injectedPropsType';
export default class StakePoolsSettingsPage extends Component<InjectedProps> {
static defaultProps = { actions: null, stores: null };

handleSelectSmashServerUrl = (smashServerUrl: string) => {
this.props.actions.staking.selectSmashServerUrl.trigger({ smashServerUrl });
};

render() {
const { stores, actions } = this.props;
const {
smashServerUrl,
smashServerUrlError,
smashServerLoading,
} = stores.staking;
const { selectSmashServerUrl, resetSmashServerError } = actions.staking;
const { resetSmashServerError } = actions.staking;
// If `smashServerUrl` is null, waits for it to be set
if (!smashServerUrl) return false;
return (
<StakePoolsSettings
smashServerUrl={smashServerUrl}
smashServerUrlError={smashServerUrlError}
onSelectSmashServerUrl={selectSmashServerUrl.trigger}
onSelectSmashServerUrl={this.handleSelectSmashServerUrl}
onResetSmashServerError={resetSmashServerError.trigger}
isLoading={smashServerLoading}
/>
Expand Down
21 changes: 11 additions & 10 deletions source/renderer/app/stores/StakingStore.js
Expand Up @@ -145,17 +145,18 @@ export default class StakingStore extends Store {
this.smashServerLoading = true;
let smashServerUrl: string = await this.getSmashSettingsRequest.execute();

// @SMASH TODO - Add this back after testing
// If the server wasn't set, sets it for IOHK
if (
!smashServerUrl ||
smashServerUrl === 'none' ||
smashServerUrl === 'direct'
) {
const poolMetadataSource = SMASH_SERVERS_LIST.iohk.url;
await this.updateSmashSettingsRequest.execute(poolMetadataSource);

smashServerUrl = SMASH_SERVERS_LIST.iohk.url;
}
// if (
// !smashServerUrl ||
// smashServerUrl === 'none' ||
// smashServerUrl === 'direct'
// ) {
// const poolMetadataSource = SMASH_SERVERS_LIST.iohk.url;
// await this.updateSmashSettingsRequest.execute(poolMetadataSource);

// smashServerUrl = SMASH_SERVERS_LIST.iohk.url;
// }

runInAction(() => {
this.smashServerUrl = smashServerUrl;
Expand Down
8 changes: 7 additions & 1 deletion source/renderer/app/types/stakingTypes.js
Expand Up @@ -2,5 +2,11 @@

export type RedeemItnRewardsStep = 'configuration' | 'confirmation' | 'result';
// @SMASH TODO - remove testing server
export type SmashServerType = 'testingKnown' | 'iohk' | 'adaPools' | 'custom';
export type SmashServerType =
| 'testingKnown'
| 'iohk'
| 'adaPools'
| 'custom'
| 'direct'
| 'none';
export type DelegationAction = 'join' | 'quit';

0 comments on commit ed6cca0

Please sign in to comment.