Skip to content

Commit

Permalink
Remove isJormungandr environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Jul 6, 2020
1 parent b8c8f22 commit d22563d
Show file tree
Hide file tree
Showing 63 changed files with 331 additions and 435 deletions.
15 changes: 10 additions & 5 deletions app/api/ada/index.js
Expand Up @@ -176,6 +176,7 @@ import type {
} from '../common/types';
import { getApiForNetwork } from '../common/utils';
import { CoreAddressTypes } from './lib/storage/database/primitives/enums';
import { networks } from './lib/storage/database/prepackaged/networks';

declare var CONFIG: ConfigType;
const protocolMagic = CONFIG.network.protocolMagic;
Expand Down Expand Up @@ -333,7 +334,7 @@ export type PrepareAndBroadcastLedgerSignedTxFunc = (
// createUnsignedTx

export type CreateUnsignedTxRequest = {|
publicDeriver: IGetAllUtxos & IHasUtxoChains,
publicDeriver: IPublicDeriver<ConceptualWallet> & IGetAllUtxos & IHasUtxoChains,
receiver: string,
filter: ElementOf<IGetAllUtxosResponse> => boolean,
...({|
Expand Down Expand Up @@ -844,13 +845,16 @@ export default class AdaApi {
const utxos = await request.publicDeriver.getAllUtxos();
const filteredUtxos = utxos.filter(utxo => request.filter(utxo));

const addressedUtxo = environment.isJormungandr()
const network = request.publicDeriver.getParent().getNetworkInfo();
const isJormungandr = network.NetworkId === networks.JormungandrMainnet.NetworkId;

const addressedUtxo = isJormungandr
? shelleyAsAddressedUtxo(filteredUtxos)
: byronAsAddressedUtxo(filteredUtxos);

let unsignedTxResponse;
if (request.shouldSendAll != null) {
unsignedTxResponse = environment.isJormungandr()
unsignedTxResponse = isJormungandr
? shelleySendAllUnsignedTx(
receiver,
addressedUtxo
Expand All @@ -866,7 +870,7 @@ export default class AdaApi {
throw new Error(`${nameof(this.createUnsignedTx)} no internal addresses left. Should never happen`);
}
const changeAddr = nextUnusedInternal.addressInfo;
unsignedTxResponse = environment.isJormungandr()
unsignedTxResponse = isJormungandr
? shelleyNewAdaUnsignedTx(
[{
address: receiver,
Expand Down Expand Up @@ -1085,13 +1089,14 @@ export default class AdaApi {
Logger.debug(`${nameof(AdaApi)}::${nameof(this.restoreWallet)} called`);
const { recoveryPhrase, walletName, walletPassword, } = request;

const isJormungandr = request.network.NetworkId === networks.JormungandrMainnet.NetworkId;
try {
// Note: we only restore for 0th account
const accountIndex = HARD_DERIVATION_START + 0;
const rootPk = generateWalletRootKey(recoveryPhrase);
const newPubDerivers = [];

if (environment.isJormungandr()) {
if (isJormungandr) {
const wallet = await createStandardCip1852Wallet({
db: request.db,
discrimination: environment.getDiscriminant(),
Expand Down
4 changes: 4 additions & 0 deletions app/api/ada/index.test.js
Expand Up @@ -21,6 +21,9 @@ import {
} from './lib/storage/database/index';
import { legacyWalletChecksum } from '@emurgo/cip4-js';
import { asGetPublicKey } from './lib/storage/models/PublicDeriver/traits';
import {
networks,
} from './lib/storage/database/prepackaged/networks';

let db: lf$Database;

Expand All @@ -36,6 +39,7 @@ test('Restore wallet', async () => {
recoveryPhrase: TX_TEST_MNEMONIC_1,
walletName: 'mywallet',
walletPassword: '123',
network: networks.ByronMainnet,
};

const response = await AdaApi.prototype.restoreWallet(restoreRequest);
Expand Down
5 changes: 1 addition & 4 deletions app/api/ada/lib/storage/database/index.js
Expand Up @@ -30,7 +30,6 @@ import { populateExplorerDb } from './explorers/tables';
import { KeyKind } from '../../../../common/lib/crypto/keys/types';
import { networks } from './prepackaged/networks';
import { prepackagedExplorers } from './prepackaged/explorers';
import environment from '../../../../../environment';

// global var from window.indexedDB
declare var indexedDB: IDBFactory;
Expand Down Expand Up @@ -263,9 +262,7 @@ async function onUpgrade(
'ConceptualWallet',
'NetworkId',
// recall: at the time we only supported 1 currency per Yoroi install
environment.isJormungandr()
? networks.JormungandrMainnet.NetworkId
: networks.ByronMainnet.NetworkId
networks.ByronMainnet.NetworkId
);
}
}
8 changes: 8 additions & 0 deletions app/api/ada/lib/storage/database/prepackaged/networks.js
Expand Up @@ -4,6 +4,7 @@ import {
CoinTypes,
} from '../../../../../../config/numbersConfig';
import { Network } from '@coinbarn/ergo-ts';
import type { NetworkRow } from '../primitives/tables';

export const CardanoForks = Object.freeze({
Haskell: 0,
Expand Down Expand Up @@ -33,3 +34,10 @@ export const networks = Object.freeze({
Fork: ErgoForks.Primary,
},
});

export function isTestnet(
network: $ReadOnly<NetworkRow>,
): boolean {
if (network.NetworkId === networks.JormungandrMainnet.NetworkId) return true;
return false;
}
2 changes: 2 additions & 0 deletions app/api/common/types.js
Expand Up @@ -5,6 +5,7 @@ import BigNumber from 'bignumber.js';
import {
PublicDeriver,
} from '../ada/lib/storage/models/PublicDeriver/index';
import type { NetworkRow } from '../ada/lib/storage/database/primitives/tables';

// isValidMnemonic

Expand All @@ -29,6 +30,7 @@ export type GetBalanceFunc = (

export type RestoreWalletRequest = {|
db: lf$Database,
network: $ReadOnly<NetworkRow>,
recoveryPhrase: string,
walletName: string,
walletPassword: string,
Expand Down
4 changes: 4 additions & 0 deletions app/api/ergo/lib/restore.test.js
Expand Up @@ -16,6 +16,9 @@ import {
loadLovefieldDB,
} from '../../ada/lib/storage/database/index';
import { generateWalletRootKey } from './crypto/wallet';
import {
networks,
} from '../../ada/lib/storage/database/prepackaged/networks';

let db: lf$Database;

Expand Down Expand Up @@ -52,6 +55,7 @@ test('Restore Ergo wallet', async () => {
recoveryPhrase,
walletName: 'mywallet',
walletPassword: '123',
network: networks.ErgoMainnet,
};

const response = await ErgoApi.prototype.restoreWallet(restoreRequest);
Expand Down
1 change: 0 additions & 1 deletion app/components/loading/Loading.js
Expand Up @@ -82,7 +82,6 @@ export default class Loading extends Component<Props> {
<div className={yoroiLogoStyles}>
<IntroBanner
isNightly={environment.isNightly()}
isJormungandr={environment.isJormungandr()}
/>
</div>

Expand Down
9 changes: 1 addition & 8 deletions app/components/notice-board/NoNotice.js
Expand Up @@ -4,8 +4,6 @@ import type { Node } from 'react';
import { observer } from 'mobx-react';
import { intlShape, defineMessages, FormattedHTMLMessage } from 'react-intl';

import environmnent from '../../environment';
import NoNoticeTestnetSvg from '../../assets/images/transaction/no-transactions-yet.testnet.inline.svg';
import NoNoticeClassicSvg from '../../assets/images/transaction/no-transactions-yet.classic.inline.svg';
import NoNoticeModernSvg from '../../assets/images/transaction/no-transactions-yet.modern.inline.svg';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
Expand Down Expand Up @@ -35,12 +33,7 @@ export default class NoNotice extends Component<Props> {
const { intl } = this.context;
const { classicTheme } = this.props;

let NoNoticeImage;
if (environmnent.isJormungandr()) {
NoNoticeImage = NoNoticeTestnetSvg;
} else {
NoNoticeImage = classicTheme ? NoNoticeClassicSvg : NoNoticeModernSvg;
}
const NoNoticeImage = classicTheme ? NoNoticeClassicSvg : NoNoticeModernSvg;

return (
<div className={styles.component}>
Expand Down
18 changes: 3 additions & 15 deletions app/components/profile/language-selection/IntroBanner.js
Expand Up @@ -3,24 +3,15 @@ import React, { Component } from 'react';
import type { Node } from 'react';
import { observer } from 'mobx-react';
import styles from './IntroBanner.scss';
import { defineMessages, intlShape, } from 'react-intl';
import TestnetLogo from '../../../assets/images/yoroi-logotestnet-gradient.inline.svg';
import { intlShape, } from 'react-intl';
import NightlyLogo from '../../../assets/images/yoroi-logo-nightly.inline.svg';
import YoroiLogo from '../../../assets/images/yoroi-logo-blue.inline.svg';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';

type Props = {|
+isNightly: boolean,
+isJormungandr: boolean,
|};

const messages = defineMessages({
title: {
id: 'profile.languageSelect.intro',
defaultMessage: '!!!You are on the Yoroi Shelley Testnet',
},
});

@observer
export default class IntroBanner extends Component<Props> {

Expand All @@ -32,22 +23,19 @@ export default class IntroBanner extends Component<Props> {
if (this.props.isNightly) {
return NightlyLogo;
}
if (this.props.isJormungandr) {
return TestnetLogo;
}
return YoroiLogo;
}

render(): Node {
const { intl } = this.context;
const Logo = this._getLogo();
const title = '';
return (
<div className={styles.component}>
<span className={styles.banner}>
<Logo />
</span>
<div className={styles.mainTitle}>
{intl.formatMessage(messages.title)}
{title}
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion app/components/topbar/banners/TestnetWarningBanner.js
Expand Up @@ -27,6 +27,7 @@ const messages = defineMessages({
});

type Props = {|
isTestnet: boolean,
|};

@observer
Expand Down Expand Up @@ -67,7 +68,7 @@ export default class TestnetWarningBanner extends Component<Props> {
</div>
);
}
if (environment.isJormungandr()) {
if (this.props.isTestnet) {
return (
<div className={styles.shelleyTestnetWarning}>
<span key="0" className={styles.shelleyTestnetWarningIcon}><ShelleyTestnetWarningSvg /></span>
Expand Down
6 changes: 4 additions & 2 deletions app/components/transfer/cards/ByronOptionDialog.js
Expand Up @@ -9,8 +9,9 @@ import globalMessages from '../../../i18n/global-messages';
import Dialog from '../../widgets/Dialog';
import DialogCloseButton from '../../widgets/DialogCloseButton';
import OptionBlock from '../../widgets/options/OptionBlock';
import environment from '../../../environment';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import type { ComplexityLevelType } from '../../../types/complexityLevelType';
import { ComplexityLevels } from '../../../types/complexityLevelType';

import styles from '../../widgets/options/OptionListWrapperStyle.scss';

Expand Down Expand Up @@ -69,6 +70,7 @@ type Props = {|
+onLedger: void => void,
|},
+onCancel: void => void,
+complexityLevel: ComplexityLevelType,
|};

const TabOptions = Object.freeze({
Expand Down Expand Up @@ -182,7 +184,7 @@ export default class ByronOptionDialog extends Component<Props, State> {
title={intl.formatMessage(icarusMessages.yoroiPaperLabel)}
learnMoreText={intl.formatMessage(globalMessages.legacyAttentionText)}
/>
{(environment.isJormungandr() || environment.isTest()) && (
{this.props.complexityLevel === ComplexityLevels.Advanced && (
<>
<OptionBlock
parentName="fromLedger"
Expand Down
5 changes: 0 additions & 5 deletions app/components/wallet/WalletAdd.js
Expand Up @@ -8,7 +8,6 @@ import classnames from 'classnames';
import CustomTooltip from '../widgets/CustomTooltip';
import MainCards from './add/MainCards';
import LogoYoroiIcon from '../../assets/images/yoroi-logo-white.inline.svg';
import LogoYoroiShelleyTestnetIcon from '../../assets/images/yoroi-logo-shelley-testnet-white.inline.svg';
import SettingsIcon from '../../assets/images/sidebar/wallet-settings-2-ic.inline.svg';
import DaedalusIcon from '../../assets/images/top-bar/daedalus-migration.inline.svg';
import NightlyLogo from '../../assets/images/yoroi-logo-nightly-white.inline.svg';
Expand Down Expand Up @@ -54,9 +53,6 @@ export default class WalletAdd extends Component<Props> {
if (environment.isNightly()) {
return NightlyLogo;
}
if (environment.isJormungandr()) {
return LogoYoroiShelleyTestnetIcon;
}
return LogoYoroiIcon;
}

Expand All @@ -69,7 +65,6 @@ export default class WalletAdd extends Component<Props> {

const componentStyle = classnames([
styles.component,
environment.isJormungandr() ? styles.shelleyTestnet : null
]);

const LogoIcon = this.getLogo();
Expand Down
4 changes: 0 additions & 4 deletions app/components/wallet/WalletAdd.scss
Expand Up @@ -158,8 +158,4 @@ $linebreakWidth: 1540px;
}
}
}

.shelleyTestnet {
background-image: url(../../assets/images/add-wallet/add-wallet-bg-testnet.inline.svg);
}
}
9 changes: 4 additions & 5 deletions app/components/wallet/WalletReceive.js
Expand Up @@ -209,10 +209,9 @@ export default class WalletReceive extends Component<Props> {
<h2>{intl.formatMessage(messages.generatedAddressesSectionTitle)}</h2>
{labelBlock.header}
{valueBlock.header}
{
!environment.isJormungandr() && onGeneratePaymentURI != null &&
<h2>{intl.formatMessage(messages.generateURLLabel)}</h2>
}
{onGeneratePaymentURI != null && (
<h2>{intl.formatMessage(messages.generateURLLabel)}</h2>
)}
<h2>{intl.formatMessage(messages.verifyAddressLabel)}</h2>
</div>

Expand Down Expand Up @@ -260,7 +259,7 @@ export default class WalletReceive extends Component<Props> {
{valueBlock.body(address)}
{/* Generate payment URL for Address action */}
{/* disable URI for Shelley testnet */}
{!environment.isJormungandr() && onGeneratePaymentURI != null && (
{onGeneratePaymentURI != null && (
<div className={classnames([
styles.addressActionItemBlock,
styles.generateURLActionBlock])}
Expand Down
5 changes: 2 additions & 3 deletions app/components/wallet/WalletRestoreVerifyDialog.js
Expand Up @@ -18,7 +18,6 @@ import { SelectedExplorer } from '../../domain/SelectedExplorer';
import type { Notification } from '../../types/notificationType';
import type { PlateResponse } from '../../api/ada/lib/cardanoCrypto/plate';
import CenteredLayout from '../layout/CenteredLayout';
import environment from '../../environment';
import type { WalletChecksum } from '@emurgo/cip4-js';
import type { $npm$ReactIntl$IntlFormat } from 'react-intl';

Expand Down Expand Up @@ -170,14 +169,14 @@ export default class WalletRestoreVerifyDialog extends Component<Props> {
{
label: intl.formatMessage(globalMessages.backButtonLabel),
onClick: onCancel,
disabled: !environment.isJormungandr() && isSubmitting,
disabled: isSubmitting,
},
{
label: intl.formatMessage(globalMessages.confirm),
onClick: onNext,
primary: true,
className: classnames(['confirmButton']),
isSubmitting: !environment.isJormungandr() && isSubmitting,
isSubmitting,
},
];

Expand Down
4 changes: 0 additions & 4 deletions app/components/wallet/add/AddAnotherWallet.js
Expand Up @@ -6,7 +6,6 @@ import classnames from 'classnames';

import MainCards from './MainCards';
import LogoYoroiIcon from '../../../assets/images/yoroi-logo-white.inline.svg';
import LogoYoroiShelleyTestnetIcon from '../../../assets/images/yoroi-logotestnet-gradient.inline.svg';
import NightlyLogo from '../../../assets/images/yoroi-logo-nightly.inline.svg';

import styles from './AddAnotherWallet.scss';
Expand All @@ -26,9 +25,6 @@ export default class AddAnotherWallet extends Component<Props> {
if (environment.isNightly()) {
return NightlyLogo;
}
if (environment.isJormungandr()) {
return LogoYoroiShelleyTestnetIcon;
}
return LogoYoroiIcon;
}

Expand Down

0 comments on commit d22563d

Please sign in to comment.