From d69d388aca40f99fec9ddbaf6e22e210fb3bd434 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 3 Mar 2019 17:46:13 -0500 Subject: [PATCH 01/10] Bug fix: lndconnect macaroon is in Base64URL format I was assuming it was in ASCII --- package-lock.json | 13 +++++++++- package.json | 4 ++- utils/MacaroonUtils.ts | 38 +++++++++++++++++++++++------ views/LNDConnectConfigQRScanner.tsx | 3 ++- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index a11c97daa..d4d76295d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zeus", - "version": "0.0.1", + "version": "0.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -813,6 +813,12 @@ "react-native-screens": "^1.0.0 || ^1.0.0-alpha" } }, + "@types/base-64": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@types/base-64/-/base-64-0.1.3.tgz", + "integrity": "sha512-DJpw7RKNMXygZ0j2xe6ROBqiJUy7JWEItkzOPBzrT35HUWS7VLYyW9XJX8yCCvE2xg8QD7wesvVyXFg8AVHTMA==", + "dev": true + }, "@types/jest": { "version": "23.3.13", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.13.tgz", @@ -1360,6 +1366,11 @@ } } }, + "base-64": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz", + "integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs=" + }, "base64-js": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", diff --git a/package.json b/package.json index 43836be0d..8def93480 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "axios": "0.18.0", + "base-64": "0.1.0", "identicon.js": "2.3.3", "lodash": "4.17.11", "mobx": "4.9.1", @@ -28,6 +29,7 @@ }, "devDependencies": { "@babel/plugin-proposal-decorators": "7.3.0", + "@types/base-64": "0.1.3", "@types/jest": "23.3.13", "@types/lodash": "4.14.120", "@types/react": "16.7.22", @@ -42,7 +44,7 @@ "jest": "24.0.0", "metro-react-native-babel-preset": "0.51.1", "react-test-renderer": "16.6.3", - "ts-jest": "^23.10.5", + "ts-jest": "23.10.5", "typescript": "3.2.4" }, "jest": { diff --git a/utils/MacaroonUtils.ts b/utils/MacaroonUtils.ts index dd760df70..73770b22a 100644 --- a/utils/MacaroonUtils.ts +++ b/utils/MacaroonUtils.ts @@ -1,12 +1,34 @@ +import { decode as atob } from 'base-64'; + class MacaroonUtils { - asciiToHex = (input: string) => { - const arr1: Array = []; - for (let n = 0, l = input.length; n < l; n++) { - const hex: string = Number(input.charCodeAt(n)).toString(16); - arr1.push(hex); - } - return arr1.join(''); - }; + base64UrlToHex = (input: string) => { + const raw = atob(this.base64UrlToBase64(input)); + let HEX = ''; + + for (let i = 0; i < raw.length; i++) { + const hexChar = raw.charCodeAt(i).toString(16); + HEX += (hexChar.length === 2 ? hexChar : '0' + hexChar); + } + return HEX.toUpperCase(); + } + + base64UrlToBase64 = (input: string) => { + // Replace non-url compatible chars with base64 standard chars + input = input + .replace(/-/g, '+') + .replace(/_/g, '/'); + + // Pad out with standard base64 required padding characters + var pad = input.length % 4; + if(pad) { + if(pad === 1) { + throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding'); + } + input += new Array(5-pad).join('='); + } + + return input; + } }; const macaroonUtils = new MacaroonUtils(); diff --git a/views/LNDConnectConfigQRScanner.tsx b/views/LNDConnectConfigQRScanner.tsx index 507e4b8bb..382bb488c 100644 --- a/views/LNDConnectConfigQRScanner.tsx +++ b/views/LNDConnectConfigQRScanner.tsx @@ -14,7 +14,8 @@ export default class LNDConnectConfigQRScanner extends React.Component Date: Sun, 3 Mar 2019 17:47:40 -0500 Subject: [PATCH 02/10] linting --- utils/MacaroonUtils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/MacaroonUtils.ts b/utils/MacaroonUtils.ts index 73770b22a..8076feae6 100644 --- a/utils/MacaroonUtils.ts +++ b/utils/MacaroonUtils.ts @@ -19,12 +19,12 @@ class MacaroonUtils { .replace(/_/g, '/'); // Pad out with standard base64 required padding characters - var pad = input.length % 4; - if(pad) { - if(pad === 1) { - throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding'); - } - input += new Array(5-pad).join('='); + const pad = input.length % 4; + if (pad) { + if (pad === 1) { + throw new Error('InvalidLengthError: Input base64url string is the wrong length to determine padding'); + } + input += new Array(5-pad).join('='); } return input; From 05a6e8906262af1870ce86d61085051484def66a Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 4 Mar 2019 20:01:32 -0500 Subject: [PATCH 03/10] Feature: Split up sat denominated values with commas Plus fix a bug that would display number sat values as sat, instead of sats --- stores/UnitsStore.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stores/UnitsStore.ts b/stores/UnitsStore.ts index e21c178f9..ba4172be7 100644 --- a/stores/UnitsStore.ts +++ b/stores/UnitsStore.ts @@ -18,6 +18,8 @@ export default class UnitsStore { this.units = this.units == 'sats' ? 'btc' : 'sats'; } + numberWithCommas = (x: string | number) => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); + @action public getAmount = (value: string | number) => { if (this.units === 'btc') { @@ -31,6 +33,7 @@ export default class UnitsStore { return `₿ ${Number(value || 0) / satoshisPerBTC}`; } - return `${value || 0} ${Number(value) > 1 ? 'sats' : 'sat'}`; + const sats = `${value || 0} ${(Number(value) === 1 || Number(value) === -1) ? 'sat' : 'sats'}`; + return this.numberWithCommas(sats); } } \ No newline at end of file From 9bc9c7b75ecb0cfaedf398f315d762f9986f74f3 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 4 Mar 2019 20:04:30 -0500 Subject: [PATCH 04/10] Design/Bug Fix: Remove padding between button group and lists on the main Wallet view Hopefully this fixes some related scrolling issues where some users are unable to press items at the end of lists --- views/Wallet/Channels.tsx | 49 +++++++++++++++++----------------- views/Wallet/Invoices.tsx | 50 +++++++++++++++++------------------ views/Wallet/Payments.tsx | 46 +++++++++++++++----------------- views/Wallet/Transactions.tsx | 46 +++++++++++++++----------------- 4 files changed, 92 insertions(+), 99 deletions(-) diff --git a/views/Wallet/Channels.tsx b/views/Wallet/Channels.tsx index 703722f99..f9a108cca 100644 --- a/views/Wallet/Channels.tsx +++ b/views/Wallet/Channels.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { FlatList, StyleSheet, View } from 'react-native'; -import { Button, List, ListItem } from 'react-native-elements'; +import { Button, ListItem } from 'react-native-elements'; import Channel from './../../models/Channel'; import Identicon from 'identicon.js'; import { inject, observer } from 'mobx-react'; @@ -44,29 +44,27 @@ export default class Channels extends React.Component { borderRadius={30} /> } - {(!!channels && channels.length > 0) || loading ? - { - const data = new Identicon(hash.sha1(item.remote_pubkey), 420).toString(); - return ( - navigation.navigate('Channel', { channel: item })} - /> - ); - }} - keyExtractor={item => item.chan_id} - ItemSeparatorComponent={this.renderSeparator} - onEndReachedThreshold={50} - refreshing={loading} - onRefresh={() => refresh()} - /> - :