From 26b641a5665cb588ea8a4d03db45177181e18210 Mon Sep 17 00:00:00 2001 From: Daniel Laanpere Date: Sun, 16 Feb 2020 15:40:40 +0200 Subject: [PATCH 01/49] setup android build to succeed --- android/app/build.gradle | 4 +- .../main/java/com/obby/MainApplication.java | 10 +- android/settings.gradle | 2 + app.json | 2 +- package.json | 2 +- src/reducers/balances.js | 1 + src/sagas/device.js | 1 + src/screens/ChatListScreen/index.js | 96 +++++----- src/screens/ChatListScreen/styles.js | 13 ++ src/screens/PaymentScreen/index.js | 2 +- yarn.lock | 178 +++++++++--------- 11 files changed, 170 insertions(+), 141 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a46f9be1..855a93dc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -134,6 +134,7 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" + missingDimensionStrategy 'react-native-camera', 'general' } splits { abi { @@ -182,8 +183,9 @@ android { dependencies { implementation project(':react-native-randombytes') implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation "com.facebook.react:react-native:+" // From node_modules + implementation "com.facebook.react:react-native:0.61.5" // From node_modules addUnimodulesDependencies() + implementation project(':react-native-camera') if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; diff --git a/android/app/src/main/java/com/obby/MainApplication.java b/android/app/src/main/java/com/obby/MainApplication.java index cd476145..0b983e13 100644 --- a/android/app/src/main/java/com/obby/MainApplication.java +++ b/android/app/src/main/java/com/obby/MainApplication.java @@ -3,6 +3,7 @@ import android.app.Application; import android.content.Context; import com.facebook.react.PackageList; +import com.facebook.react.shell.MainReactPackage; import com.facebook.react.ReactApplication; import com.bitgo.randombytes.RandomBytesPackage; import com.facebook.react.ReactNativeHost; @@ -10,7 +11,9 @@ import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; import java.util.List; -import com.myapp.generated.BasePackageList; +import java.util.Arrays; +import com.obby.generated.BasePackageList; +import org.reactnative.camera.RNCameraPackage; import org.unimodules.adapters.react.ModuleRegistryAdapter; import org.unimodules.adapters.react.ReactModuleRegistryProvider; import org.unimodules.core.interfaces.SingletonModule; @@ -29,10 +32,7 @@ public boolean getUseDeveloperSupport() { @Override protected List getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") - List packages = new PackageList(this).getPackages() { - new MainReactPackage(), - new ModuleRegistryAdapter(mModuleRegistryProvider) - }; + List packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); return packages; diff --git a/android/settings.gradle b/android/settings.gradle index d076af0d..659d02e1 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -5,3 +5,5 @@ include ':react-native-randombytes' project(':react-native-randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' +include ':react-native-camera' +project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') \ No newline at end of file diff --git a/app.json b/app.json index 34fe6bbb..4ac8c12e 100644 --- a/app.json +++ b/app.json @@ -1,4 +1,4 @@ { - "name": "Obby chat", + "name": "Obby", "displayName": "Obby chat" } diff --git a/package.json b/package.json index d1defaeb..308f932a 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "react-native-tcp": "^3.3.2", "react-native-timeago": "^0.5.0", "react-native-udp": "^2.6.1", - "react-native-unimodules": "^0.6.0", + "react-native-unimodules": "^0.7.0", "react-native-user-avatar": "^1.0.4", "react-native-webview": "^7.5.2", "react-navigation": "^4.1.0", diff --git a/src/reducers/balances.js b/src/reducers/balances.js index 376a6306..d452fa9e 100644 --- a/src/reducers/balances.js +++ b/src/reducers/balances.js @@ -7,6 +7,7 @@ const initialState = { }; function reducer(state = initialState, action) { + console.log(action.type); // TODO: remove switch (action.type) { case REHYDRATE: return _.get(action, 'payload.balances', state); diff --git a/src/sagas/device.js b/src/sagas/device.js index 41b787e0..86f3bae4 100644 --- a/src/sagas/device.js +++ b/src/sagas/device.js @@ -89,6 +89,7 @@ export function* subscribeToHub() { setInterval, () => { oClient.api.heartbeat(); + console.log('Heartbeat'); }, 10000, ); diff --git a/src/screens/ChatListScreen/index.js b/src/screens/ChatListScreen/index.js index cd938b0a..41e849ad 100644 --- a/src/screens/ChatListScreen/index.js +++ b/src/screens/ChatListScreen/index.js @@ -1,7 +1,7 @@ import React from 'react'; import { connect } from 'react-redux'; import { createStructuredSelector } from 'reselect'; -import { ScrollView } from 'react-native'; +import { ScrollView, View } from 'react-native'; import TimeAgo from 'react-native-timeago'; import UserAvatar from 'react-native-user-avatar'; import makeBlockie from 'ethereum-blockies-base64'; @@ -28,48 +28,58 @@ class ChatListScreen extends React.Component { titlePosition='left' right={} /> - - - {correspondents.map((correspondent, i) => ( - - this.props.navigation.navigate('Chat', { - correspondent, - }) - } - > - - - - - - {correspondent.name} - - - {correspondent.lastMessagePreview} - - - - - {correspondent.lastMessageTimestamp !== undefined && ( - - )} - - - - ))} - - + {!correspondents.length && ( + + + Start adding contacts by sharing your QR code or scanning someone + else's! + + + )} + {!!correspondents.length && ( + + + {correspondents.map((correspondent, i) => ( + + this.props.navigation.navigate('Chat', { + correspondent, + }) + } + > + + + + + + {correspondent.name} + + + {correspondent.lastMessagePreview} + + + + + {correspondent.lastMessageTimestamp !== undefined && ( + + )} + + + + ))} + + + )} ); } diff --git a/src/screens/ChatListScreen/styles.js b/src/screens/ChatListScreen/styles.js index 4ccb82f8..b5f23693 100644 --- a/src/screens/ChatListScreen/styles.js +++ b/src/screens/ChatListScreen/styles.js @@ -45,4 +45,17 @@ export default StyleSheet.create({ actionsBar: { flexDirection: 'row', }, + noContactsContainer: { + flex: 1, + padding: 10, + flexDirection: 'column', + justifyContent: 'center', + }, + noContactsText: { + color: colors.grey.main, + justifyContent: 'center', + textAlign: 'center', + fontFamily: 'Agenda-Light', + fontSize: 16, + }, }); diff --git a/src/screens/PaymentScreen/index.js b/src/screens/PaymentScreen/index.js index 72f4cb9e..2d4c9fef 100644 --- a/src/screens/PaymentScreen/index.js +++ b/src/screens/PaymentScreen/index.js @@ -233,7 +233,7 @@ class PaymentScreen extends React.Component { return (
Date: Sun, 16 Feb 2020 16:48:35 +0200 Subject: [PATCH 02/49] setup android build to succeed --- android/app/src/main/java/com/obby/MainApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/app/src/main/java/com/obby/MainApplication.java b/android/app/src/main/java/com/obby/MainApplication.java index 0b983e13..ae0b9a3f 100644 --- a/android/app/src/main/java/com/obby/MainApplication.java +++ b/android/app/src/main/java/com/obby/MainApplication.java @@ -33,6 +33,8 @@ public boolean getUseDeveloperSupport() { protected List getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List packages = new PackageList(this).getPackages(); + // packages.add(new MainReactPackage()); + packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider)); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); return packages; From a1cb21baf7da0a4a6afb7f0580c105c8acf5f77e Mon Sep 17 00:00:00 2001 From: Daniel Laanpere Date: Sun, 16 Feb 2020 16:49:56 +0200 Subject: [PATCH 03/49] filename case fix --- src/lib/{OCustom.js => oCustom.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/lib/{OCustom.js => oCustom.js} (100%) diff --git a/src/lib/OCustom.js b/src/lib/oCustom.js similarity index 100% rename from src/lib/OCustom.js rename to src/lib/oCustom.js From 5774b7a902ef9c87498a89cc830ad75906bd9bb7 Mon Sep 17 00:00:00 2001 From: Daniel Laanpere Date: Sun, 16 Feb 2020 19:28:50 +0200 Subject: [PATCH 04/49] new picker implementation, bug fixes --- package.json | 1 - src/components/Picker/index.js | 42 ++++++++++++++++++++++++++ src/components/Picker/styles.js | 22 ++++++++++++++ src/lib/oCustom.js | 4 --- src/lib/utils.js | 7 ++++- src/reducers/balances.js | 1 - src/reducers/wallet.js | 5 ++-- src/sagas/device.js | 10 ++----- src/sagas/wallet.js | 4 ++- src/screens/PaymentScreen/index.js | 24 +++++---------- src/screens/WalletScreen/index.js | 47 +++++++----------------------- yarn.lock | 12 -------- 12 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 src/components/Picker/index.js create mode 100644 src/components/Picker/styles.js diff --git a/package.json b/package.json index 308f932a..b641d395 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "react-native-level-fs": "^3.0.1", "react-native-os": "^1.2.6", "react-native-permissions": "^2.0.9", - "react-native-picker-select": "^6.3.3", "react-native-qrcode-scanner": "^1.3.1", "react-native-qrcode-svg": "^6.0.1", "react-native-randombytes": "^3.5.3", diff --git a/src/components/Picker/index.js b/src/components/Picker/index.js new file mode 100644 index 00000000..9d599c11 --- /dev/null +++ b/src/components/Picker/index.js @@ -0,0 +1,42 @@ +import React, { useCallback } from 'react'; +import { Picker as RNPicker, View, Text } from 'react-native'; + +import styles from './styles'; + +export default Picker = ({ + style, + onChange, + currentValue, + items = [], + ...restProps +}) => { + const onValueChanged = useCallback( + newValue => { + if (typeof onChange === 'function') { + onChange(newValue); + } + }, + [currentValue, onChange], + ); + + return ( + + {currentValue} + + {items.map(({ label, value }, i) => ( + + ))} + + + ); +}; diff --git a/src/components/Picker/styles.js b/src/components/Picker/styles.js new file mode 100644 index 00000000..9fa7432d --- /dev/null +++ b/src/components/Picker/styles.js @@ -0,0 +1,22 @@ +import { StyleSheet } from 'react-native'; +import { colors } from './../../constants'; + +export default StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'flex-end', + flexDirection: 'row', + }, + picker: { + width: 30, + height: 22, + padding: 0, + margin: 0, + }, + label: { + fontFamily: 'Agenda-Light', + fontSize: 16, + marginRight: 10, + color: colors.grey.main, + }, +}); diff --git a/src/lib/oCustom.js b/src/lib/oCustom.js index 8e5d255c..3465635f 100644 --- a/src/lib/oCustom.js +++ b/src/lib/oCustom.js @@ -239,7 +239,6 @@ export const createEncryptedPackage = (json, recipient_device_pubkey) => { var arrChunks = []; var CHUNK_LENGTH = 2003; for (var offset = 0; offset < text.length; offset += CHUNK_LENGTH) { - // console.log('offset '+offset); arrChunks.push( cipher.update( text.slice(offset, Math.min(offset + CHUNK_LENGTH, text.length)), @@ -250,10 +249,7 @@ export const createEncryptedPackage = (json, recipient_device_pubkey) => { arrChunks.push(cipher.final()); var encrypted_message_buf = Buffer.concat(arrChunks); arrChunks = null; - // var encrypted_message_buf = Buffer.concat([cipher.update(text, "utf8"), cipher.final()]); - //console.log(encrypted_message_buf); var encrypted_message = encrypted_message_buf.toString('base64'); - //console.log(encrypted_message); var authtag = cipher.getAuthTag(); // this is visible and verifiable by the hub var encrypted_package = { diff --git a/src/lib/utils.js b/src/lib/utils.js index bbd93452..22abb0be 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -48,9 +48,14 @@ export const unitToBytes = (n, unit) => { } }; -export const availableUnits = [ +export const PRIMARY_UNITS = [ { label: 'bytes', value: 'B', altValue: 'BYTE' }, { label: 'kB', value: 'kB', altValue: 'kBYTE' }, { label: 'MB', value: 'MB', altValue: 'MBYTE' }, { label: 'GB', value: 'GB', altValue: 'GBYTE' }, ]; + +export const SECONDARY_UNITS = [ + { label: 'USD', value: 'USD' }, + { label: 'BTC', value: 'BTC' }, +]; diff --git a/src/reducers/balances.js b/src/reducers/balances.js index d452fa9e..376a6306 100644 --- a/src/reducers/balances.js +++ b/src/reducers/balances.js @@ -7,7 +7,6 @@ const initialState = { }; function reducer(state = initialState, action) { - console.log(action.type); // TODO: remove switch (action.type) { case REHYDRATE: return _.get(action, 'payload.balances', state); diff --git a/src/reducers/wallet.js b/src/reducers/wallet.js index e0d1e5ee..d01b9f60 100644 --- a/src/reducers/wallet.js +++ b/src/reducers/wallet.js @@ -3,9 +3,8 @@ import { REHYDRATE } from 'redux-persist'; import { actionTypes } from '../constants'; const initialState = { - password: '', - seedWords: - 'wise pulp cruise wrap sunset run clap car budget key meadow diagram', + password: null, + seedWords: null, witnesses: [], }; diff --git a/src/sagas/device.js b/src/sagas/device.js index 86f3bae4..f661e9fa 100644 --- a/src/sagas/device.js +++ b/src/sagas/device.js @@ -76,7 +76,6 @@ export function* loginToHub(challenge) { export function* subscribeToHub() { try { - console.log('subscribe'); yield oClient.subscribe((err, result) => { if (err) { throw new Error('Hub socket error'); @@ -85,16 +84,14 @@ export function* subscribeToHub() { oChannel.put({ type, payload }); } }); - const hb = yield call( + yield call( setInterval, () => { oClient.api.heartbeat(); - console.log('Heartbeat'); }, 10000, ); } catch (error) { - yield setTimeout(() => subscribeToHub(), 5000); yield put( setToastMessage({ type: 'ERROR', @@ -115,7 +112,7 @@ export function* watchHubMessages() { } else if (payload.subject === 'hub/message') { yield receiveMessage(payload); } else if (payload.subject === 'exchange_rates') { - yield put(setExchangeRates(payload)); + yield put(setExchangeRates(payload.body)); } else if ( payload.subject === 'info' && /^(\d+) messages? sent$/.test(payload?.body) @@ -148,8 +145,6 @@ export function* receiveMessage(message) { permDeviceKey, tempDeviceKey, ); - console.log('ENCRYPTED MESSAGE: ', message); - console.log('DECRYPTED MESSAGE: ', decryptedMessage); if (decryptedMessage.subject === 'removed_paired_device') { yield put(removeCorrespondent({ address: decryptedMessage.from })); @@ -187,7 +182,6 @@ export function* receiveMessage(message) { } } catch (error) { console.log('MESSAGE PARSING ERROR:', { - error, message: message.body.message, }); if (error === 'INVALID_DECRYPTION_KEY') { diff --git a/src/sagas/wallet.js b/src/sagas/wallet.js index f190e0a0..35dd1876 100644 --- a/src/sagas/wallet.js +++ b/src/sagas/wallet.js @@ -5,6 +5,7 @@ import { oClient } from './../lib/oCustom'; import { actionTypes } from './../constants'; import { subscribeToHub } from './device'; import { setToastMessage } from './../actions/app'; +import { rotateDeviceTempKey } from '../actions/device'; import { createInitialWalletStart, createInitialWalletSuccess, @@ -35,7 +36,8 @@ let initiated = false; export function* initWallet() { try { - console.log('reload', initiated); + console.log('initiated', initiated); + // yield put(rotateDeviceTempKey()); if (!initiated) { const walletData = yield select(selectWallet()); if (walletData.password === null || walletData.seedWords === null) { diff --git a/src/screens/PaymentScreen/index.js b/src/screens/PaymentScreen/index.js index 2d4c9fef..ec014817 100644 --- a/src/screens/PaymentScreen/index.js +++ b/src/screens/PaymentScreen/index.js @@ -9,7 +9,6 @@ import { View, Text, } from 'react-native'; -import RNPickerSelect from 'react-native-picker-select'; import CopyIcon from './../../assets/images/icon-copy.svg'; import SafeAreaView from 'react-native-safe-area-view'; import _ from 'lodash'; @@ -17,13 +16,14 @@ import { isValidAddress } from 'obyte/lib/utils'; import Header from '../../components/Header'; import Button from '../../components/Button'; +import Picker from '../../components/Picker'; import styles from './styles'; import { colors } from '../../constants'; import { TouchableOpacity } from 'react-native-gesture-handler'; import { selectExchangeRates } from './../../selectors/exchangeRates'; import { selectWalletAddress } from './../../selectors/wallet'; import { sendPaymentStart } from './../../actions/wallet'; -import { availableUnits, unitToBytes } from './../../lib/utils'; +import { PRIMARY_UNITS, SECONDARY_UNITS, unitToBytes } from './../../lib/utils'; import { urlHost } from './../../lib/oCustom'; export const Methods = { @@ -179,7 +179,6 @@ class PaymentScreen extends React.Component { 'navigation.state.params.callback', false, ); - // TODO: finish the string const requestString = `[${this.state.primaryValue} ${ this.state.primaryUnit }](${urlHost}${this.props.myWalletAddress}?amount=${unitToBytes( @@ -290,14 +289,10 @@ class PaymentScreen extends React.Component { keyboardType='decimal-pad' autoFocus={true} /> - this.changePrimaryUnit(value)} - items={availableUnits.map(unit => ({ - label: unit.label, - value: unit.altValue, - }))} + items={PRIMARY_UNITS} /> @@ -307,13 +302,10 @@ class PaymentScreen extends React.Component { value={!secondaryValue ? '' : String(secondaryValue)} keyboardType='decimal-pad' /> - this.changeSecondaryUnit(value)} - items={[ - { label: 'USD', value: 'USD' }, - { label: 'BTC', value: 'BTC' }, - ]} + items={SECONDARY_UNITS} />