From 68ce215011452e781f6ac218be70a99cba411b21 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 12:36:33 -0400 Subject: [PATCH 01/10] use of ipfsgateway from GABA --- app/components/Views/Browser/index.js | 15 ++++++-- package-lock.json | 52 +++++++++------------------ package.json | 2 +- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/app/components/Views/Browser/index.js b/app/components/Views/Browser/index.js index 7bf5b28850d..c2fe3c7d635 100644 --- a/app/components/Views/Browser/index.js +++ b/app/components/Views/Browser/index.js @@ -261,6 +261,10 @@ export class Browser extends Component { * Protocol string to append to URLs that have none */ defaultProtocol: PropTypes.string, + /** + * A string that of the chosen ipfs gateway + */ + ipfsGateway: PropTypes.string, /** * Object containing the information for the current transaction */ @@ -690,6 +694,7 @@ export class Browser extends Component { const sanitizedURL = hasProtocol ? url : `${this.props.defaultProtocol}${url}`; const urlObj = new URL(sanitizedURL); const { hostname, query, pathname } = urlObj; + const { ipfsGateway } = this.props; let ipfsContent = null; let currentEnsName = null; @@ -702,7 +707,7 @@ export class Browser extends Component { const urlObj = new URL(sanitizedURL); currentEnsName = urlObj.hostname; ipfsHash = ipfsContent - .replace(this.state.ipfsGateway, '') + .replace(ipfsGateway, '') .split('/') .shift(); } @@ -756,6 +761,8 @@ export class Browser extends Component { async handleIpfsContent(fullUrl, { hostname, pathname, query }) { const { provider } = Engine.context.NetworkController; + const { ipfsGateway } = this.props; + let ipfsHash; try { ipfsHash = await resolveEnsToIpfsContentId({ provider, name: hostname }); @@ -766,7 +773,7 @@ export class Browser extends Component { return null; } - const gatewayUrl = `${this.state.ipfsGateway}${ipfsHash}${pathname || '/'}${query || ''}`; + const gatewayUrl = `${ipfsGateway}${ipfsHash}${pathname || '/'}${query || ''}`; try { const response = await fetch(gatewayUrl, { method: 'HEAD' }); @@ -1025,6 +1032,7 @@ export class Browser extends Component { } onPageChange = ({ url }) => { + const { ipfsGateway } = this.props; if ((this.goingBack && url === 'about:blank') || (this.initialUrl === url && url === 'about:blank')) { this.goBackToHomepage(); return; @@ -1044,7 +1052,7 @@ export class Browser extends Component { data.inputValue = url; } else if (url.search(`${AppConstants.IPFS_OVERRIDE_PARAM}=false`) === -1) { data.inputValue = url.replace( - `${this.state.ipfsGateway}${this.state.ipfsHash}/`, + `${ipfsGateway}${this.state.ipfsHash}/`, `https://${this.state.currentEnsName}/` ); } else if (this.isENSUrl(url)) { @@ -1661,6 +1669,7 @@ export class Browser extends Component { const mapStateToProps = state => ({ approvedHosts: state.privacy.approvedHosts, bookmarks: state.bookmarks, + ipfsGateway: state.engine.backgroundState.PreferencesController.ipfsGateway, networkType: state.engine.backgroundState.NetworkController.provider.type, network: state.engine.backgroundState.NetworkController.network, selectedAddress: state.engine.backgroundState.PreferencesController.selectedAddress, diff --git a/package-lock.json b/package-lock.json index f766bd4c46d..cf93cc40ade 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6210,7 +6210,7 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "ethereumjs-util": "^5.1.1" } }, @@ -7456,8 +7456,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -7475,13 +7474,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7494,18 +7491,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -7608,8 +7602,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -7619,7 +7612,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7632,20 +7624,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7662,7 +7651,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7735,8 +7723,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -7746,7 +7733,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7822,8 +7808,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -7853,7 +7838,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7871,7 +7855,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7910,13 +7893,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -7990,9 +7971,8 @@ } }, "gaba": { - "version": "1.0.0-beta.70", - "resolved": "https://registry.npmjs.org/gaba/-/gaba-1.0.0-beta.70.tgz", - "integrity": "sha512-gBEkxnLSixTb17Th5e/avPxIrFe96/wuCWFEthrBSJtDFhVAWwU2V+cfK+PPD4aAh+UjkWpoRCCre9fh6kUntg==", + "version": "file:../gaba/dist/gaba-1.0.0-beta.70.tgz", + "integrity": "sha512-nL8P0DyI14s2HUE1xqYZTKCNY1UfcjQ43RnbqMSy1hpRnLFruc+/vzq0e0QfZox8qPmOAtfuPjpIxiIHom7gSg==", "requires": { "await-semaphore": "^0.1.3", "eth-contract-metadata": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", @@ -18052,7 +18032,7 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-0.20.7.tgz", "integrity": "sha512-VU6/DSUX93d1fCzBz7WP/SGCQizO1rKZi4Px9j/3yRyfssHyFcZamMw2/sj4E8TlfMXONvZLoforR8B4bRoyTQ==", "requires": { - "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git", + "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2-cookies": "^1.1.0", @@ -18096,7 +18076,7 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "ethereumjs-util": "^5.1.1" } }, diff --git a/package.json b/package.json index ce35a4f6ed3..54960caefec 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ethjs-unit": "0.1.6", "events": "3.0.0", "fuse.js": "3.4.4", - "gaba": "1.0.0-beta.70", + "gaba": "file:../gaba/dist/gaba-1.0.0-beta.70.tgz", "https-browserify": "0.0.1", "jsc-android": "236355.1.1", "multihashes": "0.4.14", From 70cf170c2d2df24c9395c150d75c99c0a9d07779 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 13:56:25 -0400 Subject: [PATCH 02/10] handle ipfs gateway selection --- .../Views/AdvancedSettings/index.js | 33 +++++++- app/util/ipfs-gateways.json | 78 +++++++++++++++++++ locales/en.json | 2 + locales/es.json | 2 + 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 app/util/ipfs-gateways.json diff --git a/app/components/Views/AdvancedSettings/index.js b/app/components/Views/AdvancedSettings/index.js index a0d8da79016..c2836879272 100644 --- a/app/components/Views/AdvancedSettings/index.js +++ b/app/components/Views/AdvancedSettings/index.js @@ -29,6 +29,8 @@ import { Buffer } from 'buffer'; import Logger from '../../../util/Logger'; import { isprivateConnection } from '../../../util/networks'; import URL from 'url-parse'; +import ipfsGateways from '../../../util/ipfs-gateways.json'; +import SelectComponent from '../../UI/SelectComponent'; const styles = StyleSheet.create({ wrapper: { @@ -103,6 +105,12 @@ const styles = StyleSheet.create({ textAlign: 'center', marginBottom: 20 }, + picker: { + borderColor: colors.lightGray, + borderRadius: 5, + borderWidth: 2, + marginTop: 16 + }, inner: { paddingBottom: 48 }, @@ -120,6 +128,10 @@ const styles = StyleSheet.create({ */ class AdvancedSettings extends Component { static propTypes = { + /** + * A string that of the chosen ipfs gateway + */ + ipfsGateway: PropTypes.string, /** /* navigation object required to push new views */ @@ -258,8 +270,13 @@ class AdvancedSettings extends Component { } }; + setIpfsGateway = ipfsGateway => { + const { PreferencesController } = Engine.context; + PreferencesController.setIpfsGateway(ipfsGateway); + }; + render = () => { - const { showHexData } = this.props; + const { showHexData, ipfsGateway } = this.props; const { resetModalVisible } = this.state; return ( @@ -330,6 +347,19 @@ class AdvancedSettings extends Component { + + + {strings('app_settings.ipfs_gateway')} + {strings('app_settings.ipfs_gateway_desc')} + + + + {strings('app_settings.show_hex_data')} {strings('app_settings.hex_desc')} @@ -363,6 +393,7 @@ class AdvancedSettings extends Component { } const mapStateToProps = state => ({ + ipfsGateway: state.engine.backgroundState.PreferencesController.ipfsGateway, showHexData: state.settings.showHexData, fullState: state }); diff --git a/app/util/ipfs-gateways.json b/app/util/ipfs-gateways.json new file mode 100644 index 00000000000..c1da07e43ee --- /dev/null +++ b/app/util/ipfs-gateways.json @@ -0,0 +1,78 @@ +[ + { + "value": "https://ipfs.io/ipfs/", + "key": 0, + "label": "https://ipfs.io/ipfs/" + }, + + { + "value": "https://gateway.ipfs.io/ipfs/", + "key": 1, + "label": "https://gateway.ipfs.io/ipfs/" + }, + { + "value": "https://ipfs.infura.io/ipfs/", + "key": 2, + "label": "https://ipfs.infura.io/ipfs/" + }, + { + "value": "https://rx14.co.uk/ipfs/", + "key": 3, + "label": "https://rx14.co.uk/ipfs/" + }, + { + "value": "https://ninetailed.ninja/ipfs/", + "key": 4, + "label": "https://ninetailed.ninja/ipfs/" + }, + { + "value": "https://upload.global/ipfs/", + "key": 5, + "label": "https://upload.global/ipfs/" + }, + { + "value": "https://ipfs.jes.xxx/ipfs/", + "key": 6, + "label": "https://ipfs.jes.xxx/ipfs/" + }, + { + "value": "https://catalunya.network/ipfs/", + "key": 7, + "label": "https://catalunya.network/ipfs/" + }, + { + "value": "https://siderus.io/ipfs/", + "key": 8, + "label": "https://siderus.io/ipfs/" + }, + { "value": "https://ipfs.eternum.io/ipfs/", "key": 9, "label": "https://ipfs.eternum.io/ipfs/" }, + { "value": "https://hardbin.com/ipfs/", "key": 10, "label": "https://hardbin.com/ipfs/" }, + { "value": "https://ipfs.macholibre.org/ipfs/", "key": 11, "label": "https://ipfs.macholibre.org/ipfs/" }, + { "value": "https://ipfs.works/ipfs/", "key": 12, "label": "https://ipfs.works/ipfs/" }, + { "value": "https://ipfs.wa.hle.rs/ipfs/", "key": 13, "label": "https://ipfs.wa.hle.rs/ipfs/" }, + { "value": "https://api.wisdom.sh/ipfs/", "key": 14, "label": "https://api.wisdom.sh/ipfs/" }, + { "value": "https://gateway.blocksec.com/ipfs/", "key": 15, "label": "https://gateway.blocksec.com/ipfs/" }, + { "value": "https://ipfs.renehsz.com/ipfs/", "key": 16, "label": "https://ipfs.renehsz.com/ipfs/" }, + { "value": "https://cloudflare-ipfs.com/ipfs/", "key": 17, "label": "https://cloudflare-ipfs.com/ipfs/" }, + { "value": "https://ipns.co/", "key": 18, "label": "https://ipns.co/" }, + { "value": "https://ipfs.netw0rk.io/ipfs/", "key": 19, "label": "https://ipfs.netw0rk.io/ipfs/" }, + { "value": "https://gateway.swedneck.xyz/ipfs/", "key": 20, "label": "https://gateway.swedneck.xyz/ipfs/" }, + { "value": "https://ipfs.mrh.io/ipfs/", "key": 21, "label": "https://ipfs.mrh.io/ipfs/" }, + { + "value": "https://gateway.originprotocol.com/ipfs/", + "key": 22, + "label": "https://gateway.originprotocol.com/ipfs/" + }, + { "value": "https://ipfs.dapps.earth/ipfs/", "key": 23, "label": "https://ipfs.dapps.earth/ipfs/" }, + { "value": "https://gateway.pinata.cloud/ipfs/", "key": 24, "label": "https://gateway.pinata.cloud/ipfs/" }, + { "value": "https://ipfs.doolta.com/ipfs/", "key": 25, "label": "https://ipfs.doolta.com/ipfs/" }, + { "value": "https://ipfs.sloppyta.co/ipfs/", "key": 26, "label": "https://ipfs.sloppyta.co/ipfs/" }, + { "value": "https://ipfs.busy.org/ipfs/", "key": 27, "label": "https://ipfs.busy.org/ipfs/" }, + { "value": "https://ipfs.greyh.at/ipfs/", "key": 28, "label": "https://ipfs.greyh.at/ipfs/" }, + { "value": "https://gateway.serph.network/ipfs/", "key": 29, "label": "https://gateway.serph.network/ipfs/" }, + { "value": "https://jorropo.ovh/ipfs/", "key": 30, "label": "https://jorropo.ovh/ipfs/" }, + { "value": "https://ipfs.deo.moe/ipfs/", "key": 31, "label": "https://ipfs.deo.moe/ipfs/" }, + { "value": "https://gateway.temporal.cloud/ipfs/", "key": 32, "label": "https://gateway.temporal.cloud/ipfs/" }, + { "value": "https://ipfs.fooock.com/ipfs/", "key": 33, "label": "https://ipfs.fooock.com/ipfs/" }, + { "value": "https://cdn.cwinfo.net/ipfs/", "key": 34, "label": "https://cdn.cwinfo.net/ipfs/" } +] diff --git a/locales/en.json b/locales/en.json index f9822eebc2a..547cc38578f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -182,6 +182,8 @@ "title": "Settings", "current_conversion": "Base Currency", "current_language": "Current Language", + "ipfs_gateway": "IPFS Gateway", + "ipfs_gateway_desc": "Choose your preferred IPFS gateway.", "search_engine": "Search Engine", "new_RPC_URL": "New RPC Network", "state_logs": "State Logs", diff --git a/locales/es.json b/locales/es.json index 9f500cf8721..972e59a20fc 100644 --- a/locales/es.json +++ b/locales/es.json @@ -183,6 +183,8 @@ "current_conversion": "Conversión actual", "current_language": "Lenguaje Actual", "new_RPC_URL": "Nueva URL del RPC", + "ipfs_gateway": "IPFS Gateway", + "ipfs_gateway_desc": "Elige tu IPFS gateway preferida.", "state_logs": "Logs de Estado", "reveal_seed_words": "Revelar Palabras de Semilla", "reset_account": "Reiniciar Cuenta", From 226263b2143bf4bd050214924f6767844ecc6398 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 14:02:52 -0400 Subject: [PATCH 03/10] snapshots --- .../__snapshots__/index.test.js.snap | 232 ++++++++++++++++++ .../Views/AdvancedSettings/index.test.js | 9 +- 2 files changed, 240 insertions(+), 1 deletion(-) diff --git a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap index fa92f98e0ca..7855fde5246 100644 --- a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap @@ -313,6 +313,238 @@ exports[`AdvancedSettings should render correctly 1`] = ` + + + IPFS Gateway + + + Choose your preferred IPFS gateway. + + + + + { it('should render correctly', () => { const initialState = { - settings: { showHexData: true } + settings: { showHexData: true }, + engine: { + backgroundState: { + PreferencesController: { + ipfsGateway: 'https://ipfs.io/ipfs/' + } + } + } }; const wrapper = shallow( From f9ba9eb5260cf36bf4be69edf6a68c4d95b3e3af Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 14:07:17 -0400 Subject: [PATCH 04/10] snapshots --- app/components/Views/Settings/__snapshots__/index.test.js.snap | 2 +- locales/en.json | 2 +- locales/es.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/Views/Settings/__snapshots__/index.test.js.snap b/app/components/Views/Settings/__snapshots__/index.test.js.snap index 144dda22b51..6967715194e 100644 --- a/app/components/Views/Settings/__snapshots__/index.test.js.snap +++ b/app/components/Views/Settings/__snapshots__/index.test.js.snap @@ -17,7 +17,7 @@ exports[`Settings should render correctly 1`] = ` title="General" /> diff --git a/locales/en.json b/locales/en.json index 547cc38578f..4a9117c94cc 100644 --- a/locales/en.json +++ b/locales/en.json @@ -225,7 +225,7 @@ "general_title": "General", "general_desc": "Currency conversion, primary currency, language", "advanced_title": "Advanced", - "advanced_desc": "Access developer features, reset account, setup testnets, sync with extension, state logs and custom RPC", + "advanced_desc": "Access developer features, reset account, setup testnets, sync with extension, state logs, IPFS gateway and custom RPC", "security_title": "Security & Privacy", "security_desc": "Privacy settings, private key and wallet seed phrase", "info_title": "About MetaMask", diff --git a/locales/es.json b/locales/es.json index 972e59a20fc..589f5e657d3 100644 --- a/locales/es.json +++ b/locales/es.json @@ -224,7 +224,7 @@ "general_title": "General", "general_desc": "Conversion, Moneda principal, lenguaje", "advanced_title": "Avanzado", - "advanced_desc": "Accede a opciones de desarrolador, reiniciar cuenta, sincronizar con extension, logs de estado, agregar redes de prueba y RPC personalizados", + "advanced_desc": "Accede a opciones de desarrolador, reiniciar cuenta, sincronizar con extension, logs de estado, agregar redes de prueba, IPFS gateway y RPC personalizados", "security_title": "Seguridad y privacidad", "security_desc": "Opciones de privacidad y frase semilla de la billetera", "info_title": "Acerca de MetaMask", From 9a85afc890bad5fcf11888dd8ef8dc744676797d Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 14:25:30 -0400 Subject: [PATCH 05/10] reorder ipfs gateways list --- app/util/ipfs-gateways.json | 55 ++++++------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/app/util/ipfs-gateways.json b/app/util/ipfs-gateways.json index c1da07e43ee..9711e5420b2 100644 --- a/app/util/ipfs-gateways.json +++ b/app/util/ipfs-gateways.json @@ -1,50 +1,13 @@ [ - { - "value": "https://ipfs.io/ipfs/", - "key": 0, - "label": "https://ipfs.io/ipfs/" - }, - - { - "value": "https://gateway.ipfs.io/ipfs/", - "key": 1, - "label": "https://gateway.ipfs.io/ipfs/" - }, - { - "value": "https://ipfs.infura.io/ipfs/", - "key": 2, - "label": "https://ipfs.infura.io/ipfs/" - }, - { - "value": "https://rx14.co.uk/ipfs/", - "key": 3, - "label": "https://rx14.co.uk/ipfs/" - }, - { - "value": "https://ninetailed.ninja/ipfs/", - "key": 4, - "label": "https://ninetailed.ninja/ipfs/" - }, - { - "value": "https://upload.global/ipfs/", - "key": 5, - "label": "https://upload.global/ipfs/" - }, - { - "value": "https://ipfs.jes.xxx/ipfs/", - "key": 6, - "label": "https://ipfs.jes.xxx/ipfs/" - }, - { - "value": "https://catalunya.network/ipfs/", - "key": 7, - "label": "https://catalunya.network/ipfs/" - }, - { - "value": "https://siderus.io/ipfs/", - "key": 8, - "label": "https://siderus.io/ipfs/" - }, + { "value": "https://ipfs.io/ipfs/", "key": 0, "label": "https://ipfs.io/ipfs/" }, + { "value": "https://gateway.ipfs.io/ipfs/", "key": 1, "label": "https://gateway.ipfs.io/ipfs/" }, + { "value": "https://ipfs.infura.io/ipfs/", "key": 2, "label": "https://ipfs.infura.io/ipfs/" }, + { "value": "https://rx14.co.uk/ipfs/", "key": 3, "label": "https://rx14.co.uk/ipfs/" }, + { "value": "https://ninetailed.ninja/ipfs/", "key": 4, "label": "https://ninetailed.ninja/ipfs/" }, + { "value": "https://upload.global/ipfs/", "key": 5, "label": "https://upload.global/ipfs/" }, + { "value": "https://ipfs.jes.xxx/ipfs/", "key": 6, "label": "https://ipfs.jes.xxx/ipfs/" }, + { "value": "https://catalunya.network/ipfs/", "key": 7, "label": "https://catalunya.network/ipfs/" }, + { "value": "https://siderus.io/ipfs/", "key": 8, "label": "https://siderus.io/ipfs/" }, { "value": "https://ipfs.eternum.io/ipfs/", "key": 9, "label": "https://ipfs.eternum.io/ipfs/" }, { "value": "https://hardbin.com/ipfs/", "key": 10, "label": "https://hardbin.com/ipfs/" }, { "value": "https://ipfs.macholibre.org/ipfs/", "key": 11, "label": "https://ipfs.macholibre.org/ipfs/" }, From c739d9935c405f4f528d46797c77b0b77b036c8d Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 16:00:40 -0400 Subject: [PATCH 06/10] only show available ipfs gateways --- .../Views/AdvancedSettings/index.js | 34 ++++++++++++++++--- app/util/general.js | 15 ++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/util/general.js diff --git a/app/components/Views/AdvancedSettings/index.js b/app/components/Views/AdvancedSettings/index.js index c2836879272..18dd080ecdc 100644 --- a/app/components/Views/AdvancedSettings/index.js +++ b/app/components/Views/AdvancedSettings/index.js @@ -31,6 +31,10 @@ import { isprivateConnection } from '../../../util/networks'; import URL from 'url-parse'; import ipfsGateways from '../../../util/ipfs-gateways.json'; import SelectComponent from '../../UI/SelectComponent'; +import timeoutFetch from '../../../util/general'; + +const HASH_TO_TEST = 'Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a'; +const HASH_STRING = 'Hello from IPFS Gateway Checker'; const styles = StyleSheet.create({ wrapper: { @@ -157,10 +161,12 @@ class AdvancedSettings extends Component { resetModalVisible: false, rpcUrl: undefined, warningRpcUrl: '', - inputWidth: Platform.OS === 'android' ? '99%' : undefined + inputWidth: Platform.OS === 'android' ? '99%' : undefined, + onlineIpfsGateways: [] }; - componentDidMount = () => { + componentDidMount = async () => { + await this.handleAvailableIpfsGateways(); this.mounted = true; // Workaround https://github.com/facebook/react-native/issues/9958 this.state.inputWidth && @@ -173,6 +179,26 @@ class AdvancedSettings extends Component { this.mounted = false; }; + handleAvailableIpfsGateways = async () => { + const ipfsGatewaysPromises = ipfsGateways.map(async ipfsGateway => { + const testUrl = ipfsGateway.value + HASH_TO_TEST + '#x-ipfs-companion-no-redirect'; + try { + const res = await timeoutFetch(testUrl); + const text = await res.text(); + const available = text.trim() === HASH_STRING.trim(); + ipfsGateway.available = available; + return ipfsGateway; + } catch (e) { + ipfsGateway.available = false; + return ipfsGateway; + } + }); + const ipfsGatewaysAvailability = await Promise.all(ipfsGatewaysPromises); + const onlineIpfsGateways = ipfsGatewaysAvailability.filter(ipfsGateway => ipfsGateway.available); + const sortedOnlineIpfsGateways = onlineIpfsGateways.sort((a, b) => a.key < b.key); + this.setState({ onlineIpfsGateways: sortedOnlineIpfsGateways }); + }; + displayResetAccountModal = () => { this.setState({ resetModalVisible: true }); }; @@ -277,7 +303,7 @@ class AdvancedSettings extends Component { render = () => { const { showHexData, ipfsGateway } = this.props; - const { resetModalVisible } = this.state; + const { resetModalVisible, onlineIpfsGateways } = this.state; return ( @@ -356,7 +382,7 @@ class AdvancedSettings extends Component { selectedValue={ipfsGateway} onValueChange={this.setIpfsGateway} label={strings('app_settings.ipfs_gateway')} - options={ipfsGateways} + options={onlineIpfsGateways} /> diff --git a/app/util/general.js b/app/util/general.js new file mode 100644 index 00000000000..76b8e636450 --- /dev/null +++ b/app/util/general.js @@ -0,0 +1,15 @@ +/** + * Fetch that fails after timeout + * + * @param url - Url to fetch + * @param options - Options to send with the request + * @param timeout - Timeout to fail request + * + * @returns - Promise resolving the request + */ +export default function timeoutFetch(url, options, timeout = 500) { + return Promise.race([ + fetch(url, options), + new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)) + ]); +} From 985b0ab3fc5d5c3debda38deb7db156ae908ff18 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Tue, 9 Apr 2019 16:01:50 -0400 Subject: [PATCH 07/10] snapshots --- .../__snapshots__/index.test.js.snap | 180 +----------------- 1 file changed, 1 insertion(+), 179 deletions(-) diff --git a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap index 7855fde5246..842d076f3c1 100644 --- a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap @@ -362,185 +362,7 @@ exports[`AdvancedSettings should render correctly 1`] = ` From 9b46202a91aac5e01855aae3a204a1027872656c Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Wed, 10 Apr 2019 14:39:43 -0400 Subject: [PATCH 08/10] bump gaba --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf93cc40ade..c3e3a3f3d56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7971,8 +7971,9 @@ } }, "gaba": { - "version": "file:../gaba/dist/gaba-1.0.0-beta.70.tgz", - "integrity": "sha512-nL8P0DyI14s2HUE1xqYZTKCNY1UfcjQ43RnbqMSy1hpRnLFruc+/vzq0e0QfZox8qPmOAtfuPjpIxiIHom7gSg==", + "version": "1.0.0-beta.72", + "resolved": "https://registry.npmjs.org/gaba/-/gaba-1.0.0-beta.72.tgz", + "integrity": "sha512-InoC/pTUlopKOikTfQgpdQu2SlI8dTZvn0xeVGFb10I56YggDUjF1YQoVzwr0kYtGaQGIWRha4tLCw59zZjUhw==", "requires": { "await-semaphore": "^0.1.3", "eth-contract-metadata": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", @@ -18032,7 +18033,6 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-0.20.7.tgz", "integrity": "sha512-VU6/DSUX93d1fCzBz7WP/SGCQizO1rKZi4Px9j/3yRyfssHyFcZamMw2/sj4E8TlfMXONvZLoforR8B4bRoyTQ==", "requires": { - "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2-cookies": "^1.1.0", @@ -18041,7 +18041,7 @@ "dependencies": { "bignumber.js": { "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", - "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git" + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934" } } }, diff --git a/package.json b/package.json index 54960caefec..4ee546eb24c 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ethjs-unit": "0.1.6", "events": "3.0.0", "fuse.js": "3.4.4", - "gaba": "file:../gaba/dist/gaba-1.0.0-beta.70.tgz", + "gaba": "1.0.0-beta.72", "https-browserify": "0.0.1", "jsc-android": "236355.1.1", "multihashes": "0.4.14", From 52ff8b2e4c208336c678d3561a4d76123b6398e5 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Wed, 10 Apr 2019 15:47:50 -0400 Subject: [PATCH 09/10] handle current gateway down --- app/components/UI/SelectComponent/index.js | 10 +++++++++- app/components/Views/AdvancedSettings/index.js | 1 + locales/en.json | 1 + locales/es.json | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/components/UI/SelectComponent/index.js b/app/components/UI/SelectComponent/index.js index 1c8912f28a5..76aef3e384d 100644 --- a/app/components/UI/SelectComponent/index.js +++ b/app/components/UI/SelectComponent/index.js @@ -82,6 +82,10 @@ const styles = StyleSheet.create({ export default class SelectComponent extends Component { static propTypes = { + /** + * Default value to show + */ + defaultValue: PropTypes.string, /** * Label for the field */ @@ -137,10 +141,14 @@ export default class SelectComponent extends Component { }; getSelectedValue = () => { - const el = this.props.options && this.props.options.filter(o => o.value === this.props.selectedValue); + const { options, selectedValue, defaultValue } = this.props; + const el = options && options.filter(o => o.value === selectedValue); if (el.length && el[0].label) { return el[0].label; } + if (defaultValue) { + return defaultValue; + } return ''; }; diff --git a/app/components/Views/AdvancedSettings/index.js b/app/components/Views/AdvancedSettings/index.js index 18dd080ecdc..1df68f380d4 100644 --- a/app/components/Views/AdvancedSettings/index.js +++ b/app/components/Views/AdvancedSettings/index.js @@ -380,6 +380,7 @@ class AdvancedSettings extends Component { Date: Wed, 10 Apr 2019 15:49:31 -0400 Subject: [PATCH 10/10] snapshots --- .../Views/AdvancedSettings/__snapshots__/index.test.js.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap index 842d076f3c1..dea8ed649d7 100644 --- a/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/AdvancedSettings/__snapshots__/index.test.js.snap @@ -360,6 +360,7 @@ exports[`AdvancedSettings should render correctly 1`] = ` } >