Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: adds custom network support #2468

Merged
merged 23 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/actions/appActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @flow
import { createBatchActions } from 'spunky'

import networkActions from './networkActions'
import accountsActions from './accountsActions'
import settingsActions from './settingsActions'
import contactsActions from './contactsActions'
Expand All @@ -10,7 +9,6 @@ import n3AccountsActions from './n3AccountsActions'
export const ID = 'app'

export default createBatchActions(ID, {
network: networkActions,
accounts: accountsActions,
n3Accounts: n3AccountsActions,
settings: settingsActions,
Expand Down
2 changes: 1 addition & 1 deletion app/actions/nodeStorageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ export const getNode = async (
await setNode('', net)
return ''
}

const storage = await getStorage(`${STORAGE_KEY}-${net}`).catch(console.error)
const nodeInStorage = get(storage, 'node')
const expiration = get(storage, 'timestamp')
if (!nodeInStorage || !expiration || determineIfCacheIsExpired(expiration)) {
return ''
}

return nodeInStorage
}

Expand Down
52 changes: 27 additions & 25 deletions app/actions/settingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
} from '../core/constants'
import { version } from '../../package.json'

type Settings = {
export type Settings = {
currency: string,
blockExplorer: string,
tokens: Array<TokenItemType>,
version: string,
theme: string,
soundEnabled: boolean,
chain: string,
language: string,
}

const STORAGE_KEY = 'settings'
Expand Down Expand Up @@ -58,37 +59,38 @@ export const getSettings = async (): Promise<Settings> => {
return { ...defaults, ...settings, tokens }
}

export const updateSettings = async (values: Settings = {}) => {
const settings = await getSettings()
const { chain } = values
const newSettings = {
...settings,
...values,
}
const parsedForLocalStorage = cloneDeep(newSettings)
if (chain === 'neo2') {
const tokensForStorage = [
...newSettings.tokens.filter(token => token.isUserGenerated),
]
parsedForLocalStorage.tokens = tokensForStorage
} else {
const tokens = await getDefaultTokens('neo3')
newSettings.tokens = tokens
}
// NOTE: we only save user generated tokens to local storage to avoid
// conflicts in managing the "master" nep5 list
await setStorage(STORAGE_KEY, parsedForLocalStorage)
return newSettings
}

export const ID = 'settings'

export const updateSettingsActions = createActions(
ID,
// $FlowFixMe
(values: Settings = {}) => async (): Promise<Settings> => {
const settings = await getSettings()
const { chain } = values
const newSettings = {
...settings,
...values,
}
const parsedForLocalStorage = cloneDeep(newSettings)
if (chain === 'neo2') {
const tokensForStorage = [
...newSettings.tokens.filter(token => token.isUserGenerated),
]
parsedForLocalStorage.tokens = tokensForStorage
} else {
const tokens = await getDefaultTokens('neo3')
newSettings.tokens = tokens
}
// NOTE: we only save user generated tokens to local storage to avoid
// conflicts in managing the "master" nep5 list

await setStorage(STORAGE_KEY, parsedForLocalStorage)
return newSettings
},
(values: Settings = {}) => (): Promise<Settings> => updateSettings(values),
)

export default createActions(ID, ({ store }) => async (): Promise<Settings> => {
export default createActions(ID, () => async (): Promise<Settings> => {
const settings = await getSettings()
const { chain } = settings

Expand Down
3 changes: 3 additions & 0 deletions app/assets/icons/alternate-check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/icons/money.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions app/components/Blockchain/Address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { compose } from 'recompose'
import Address from './Address'
import withNetworkData from '../../../hocs/withNetworkData'
import withExplorerData from '../../../hocs/withExplorerData'
import withChainData from '../../../hocs/withChainData'
import withSettingsContext from '../../../hocs/withSettingsContext'

export default compose(
withNetworkData(),
withExplorerData(),
withChainData(),
)(Address)
)(withSettingsContext(Address))
6 changes: 3 additions & 3 deletions app/components/Blockchain/Transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { showModal } from '../../../modules/modal'
import { MODAL_TYPES } from '../../../core/constants'

import contactsActions from '../../../actions/contactsActions'
import withChainData from '../../../hocs/withChainData'

import withSettingsContext from '../../../hocs/withSettingsContext'

const mapDispatchToProps = dispatch => ({
showAddContactModal: props =>
Expand All @@ -28,9 +29,8 @@ export default compose(
null,
mapDispatchToProps,
),
withChainData(),
withAuthData(),
withData(contactsActions, mapContactsDataToProps),
withNetworkData(),
withExplorerData(),
)(Transaction)
)(withSettingsContext(Transaction))
6 changes: 3 additions & 3 deletions app/components/Contacts/AddContactPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AddContactPanel from './AddContactPanel'
import { addContactActions } from '../../../actions/contactsActions'
import withProgressChange from '../../../hocs/withProgressChange'
import withFailureNotification from '../../../hocs/withFailureNotification'
import withChainData from '../../../hocs/withChainData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const { LOADED } = progressValues

Expand All @@ -18,12 +18,12 @@ const mapContactActionsToProps = (actions: Object) => ({

export default compose(
withProps(({ name }) => ({ oldName: name })),
withChainData(),

withProgressChange(
addContactActions,
LOADED,
(state, props) => props.onSave && props.onSave(),
),
withActions(addContactActions, mapContactActionsToProps),
withFailureNotification(addContactActions),
)(AddContactPanel)
)(withSettingsContext(AddContactPanel))
5 changes: 2 additions & 3 deletions app/components/Contacts/ContactForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import withAuthData from '../../../hocs/withAuthData'

import ContactForm from './ContactForm'
import contactsActions from '../../../actions/contactsActions'
import withChainData from '../../../hocs/withChainData'
import withCameraAvailability from '../../../hocs/withCameraAvailability'
import withSettingsContext from '../../../hocs/withSettingsContext'

const mapContactsDataToProps = (contacts: Object) => ({ contacts })

export default compose(
withAuthData(),
withChainData(),
withData(contactsActions, mapContactsDataToProps),
withState('formName', 'setName', ({ formName }) => formName || ''),
withState(
Expand All @@ -24,4 +23,4 @@ export default compose(
),
injectIntl,
withCameraAvailability,
)(ContactForm)
)(withSettingsContext(ContactForm))
5 changes: 2 additions & 3 deletions app/components/Contacts/ContactsPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
showSuccessNotification,
} from '../../../modules/notifications'
import { showModal } from '../../../modules/modal'
import withChainData from '../../../hocs/withChainData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const actionCreators = {
showModal,
Expand All @@ -35,8 +35,7 @@ export default compose(
mapDispatchToProps,
),
withRouter,
withChainData(),
withActions(deleteContactActions, mapContactActionsToProps),
withFailureNotification(deleteContactActions),
injectIntl,
)(ContactsPanel)
)(withSettingsContext(ContactsPanel))
5 changes: 2 additions & 3 deletions app/components/Contacts/EditContactPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import withProgressChange from '../../../hocs/withProgressChange'
import withFailureNotification from '../../../hocs/withFailureNotification'
import { showModal } from '../../../modules/modal'
import withChainData from '../../../hocs/withChainData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const { LOADED } = progressValues

Expand Down Expand Up @@ -56,10 +56,9 @@ export default compose(
LOADED,
(state, props) => props.onSave && props.onSave(),
),
withChainData(),
withActions(updateContactActions, mapContactActionsToProps),
withActions(deleteContactActions, mapDeleteContactActionsToProps),
withFailureNotification(deleteContactActions),
withFailureNotification(updateContactActions),
injectIntl,
)(EditContactPanel)
)(withSettingsContext(EditContactPanel))
5 changes: 2 additions & 3 deletions app/components/CreateImportWalletForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { injectIntl } from 'react-intl'

import CreateImportWalletForm from './CreateImportWalletForm'
import { generateNewWalletAccount } from '../../modules/generateWallet'
import withChainData from '../../hocs/withChainData'
import withSettingsContext from '../../hocs/withSettingsContext'

const actionCreators = {
generateNewWalletAccount,
Expand All @@ -21,5 +21,4 @@ export default compose(
null,
mapDispatchToProps,
),
withChainData(),
)(injectIntl(CreateImportWalletForm))
)(withSettingsContext(injectIntl(CreateImportWalletForm)))
5 changes: 2 additions & 3 deletions app/components/Dashboard/AssetBalancesPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import withFailureNotification from '../../../hocs/withFailureNotification'
import withNetworkData from '../../../hocs/withNetworkData'
import withAuthData from '../../../hocs/withAuthData'
import withFilteredTokensData from '../../../hocs/withFilteredTokensData'
import withChainData from '../../../hocs/withChainData'
import { ASSETS } from '../../../core/constants'
import { toBigNumber } from '../../../core/math'
import withSettingsContext from '../../../hocs/withSettingsContext'

const mapBalanceDataToProps = balances => ({
NEO: balances.NEO,
Expand Down Expand Up @@ -66,7 +66,6 @@ export default compose(
// Reload data with the currency changes.
withNetworkData(),
withAuthData(),
withChainData(),
withFilteredTokensData(),
withProgressPanel(assetBalancesPanelActions, {
title: <FormattedMessage id="dashboardAssetsPanelLabel" />,
Expand All @@ -90,4 +89,4 @@ export default compose(
{},
true,
),
)(AssetBalancesPanel)
)(withSettingsContext(AssetBalancesPanel))
3 changes: 2 additions & 1 deletion app/components/HeaderBar/HeaderBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import N3Logo from '../../assets/images/n3_logo.png'
import OldNeoLogo from '../../assets/images/neo-logo.png'

import styles from './HeaderBar.scss'
import { MAIN_NETWORK_ID } from '../../core/constants'

const NEO_IMAGE = imageMap.NEO

Expand Down Expand Up @@ -40,7 +41,7 @@ export default class HeaderBar extends React.PureComponent<Props> {

return (
<React.Fragment>
{!isMainNetwork(networkId) && (
{!isMainNetwork(networkId || MAIN_NETWORK_ID) && (
<div className={styles.currentNetwork}>{net}</div>
)}
<div className={styles.headerBar}>
Expand Down
7 changes: 2 additions & 5 deletions app/components/HeaderBar/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// @flow
import { compose } from 'recompose'
import withChainData from '../../hocs/withChainData'

import withNetworkData from '../../hocs/withNetworkData'
import withSettingsContext from '../../hocs/withSettingsContext'
import HeaderBar from './HeaderBar'

export default compose(
withNetworkData(),
withChainData(),
)(HeaderBar)
export default compose(withNetworkData())(withSettingsContext(HeaderBar))
5 changes: 2 additions & 3 deletions app/components/Migration/CreateMigrationWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { injectIntl } from 'react-intl'

import CreateMigrationWallet from './CreateMigrationWallet'
import { generateNewWalletAccount } from '../../../modules/generateWallet'
import withChainData from '../../../hocs/withChainData'
import withAuthData from '../../../hocs/withAuthData'
import withNetworkData from '../../../hocs/withNetworkData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const actionCreators = {
generateNewWalletAccount,
Expand All @@ -23,6 +23,5 @@ export default compose(
mapDispatchToProps,
),
withAuthData(),
withChainData(),
withNetworkData(),
)(injectIntl(CreateMigrationWallet))
)(withSettingsContext(injectIntl(CreateMigrationWallet)))
5 changes: 2 additions & 3 deletions app/components/Migration/TokenSwap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { injectIntl } from 'react-intl'

import TokenSwap from './TokenSwap'
import { generateNewWalletAccount } from '../../../modules/generateWallet'
import withChainData from '../../../hocs/withChainData'
import withAuthData from '../../../hocs/withAuthData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const actionCreators = {
generateNewWalletAccount,
Expand All @@ -22,5 +22,4 @@ export default compose(
mapDispatchToProps,
),
withAuthData(),
withChainData(),
)(injectIntl(TokenSwap))
)(withSettingsContext(injectIntl(TokenSwap)))
5 changes: 2 additions & 3 deletions app/components/Modals/AddContactModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { showSuccessNotification } from '../../../modules/notifications'

import AddContactModal from './AddContactModal'
import { addContactActions } from '../../../actions/contactsActions'
import withChainData from '../../../hocs/withChainData'
import withSettingsContext from '../../../hocs/withSettingsContext'

const mapContactActionsToProps = (actions: Object) => ({
onSave: (name: string, address: string, chain: string) =>
Expand All @@ -26,6 +26,5 @@ export default compose(
null,
mapDispatchToProps,
),
withChainData(),
withActions(addContactActions, mapContactActionsToProps),
)(AddContactModal)
)(withSettingsContext(AddContactModal))
Loading