diff --git a/BlueComponents.js b/BlueComponents.js index bd81f7661..5624509c1 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -2026,7 +2026,7 @@ export class WalletsCarousel extends Component { itemWidth={itemWidth} inactiveSlideScale={1} inactiveSlideOpacity={0.7} - initialNumToRender={20} + initialNumToRender={4} onLayout={this.onLayout} contentContainerCustomStyle={{ left: -20 }} /> diff --git a/BlueElectrum.js b/BlueElectrum.js index 2d7fc559b..73d5a06fd 100644 --- a/BlueElectrum.js +++ b/BlueElectrum.js @@ -50,7 +50,7 @@ async function connectMain() { mainClient.close(); mainConnected = false; setTimeout(connectMain, 500); - console.warn('reconnecting after socket error'); + console.log('reconnecting after socket error'); return; } mainConnected = false; @@ -148,11 +148,15 @@ module.exports.getConfig = async function () { return { host: mainClient.host, port: mainClient.port, - status: mainClient.status && mainConnected ? 1 : 0, + status: mainClient.status ? 1 : 0, serverName, }; }; +module.exports.getSecondsSinceLastRequest = function () { + return mainClient && mainClient.timeLastCall ? (+new Date() - mainClient.timeLastCall) / 1000 : -1; +}; + /** * * @param address {String} diff --git a/android/app/build.gradle b/android/app/build.gradle index e8cf87c4e..150419b3c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -140,7 +140,7 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 - versionName "5.4.1" + versionName "5.4.2" multiDexEnabled true missingDimensionStrategy 'react-native-camera', 'general' testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type diff --git a/blue_modules/net.js b/blue_modules/net.js new file mode 100644 index 000000000..194215d15 --- /dev/null +++ b/blue_modules/net.js @@ -0,0 +1,114 @@ +/** + * @fileOverview adapter for ReactNative TCP module + * This module mimics the nodejs net api and is intended to work in RN environment. + * @see https://github.com/Rapsssito/react-native-tcp-socket + */ + +import TcpSocket from 'react-native-tcp-socket'; + +/** + * Constructor function. Resulting object has to act as it was a real socket (basically + * conform to nodejs/net api) + * + * @constructor + */ +function Socket() { + this._socket = false; // reference to socket thats gona be created later + + this._listeners = {}; + + // functions not supported by RN module, yet: + this.setTimeout = () => {}; + this.setEncoding = () => {}; + this.setKeepAlive = () => {}; + this.setNoDelay = () => {}; + + this.connect = (port, host, callback) => { + this._socket = TcpSocket.createConnection( + { + port, + host, + tls: false, + }, + callback, + ); + + this._socket.on('data', data => { + this._passOnEvent('data', data); + }); + this._socket.on('end', data => { + this._passOnEvent('end', data); + }); + this._socket.on('timeout', () => { + this._passOnEvent('timeout'); + }); + this._socket.on('onerror', data => { + this._passOnEvent('onerror', data); + }); + this._socket.on('error', data => { + this._passOnEvent('error', data); + }); + this._socket.on('close', data => { + this._passOnEvent('close', data); + }); + this._socket.on('connect', data => { + this._passOnEvent('connect', data); + }); + this._socket.on('secureConnect', data => { + this._passOnEvent('secureConnect', data); + }); + this._socket.on('connection', data => { + this._passOnEvent('connection', data); + }); + }; + + this._passOnEvent = (event, data) => { + this._listeners[event] = this._listeners[event] || []; + for (const savedListener of this._listeners[event]) { + savedListener(data); + } + }; + + this.on = (event, listener) => { + this._listeners[event] = this._listeners[event] || []; + this._listeners[event].push(listener); + }; + + this.removeListener = (event, listener) => { + this._listeners[event] = this._listeners[event] || []; + const newListeners = []; + + let found = false; + for (const savedListener of this._listeners[event]) { + if (savedListener === listener) { + // found our listener + found = true; + // we just skip it + } else { + // other listeners should go back to original array + newListeners.push(savedListener); + } + } + + if (found) { + this._listeners[event] = newListeners; + } else { + // something went wrong, lets just cleanup all listeners + this._listeners[event] = []; + } + }; + + this.end = () => { + this._socket.end(); + }; + + this.destroy = () => { + this._socket.destroy(); + }; + + this.write = data => { + this._socket.write(data); + }; +} + +module.exports.Socket = Socket; diff --git a/blue_modules/tls.js b/blue_modules/tls.js new file mode 100644 index 000000000..76d1fb045 --- /dev/null +++ b/blue_modules/tls.js @@ -0,0 +1,33 @@ +/** + * @fileOverview adapter for ReactNative TCP module + * This module mimics the nodejs tls api and is intended to work in RN environment. + * @see https://github.com/Rapsssito/react-native-tcp-socket + */ + +import TcpSocket from 'react-native-tcp-socket'; + +/** + * Constructor function. Mimicking nodejs/tls api + * + * @constructor + */ +function connect(config, callback) { + const client = TcpSocket.createConnection( + { + port: config.port, + host: config.host, + tls: true, + tlsCheckValidity: config.rejectUnauthorized, + }, + callback, + ); + + // functions not supported by RN module, yet: + client.setEncoding = () => {}; + client.setKeepAlive = () => {}; + client.setNoDelay = () => {}; + + return client; +} + +module.exports.connect = connect; diff --git a/ios/BlueWallet/Info.plist b/ios/BlueWallet/Info.plist index d2190f073..be5fbb027 100644 --- a/ios/BlueWallet/Info.plist +++ b/ios/BlueWallet/Info.plist @@ -48,7 +48,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 5.4.1 + 5.4.2 CFBundleSignature ???? CFBundleURLTypes diff --git a/ios/BlueWalletWatch Extension/Info.plist b/ios/BlueWalletWatch Extension/Info.plist index 4f743db37..e12d24b38 100644 --- a/ios/BlueWalletWatch Extension/Info.plist +++ b/ios/BlueWalletWatch Extension/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 5.4.1 + 5.4.2 CFBundleVersion 239 CLKComplicationPrincipalClass diff --git a/ios/BlueWalletWatch/Info.plist b/ios/BlueWalletWatch/Info.plist index 79380cdce..a9db3e1fe 100644 --- a/ios/BlueWalletWatch/Info.plist +++ b/ios/BlueWalletWatch/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 5.4.1 + 5.4.2 CFBundleVersion 239 UISupportedInterfaceOrientations diff --git a/ios/TodayExtension/Info.plist b/ios/TodayExtension/Info.plist index cc02ba7a6..ade16b2ad 100644 --- a/ios/TodayExtension/Info.plist +++ b/ios/TodayExtension/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 5.4.1 + 5.4.2 CFBundleVersion 1 NSExtension diff --git a/package-lock.json b/package-lock.json index 3c69eab39..8ae75135b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bluewallet", - "version": "5.4.1", + "version": "5.4.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -5435,8 +5435,8 @@ "integrity": "sha512-2fvco0F2bBIgqzO8GRP0Jt/91pdrf9KfZ5FsmkYkjERmIJG585cFeFZV4+CO6oTmU3HmCTgfcZuEa7kW8VUh3A==" }, "electrum-client": { - "version": "git+https://github.com/BlueWallet/rn-electrum-client.git#2a5bb11dd9a8d89f328049d9ed59bce49d88a15d", - "from": "git+https://github.com/BlueWallet/rn-electrum-client.git#2a5bb11dd9a8d89f328049d9ed59bce49d88a15d" + "version": "git+https://github.com/BlueWallet/rn-electrum-client.git#cc018effafd2256272f348953500c4d27cef0d2f", + "from": "git+https://github.com/BlueWallet/rn-electrum-client.git#cc018effafd2256272f348953500c4d27cef0d2f" }, "electrum-mnemonic": { "version": "2.0.0", @@ -7900,11 +7900,6 @@ "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==" }, - "ip-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-3.0.0.tgz", - "integrity": "sha512-T8wDtjy+Qf2TAPDQmBp0eGKJ8GavlWlUnamr3wRn6vvdZlKVuJXXMlSncYFRYgVHOM3If5NR1H4+OvVQU9Idvg==" - }, "is": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/is/-/is-0.2.7.tgz", @@ -12087,89 +12082,12 @@ "css-tree": "^1.0.0-alpha.37" } }, - "react-native-tcp": { - "version": "git+https://github.com/BlueWallet/react-native-tcp.git#113433d505063d58a17317e925f03f65e7fc5c3d", - "from": "git+https://github.com/BlueWallet/react-native-tcp.git", + "react-native-tcp-socket": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/react-native-tcp-socket/-/react-native-tcp-socket-3.6.0.tgz", + "integrity": "sha512-lGnlklcHNCQSgdVhrF4fwslc6Xjk3nXLVqjqvJY1pSEJ9H8S4clZR4uwohfbM16VrHnUhBh4o/1wGRO/xrp7nQ==", "requires": { - "base64-js": "1.3.0", - "buffer": "5.2.1", - "events": "3.0.0", - "ip-regex": "3.0.0", - "process": "0.11.10", - "stream-browserify": "2.0.1", - "util": "0.11.1" - }, - "dependencies": { - "base64-js": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", - "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" - }, - "buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz", - "integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - }, - "events": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.0.0.tgz", - "integrity": "sha512-Dc381HFWJzEOhQ+d8pkNon++bk9h6cdAoAj4iE6Q4y6xgTzySWXlKn05/TVNpjnfRqi/X0EpJEJohPjNI3zpVA==" - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "stream-browserify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", - "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", - "requires": { - "inherits": "~2.0.1", - "readable-stream": "^2.0.2" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "util": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", - "integrity": "sha512-HShAsny+zS2TZfaXxD9tYj4HQGlBezXZMZuM/S5PKLLoZkShZiGk9o5CzukI1LVHZvjdvZ2Sj1aW/Ndn2NB/HQ==", - "requires": { - "inherits": "2.0.3" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - } - } - } + "buffer": "^5.4.3" } }, "react-native-tooltip": { diff --git a/package.json b/package.json index 6244f4f2d..207ced35f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bluewallet", - "version": "5.4.1", + "version": "5.4.2", "license": "MIT", "devDependencies": { "@babel/core": "^7.9.6", @@ -83,7 +83,7 @@ "dayjs": "1.8.27", "detox": "16.7.1", "ecurve": "1.0.6", - "electrum-client": "git+https://github.com/BlueWallet/rn-electrum-client.git#2a5bb11dd9a8d89f328049d9ed59bce49d88a15d", + "electrum-client": "git+https://github.com/BlueWallet/rn-electrum-client.git#cc018effafd2256272f348953500c4d27cef0d2f", "electrum-mnemonic": "2.0.0", "eslint-config-prettier": "6.11.0", "eslint-config-standard": "14.1.1", @@ -132,7 +132,7 @@ "react-native-snap-carousel": "3.9.1", "react-native-sortable-list": "0.0.24", "react-native-svg": "9.13.6", - "react-native-tcp": "git+https://github.com/BlueWallet/react-native-tcp.git", + "react-native-tcp-socket": "3.6.0", "react-native-tooltip": "git+https://github.com/marcosrdz/react-native-tooltip.git", "react-native-vector-icons": "6.6.0", "react-native-watch-connectivity": "0.4.2", diff --git a/screen/settings/electrumSettings.js b/screen/settings/electrumSettings.js index 80598d6e4..fd58332c6 100644 --- a/screen/settings/electrumSettings.js +++ b/screen/settings/electrumSettings.js @@ -109,7 +109,7 @@ export default class ElectrumSettings extends Component { this.setState({ config: await BlueElectrum.getConfig(), }); - }, 1000); + }, 500); this.setState({ config: await BlueElectrum.getConfig(), @@ -145,7 +145,9 @@ export default class ElectrumSettings extends Component { await AsyncStorage.setItem(AppStorage.ELECTRUM_SSL_PORT, sslPort); alert('Your changes have been saved successfully. Restart may be required for changes to take effect.'); } - } catch (_) {} + } catch (error) { + alert(error); + } this.setState({ isLoading: false }); }); }; diff --git a/screen/wallets/list.js b/screen/wallets/list.js index 3d0e9abaf..6c2a11a2c 100644 --- a/screen/wallets/list.js +++ b/screen/wallets/list.js @@ -653,6 +653,7 @@ export default class WalletsList extends Component { renderItem={this.renderSectionItem} keyExtractor={this.sectionListKeyExtractor} renderSectionHeader={this.renderSectionHeader} + initialNumToRender={20} contentInset={styles.scrollContent} renderSectionFooter={this.renderSectionFooter} sections={[ diff --git a/shim.js b/shim.js index 04c2e6199..5ee63e697 100644 --- a/shim.js +++ b/shim.js @@ -15,8 +15,13 @@ if (typeof process === 'undefined') { process.browser = false; -global.net = require('react-native-tcp'); -global.tls = require('react-native-tcp/tls'); +// global.net = require('react-native-tcp'); +// global.tls = require('react-native-tcp/tls'); +// +// since new TCP/TLS module for React Native has different api from what is expected from nodejs/net & nodejs/tls +// (or from old module) we wrap this module in adapter: +global.net = require('./blue_modules/net'); +global.tls = require('./blue_modules/tls'); // global.location = global.location || { port: 80 } const isDev = typeof __DEV__ === 'boolean' && __DEV__;