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

[Wallet] Wallet can switch between hosted and local node #1419

Merged
merged 66 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1242a1f
Always write key to disk to allow to switch into zero sync mode
annakaz Oct 11, 2019
1e7fa99
Add celo lite settings component
annakaz Oct 11, 2019
1eaf14d
Add celo lite settings link
annakaz Oct 11, 2019
5f1443e
Update state to keep track of sync mode, account in web3 keystore
annakaz Oct 11, 2019
d170908
Make celo lite settings screen responsive
annakaz Oct 11, 2019
e49e37a
WIP switching
annakaz Oct 14, 2019
6e0f4bf
Merge branch 'master' into annakaz/zero-sync-option
annakaz Oct 14, 2019
304b8c2
Fixing redux saga logic
annakaz Oct 14, 2019
a017e5b
Get sagas working
annakaz Oct 14, 2019
b34d55d
Move zeroSync logic out, refactor assignAccountFromPrivateKey
annakaz Oct 14, 2019
b0dc9b3
Moving more logic to web3/zeroSync
annakaz Oct 14, 2019
2f9dc16
Merge branch 'master' into annakaz/zero-sync-option
annakaz Oct 14, 2019
d46e1cf
Yield select whenever zeroSync mode needed
annakaz Oct 14, 2019
8f7db2c
Switching between providers
annakaz Oct 14, 2019
eafce36
check sync mode via web3 provider
annakaz Oct 14, 2019
e12c0cf
switch web3 provider when necessary
annakaz Oct 14, 2019
dae95b3
Default to starting in full sync mode
annakaz Oct 14, 2019
a9a3dde
Revert changes to functions using sendTransaction
annakaz Oct 14, 2019
cfcd1fb
Handle isZeroSync mode using web3 object
annakaz Oct 15, 2019
15d7653
Ensure private key exists/web3 keystore exists for switch
annakaz Oct 15, 2019
b71ad0c
Switch to always reading zeroSync state from web3
annakaz Oct 15, 2019
efcfcee
Merge branch 'master' into annakaz/zero-sync-toggle
annakaz Oct 16, 2019
76abb84
Stop storing account in web3 keystore separately
annakaz Oct 16, 2019
9b44218
Remove zerosync logic
annakaz Oct 16, 2019
cfa940c
Remove zerosync file
annakaz Oct 16, 2019
bb210fa
Revert logic changes to save for diffrerent pr
annakaz Oct 16, 2019
8e5d46b
Remove some unused styles
annakaz Oct 16, 2019
d79988c
Comment out celoLite settings for now
annakaz Oct 16, 2019
8735f97
Add spanish translations, a couple comments
annakaz Oct 16, 2019
332e24e
Add jest tests
annakaz Oct 16, 2019
03cfa6f
Add Licenses test
annakaz Oct 16, 2019
1d33eb9
Update spanish translations
annakaz Oct 16, 2019
6843c4e
Fix linting error
annakaz Oct 16, 2019
e8a529d
Merge branch 'master' into annakaz/zero-sync-toggle
annakaz Oct 16, 2019
8a5a917
Merge branch 'master' into annakaz/zero-sync-toggle
annakaz Oct 16, 2019
456f72f
Merge branch 'master' into annakaz/zero-sync-toggle
annakaz Oct 17, 2019
3c448b4
Switch to generator fns in verification
annakaz Oct 17, 2019
93c15b3
Field yield all
annakaz Oct 17, 2019
b0b7401
Move invite to saga (working and tested on integration)
annakaz Oct 17, 2019
74c73da
WIP turing send to generators, not working
annakaz Oct 17, 2019
8e18032
Finish switch to generators
annakaz Oct 17, 2019
3beff76
Use zeroSync state throughout
annakaz Oct 17, 2019
6082761
Finish switch over to only using state, excet in intialization web3
annakaz Oct 17, 2019
cc32812
WIP getting zerosync to actually turn on
annakaz Oct 18, 2019
3adf667
Merge branch 'master' into annakaz/zero-sync-toggle-logic
annakaz Oct 21, 2019
72b46ba
Get switch from geth to zerosync working (tested w exchange, only sam…
annakaz Oct 21, 2019
e6b1139
Add back in zeroSync check in addLocalAccount
annakaz Oct 21, 2019
0d306a8
Turn zeroSync on/off now working in same session (geth always running)
annakaz Oct 21, 2019
182d1c8
Add sync mode checker to initial app load. Tested going from geth to …
annakaz Oct 21, 2019
ebbe915
Rename to initiallyZeroSync mode, use put in toggle saga
annakaz Oct 21, 2019
a0fa526
App refresh for either mode
annakaz Oct 21, 2019
bd92712
web3/saga cleanup
annakaz Oct 21, 2019
df3d392
Store zeroSync param separate from sync mode
annakaz Oct 21, 2019
f0fa40d
Merge branch 'master' into annakaz/zero-sync-toggle-logic
annakaz Oct 21, 2019
ff7261a
Update env files with zeroSync mode
annakaz Oct 22, 2019
9cd47ca
Update accounts snapshot
annakaz Oct 22, 2019
376920d
Clean up for review
annakaz Oct 22, 2019
9c7fd33
Make changes based on review
annakaz Oct 22, 2019
f2bf8c1
Merge branch 'master' into annakaz/zero-sync-toggle-logic
annakaz Oct 23, 2019
5bc42c5
Remove unnecessary yield puts causing loop"
annakaz Oct 23, 2019
30fa17d
Turn geth off, fix tests, use back button in header
annakaz Oct 23, 2019
59ae0f6
Make zeroSyncInitially false for all env files
annakaz Oct 23, 2019
9fbb5c8
Merge branch 'master' into annakaz/zero-sync-toggle-logic
annakaz Oct 23, 2019
5faf4b6
Wait for web3 to sync after switching to geth
annakaz Oct 23, 2019
d45f1e6
PR cleanup
annakaz Oct 23, 2019
a615862
Merge branch 'master' into annakaz/zero-sync-toggle-logic
annakaz Oct 24, 2019
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
20 changes: 10 additions & 10 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why my pre commit hook reformats this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it did the same for me, i had to manually revert it. But it's nbd feel free to leave in this PR

Many packages depend on other packages within the monorepo. When this happens, follow these rules:

1. All packages must use **master version** of sibling packages.
2. Exception to (1) are packages that represent a GAE/firebase app which must use the last published version.
3. To differentiate published vs unpublished version. Master version (in package.json) must end with suffix `-dev` and should not be published.
4. If a developer want to publish a version; then after publishing it needs to set master version to next `-dev` version and change all package.json that require on it.
1. All packages must use **master version** of sibling packages.
2. Exception to (1) are packages that represent a GAE/firebase app which must use the last published version.
3. To differentiate published vs unpublished version. Master version (in package.json) must end with suffix `-dev` and should not be published.
4. If a developer want to publish a version; then after publishing it needs to set master version to next `-dev` version and change all package.json that require on it.

To check which pakages need amending, you can run (in the root pkg):

yarn check:packages

A practical example:

* In any given moment, `contractkit/package.json#version` field **must** of the form `x.y.z-dev`
* If current version of contractkit is: `0.1.6-dev` and we want to publish a new version, we should:
* publish version `0.1.6`
* change `package.json#version` to `0.1.7-dev`
* change in other packages within monorepo that were using `0.1.6-dev` to `0.1.7-dev`
- In any given moment, `contractkit/package.json#version` field **must** of the form `x.y.z-dev`
- If current version of contractkit is: `0.1.6-dev` and we want to publish a new version, we should:
- publish version `0.1.6`
- change `package.json#version` to `0.1.7-dev`
- change in other packages within monorepo that were using `0.1.6-dev` to `0.1.7-dev`

## How to publish a new npm package

First checkout the alfajores branch.
Expand Down
8 changes: 5 additions & 3 deletions packages/mobile/.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
ENVIRONMENT=local
DEFAULT_TESTNET=integration
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
DEFAULT_TESTNET=alfajores
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=true
FIREBASE_ENABLED=true
SECRETS_KEY=debug
SHOW_TESTNET_BANNER=true
SHOW_TESTNET_BANNER=true
4 changes: 3 additions & 1 deletion packages/mobile/.env.alfajores
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=alfajores
DEFAULT_TESTNET=alfajores
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=false
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.integration
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=integration
DEFAULT_TESTNET=integration
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=true
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.pilot
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=pilot
DEFAULT_TESTNET=pilot
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=false
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.pilotstaging
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=pilotstaging
DEFAULT_TESTNET=pilotstaging
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=true
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.production
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=production
DEFAULT_TESTNET=argentinaproduction
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=false
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.staging
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=staging
DEFAULT_TESTNET=alfajoresstaging
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=true
FIREBASE_ENABLED=true
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/.env.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ENVIRONMENT=local
DEFAULT_TESTNET=integration
# -1 == ZeroSync, 5 == Ultralight, see src/geth/consts.ts for more info
# If ZERO_SYNC_ENABLED_INITIALLY, local geth will not run initially.
# If toggled on, it will use DEFAULT_SYNC_MODE. See src/geth/consts.ts for more info
ZERO_SYNC_ENABLED_INITIALLY=false
DEFAULT_SYNC_MODE=5
DEV_SETTINGS_ACTIVE_INITIALLY=true
FIREBASE_ENABLED=false
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/locales/en-US/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"web3FailedToSync": "Failing to sync, check your network connection",
"errorDuringSync": "Error occurred during sync, please try again later",
"calculateFeeFailed": "Could not calculate fee",
"failedToSwitchSyncModes": "Failed to switch sync modes",
"gold": "Gold",
"localCurrencyTitle": "Select Currency"
}
1 change: 1 addition & 0 deletions packages/mobile/locales/es-419/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"web3FailedToSync": "Fallo la sincronización, por favor verifica tu conexión",
"errorDuringSync": "Ocurrió un error duranet la sincronización, por favor intente más tarde",
"calculateFeeFailed": "No se pudo calcular la comisión",
"failedToSwitchSyncModes": "Error al cambiar de red modos",
"gold": "Oro",
"localCurrencyTitle": "Seleccione el tipo de moneda"
}
4 changes: 1 addition & 3 deletions packages/mobile/src/account/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ export class Account extends React.Component<Props, State> {
<SettingsItem title={t('celoRewards')} onPress={navigateToVerifierApp} />
)}
<SettingsItem title={t('analytics')} onPress={this.goToAnalytics} />
{/* // TODO(anna) Disabled until switch geth on/off is implemented
<SettingsItem title={t('celoLite')} onPress={this.goToCeloLite} />
*/}
<SettingsItem title={t('celoLite')} onPress={this.goToCeloLite} />
<SettingsItem title={t('languageSettings')} onPress={this.goToLanguageSetting} />
<SettingsItem
title={t('localCurrencySetting')}
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/account/CeloLite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WithNamespaces, withNamespaces } from 'react-i18next'
import { ScrollView, StyleSheet, Text } from 'react-native'
import { connect } from 'react-redux'
import i18n, { Namespaces } from 'src/i18n'
import { headerWithCancelButton } from 'src/navigator/Headers'
import { headerWithBackButton } from 'src/navigator/Headers'
import { RootState } from 'src/redux/reducers'
import { setZeroSyncMode } from 'src/web3/actions'

Expand All @@ -32,7 +32,7 @@ const mapStateToProps = (state: RootState): StateProps => {

export class CeloLite extends React.Component<Props> {
static navigationOptions = () => ({
...headerWithCancelButton,
...headerWithBackButton,
headerTitle: i18n.t('accountScreen10:celoLite'),
})

Expand Down
150 changes: 150 additions & 0 deletions packages/mobile/src/account/__snapshots__/Account.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,81 @@ exports[`Account renders correctly 1`] = `
</View>
</View>
</View>
<View
accessible={true}
isTVSelectable={true}
nativeBackgroundAndroid={
Object {
"attribute": "selectableItemBackground",
"type": "ThemeAttrAndroid",
}
}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View
style={
Object {
"borderBottomWidth": 1,
"borderColor": "#EEEEEE",
"flexDirection": "row",
"justifyContent": "space-between",
"marginLeft": 15,
"padding": 20,
}
}
>
<View
style={
Array [
Object {
"justifyContent": "center",
},
]
}
>
<Text
style={
Object {
"color": "#2E3338",
"fontFamily": "Hind-Regular",
"fontSize": 16,
"lineHeight": 24,
}
}
>
celoLite
</Text>
</View>
<View
style={
Array [
Object {
"justifyContent": "center",
},
]
}
>
<svg
height={16}
style={Object {}}
viewBox="0 0 15 15"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.70376 9.12461L2.12123 15.7071C1.73071 16.0976 1.09755 16.0976 0.707015 15.7071C0.316497 15.3166 0.316497 14.6834 0.707015 14.2929L6.58575 8.41419L0.707091 2.53553C0.316573 2.14501 0.316573 1.51185 0.707091 1.12131C1.09761 0.730797 1.73079 0.730797 2.12131 1.12131L8.70708 7.70708C9.0976 8.09762 9.0976 8.73078 8.70708 9.1213L8.70376 9.12461Z"
fill="#42D689"
style={Object {}}
/>
</svg>
</View>
</View>
</View>
<View
accessible={true}
isTVSelectable={true}
Expand Down Expand Up @@ -1382,6 +1457,81 @@ exports[`Account renders correctly when dev mode active 1`] = `
</View>
</View>
</View>
<View
accessible={true}
isTVSelectable={true}
nativeBackgroundAndroid={
Object {
"attribute": "selectableItemBackground",
"type": "ThemeAttrAndroid",
}
}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View
style={
Object {
"borderBottomWidth": 1,
"borderColor": "#EEEEEE",
"flexDirection": "row",
"justifyContent": "space-between",
"marginLeft": 15,
"padding": 20,
}
}
>
<View
style={
Array [
Object {
"justifyContent": "center",
},
]
}
>
<Text
style={
Object {
"color": "#2E3338",
"fontFamily": "Hind-Regular",
"fontSize": 16,
"lineHeight": 24,
}
}
>
celoLite
</Text>
</View>
<View
style={
Array [
Object {
"justifyContent": "center",
},
]
}
>
<svg
height={16}
style={Object {}}
viewBox="0 0 15 15"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M8.70376 9.12461L2.12123 15.7071C1.73071 16.0976 1.09755 16.0976 0.707015 15.7071C0.316497 15.3166 0.316497 14.6834 0.707015 14.2929L6.58575 8.41419L0.707091 2.53553C0.316573 2.14501 0.316573 1.51185 0.707091 1.12131C1.09761 0.730797 1.73079 0.730797 2.12131 1.12131L8.70708 7.70708C9.0976 8.09762 9.0976 8.73078 8.70708 9.1213L8.70376 9.12461Z"
fill="#42D689"
style={Object {}}
/>
</svg>
</View>
</View>
</View>
<View
accessible={true}
isTVSelectable={true}
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/app/ErrorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ export enum ErrorMessages {
QR_FAILED_INVALID_ADDRESS = 'qrFailedInvalidAddress',
CORRUPTED_CHAIN_DELETED = 'corruptedChainDeleted',
CALCULATE_FEE_FAILED = 'calculateFeeFailed',
FAILED_TO_SWITCH_SYNC_MODES = 'failedToSwitchSyncModes',
FAILED_FETCH_MNEMONIC = 'failedFetchMnemonic',
}
15 changes: 15 additions & 0 deletions packages/mobile/src/app/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Screens, Stacks } from 'src/navigator/Screens'
import { PersistedRootState } from 'src/redux/reducers'
import Logger from 'src/utils/Logger'
import { clockInSync } from 'src/utils/time'
import { setZeroSyncMode } from 'src/web3/actions'
import { isInitiallyZeroSyncMode } from 'src/web3/contracts'
import { zeroSyncSelector } from 'src/web3/selectors'

const TAG = 'app/saga'

Expand Down Expand Up @@ -58,6 +61,17 @@ export function* checkAppDeprecation() {
}
}

// Upon every app restart, web3 is initialized according to .env file
// This updates to the chosen zeroSync mode in store
export function* toggleToProperSyncMode() {
Logger.info(TAG, '@toggleToProperSyncMode ensuring proper sync mode...')
yield take(REHYDRATE)
const zeroSyncMode = yield select(zeroSyncSelector)
if (zeroSyncMode !== isInitiallyZeroSyncMode()) {
yield put(setZeroSyncMode(zeroSyncMode))
}
}

export function* navigateToProperScreen() {
yield all([take(REHYDRATE), take(NavActions.SET_NAVIGATOR)])

Expand Down Expand Up @@ -120,4 +134,5 @@ export function handleDeepLink(deepLink: string) {
export function* appSaga() {
yield spawn(checkAppDeprecation)
yield spawn(navigateToProperScreen)
yield spawn(toggleToProperSyncMode)
}
4 changes: 4 additions & 0 deletions packages/mobile/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ export const GOLD_TRANSACTION_MIN_AMOUNT = 0.001
export const DEFAULT_SYNC_MODE: GethSyncMode = Config.DEFAULT_SYNC_MODE
? new BigNumber(Config.DEFAULT_SYNC_MODE).toNumber()
: GethSyncMode.Ultralight

export const ZERO_SYNC_ENABLED_INITIALLY = Config.ZERO_SYNC_ENABLED_INITIALLY
? stringToBoolean(Config.ZERO_SYNC_ENABLED_INITIALLY)
: false
Loading