-
Notifications
You must be signed in to change notification settings - Fork 22
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
(15) refactor: network settings actions #360
Changes from 13 commits
5b16276
300e4b4
d14be82
7ffd6eb
461f1d4
e938aea
46de5af
03ba63f
61d88a5
0352e19
c70ac97
02acec2
67fa735
1be1450
0f97f75
e0ad2a1
393eb4b
185670b
51609ad
bbb8f5d
f31c263
3825b2e
d994fdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -120,11 +120,22 @@ export const types = { | |||||||||
// NOTE: These actions follows a taxonomy that should be applied | ||||||||||
// to all other actions. | ||||||||||
// See: https://github.com/HathorNetwork/hathor-wallet-mobile/issues/334 | ||||||||||
NETWORKSETTINGS_UPDATE: 'NETWORK_SETTINGS_UPDATE', | ||||||||||
/* It delivers the user's network settings input from the form. */ | ||||||||||
NETWORKSETTINGS_UPDATE_REQUEST: 'NETWORK_SETTINGS_UPDATE_REQUEST', | ||||||||||
/* It updates the redux state */ | ||||||||||
NETWORKSETTINGS_UPDATE_STATE: 'NETWORKSETTINGS_UPDATE_STATE', | ||||||||||
/* It persists the complete structure of network settings in the app storage and updates the redux store. */ | ||||||||||
NETWORKSETTINGS_PERSIST_STORE: 'NETWORKSETTINGS_PERSIST_STORE', | ||||||||||
/* It indicates the persistence is complete and the wallet will be reloaded. */ | ||||||||||
NETWORKSETTINGS_UPDATE_WAITING: 'NETWORKSETTINGS_UPDATE_WAITING', | ||||||||||
/* It indicates the update is complete after wallet reloads. */ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved: d994fdb |
||||||||||
NETWORKSETTINGS_UPDATE_SUCCESS: 'NETWORK_SETTINGS_UPDATE_SUCCESS', | ||||||||||
NETWORKSETTINGS_UPDATE_READY: 'NETWORK_SETTINGS_UPDATE_READY', | ||||||||||
/* It indicates the update request has invalid inputs. */ | ||||||||||
NETWORKSETTINGS_UPDATE_INVALID: 'NETWORKSETTINGS_UPDATE_INVALID', | ||||||||||
/* It indicates the update request has failed. */ | ||||||||||
NETWORKSETTINGS_UPDATE_FAILURE: 'NETWORK_SETTINGS_UPDATE_FAILURE', | ||||||||||
NETWORKSETTINGS_UPDATE_ERRORS: 'NETWORK_SETTINGS_UPDATE_ERRORS', | ||||||||||
/* It updates the redux state of network settings status */ | ||||||||||
NETWORKSETTINGS_UPDATE_READY: 'NETWORK_SETTINGS_UPDATE_READY', | ||||||||||
}; | ||||||||||
|
||||||||||
export const featureToggleInitialized = () => ({ | ||||||||||
|
@@ -861,13 +872,13 @@ export const setWCConnectionFailed = (failed) => ({ | |||||||||
* walletServiceWsUrl?: string | ||||||||||
* }} customNetworkRequest Request input | ||||||||||
*/ | ||||||||||
export const networkSettingsUpdate = (customNetworkRequest) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE, | ||||||||||
export const networkSettingsUpdateRequest = (customNetworkRequest) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_REQUEST, | ||||||||||
payload: customNetworkRequest, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits the custom network settings to be stored and persisted. | ||||||||||
* Emits the custom network settings to update the redux store. | ||||||||||
* @param {{ | ||||||||||
* stage: string, | ||||||||||
* network: string, | ||||||||||
|
@@ -878,22 +889,56 @@ export const networkSettingsUpdate = (customNetworkRequest) => ({ | |||||||||
* walletServiceWsUrl?: string | ||||||||||
* }} customNetwork Settings to persist | ||||||||||
*/ | ||||||||||
export const networkSettingsUpdateSuccess = (customNetwork) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_SUCCESS, | ||||||||||
export const networkSettingsUpdateState = (customNetwork) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_STATE, | ||||||||||
payload: customNetwork, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits the custom network settings to persist in the app storage and update the redux store. | ||||||||||
* @param {{ | ||||||||||
* stage: string, | ||||||||||
* network: string, | ||||||||||
* nodeUrl: string, | ||||||||||
* explorerUrl: string, | ||||||||||
* explorerServiceUrl: string, | ||||||||||
* walletServiceUrl?: string | ||||||||||
* walletServiceWsUrl?: string | ||||||||||
* }} customNetwork Settings to persist | ||||||||||
*/ | ||||||||||
export const networkSettingsPersistStore = (customNetwork) => ({ | ||||||||||
type: types.NETWORKSETTINGS_PERSIST_STORE, | ||||||||||
payload: customNetwork, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits the waiting signal after persist the custom network. | ||||||||||
* It means the wallet will reload. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved: d994fdb |
||||||||||
*/ | ||||||||||
export const networkSettingsUpdateWaiting = () => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_WAITING, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits the success signal after wallet reloads. | ||||||||||
* It servers as hook for the frontend to provide feedback for the user. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here (and in the previous comments) is that the action by itself does not emit anything, somewhere else is dispatching this action There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved: d994fdb |
||||||||||
*/ | ||||||||||
export const networkSettingsUpdateSuccess = () => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_SUCCESS, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits the failure signal for custom network settings request. | ||||||||||
* It means the request couldn't be processed due to internal error. | ||||||||||
* It servers as hook for the frontend to provide feedback for the user. | ||||||||||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
*/ | ||||||||||
export const networkSettingsUpdateFailure = () => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_FAILURE, | ||||||||||
}); | ||||||||||
|
||||||||||
/** | ||||||||||
* Emits errors signal for custom network settings form representing | ||||||||||
* invalid inputs. | ||||||||||
* Emits invalid signal for custom network settings request inputs. | ||||||||||
* It means the form should present the invalid message on the corresponding inputs. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved: d994fdb |
||||||||||
* @param {{ | ||||||||||
* message: string, | ||||||||||
* nodeUrl: string, | ||||||||||
|
@@ -903,8 +948,8 @@ export const networkSettingsUpdateFailure = () => ({ | |||||||||
* walletServiceWsUrl?: string | ||||||||||
* }} errors The validation errors from custom network settings form | ||||||||||
*/ | ||||||||||
export const networkSettingsUpdateErrors = (errors) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_ERRORS, | ||||||||||
export const networkSettingsUpdateInvalid = (errors) => ({ | ||||||||||
type: types.NETWORKSETTINGS_UPDATE_INVALID, | ||||||||||
payload: errors, | ||||||||||
}); | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,28 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import { useSelector } from 'react-redux'; | ||
import { eq } from 'lodash'; | ||
import { isEqual } from 'lodash'; | ||
import { t } from 'ttag'; | ||
import { AlertUI } from '../../styles/themes'; | ||
import { ToplineBar } from '../ToplineBar'; | ||
import { PRE_SETTINGS_MAINNET } from '../../constants'; | ||
|
||
const customNetworkText = t`Custom network`; | ||
|
||
function notMainnet(networkSettings) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method deserves a comment explaining why you split the validation in two. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added: f31c263 |
||
return !isEqual(networkSettings, PRE_SETTINGS_MAINNET); | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const style = { | ||
backgroundColor: AlertUI.primaryColor, | ||
color: AlertUI.dark40Color, | ||
}; | ||
|
||
export const NetworkStatusBar = () => { | ||
const getStatusText = (networkSettings) => `${customNetworkText}: ${networkSettings.network}`; | ||
const networkSettings = useSelector((state) => state.networkSettings); | ||
if (eq(networkSettings, PRE_SETTINGS_MAINNET)) { | ||
return null; | ||
} | ||
|
||
const style = { | ||
backgroundColor: AlertUI.primaryColor, | ||
color: AlertUI.dark40Color, | ||
}; | ||
const text = `${customNetworkText}: ${networkSettings.network}`; | ||
return ( | ||
<ToplineBar style={style} text={text} /> | ||
return notMainnet(networkSettings) && ( | ||
<ToplineBar style={style} text={getStatusText(networkSettings)} /> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved: d994fdb