diff --git a/packages/walletconnect-core/package-lock.json b/packages/walletconnect-core/package-lock.json index ecc21bdf4..7f0f50518 100644 --- a/packages/walletconnect-core/package-lock.json +++ b/packages/walletconnect-core/package-lock.json @@ -2031,9 +2031,9 @@ "dev": true }, "eth-parse-uri": { - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/eth-parse-uri/-/eth-parse-uri-0.6.6.tgz", - "integrity": "sha512-6Ia/H6cJ/u9intEOmgnbaC2ooAWEqdBQ7U8j1qV665PRF8nhBYoNbdqAZHb0l/Iw2/VWBJsYS4qNzAUze2OAJQ==" + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/eth-parse-uri/-/eth-parse-uri-0.6.7.tgz", + "integrity": "sha512-shYKNcutyYFaJJQLIvPpD58XOTkMoTaN7i39AN4GRNFZIRoRF/TlHUjwbt2NNXPe9wK3K/7IoK2egYkj096kfg==" }, "events": { "version": "1.1.1", diff --git a/packages/walletconnect-core/package.json b/packages/walletconnect-core/package.json index 0c2255fff..7cd9ec7d5 100644 --- a/packages/walletconnect-core/package.json +++ b/packages/walletconnect-core/package.json @@ -45,6 +45,6 @@ "webpack-cli": "^3.1.0" }, "dependencies": { - "eth-parse-uri": "^0.6.6" + "eth-parse-uri": "^0.6.7" } } diff --git a/packages/walletconnect-core/src/connector.js b/packages/walletconnect-core/src/connector.js index 51b2fd050..f609f574e 100644 --- a/packages/walletconnect-core/src/connector.js +++ b/packages/walletconnect-core/src/connector.js @@ -262,7 +262,7 @@ export default class Connector { let _config = { method: 'GET', headers: { - Accept: 'application/json', + // Accept: 'application/json', 'Content-Type': 'application/json' } } @@ -272,7 +272,7 @@ export default class Connector { } if (body) { - config.body = JSON.stringify(body) + _config.body = JSON.stringify(body) } const res = await fetch(requestUrl, _config) diff --git a/packages/walletconnect-core/webpack.config.js b/packages/walletconnect-core/webpack.config.js index 155164865..6f7bf6f8d 100644 --- a/packages/walletconnect-core/webpack.config.js +++ b/packages/walletconnect-core/webpack.config.js @@ -1,16 +1,21 @@ /* eslint-disable */ -var path = require('path') +const path = require('path') +const pkg = require('./package.json') module.exports = { mode: 'production', entry: ['@babel/polyfill', './src/index.js'], output: { path: path.resolve(__dirname, 'dist'), - filename: 'js-walletconnect-core.js', - library: 'js-walletconnect-core', + filename: `${pkg.name}.js`, + library: pkg.name, libraryTarget: 'commonjs2' }, + externals: { + crypto: 'crypto', + Buffer: 'buffer' + }, module: { rules: [ { diff --git a/packages/walletconnect-react-native/package-lock.json b/packages/walletconnect-react-native/package-lock.json index 8e63268c8..f969b8ae4 100644 --- a/packages/walletconnect-react-native/package-lock.json +++ b/packages/walletconnect-react-native/package-lock.json @@ -2548,6 +2548,15 @@ "integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=", "dev": true }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "dev": true, + "requires": { + "iconv-lite": "~0.4.13" + } + }, "end-of-stream": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", @@ -2682,9 +2691,9 @@ "dev": true }, "eth-parse-uri": { - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/eth-parse-uri/-/eth-parse-uri-0.6.6.tgz", - "integrity": "sha512-6Ia/H6cJ/u9intEOmgnbaC2ooAWEqdBQ7U8j1qV665PRF8nhBYoNbdqAZHb0l/Iw2/VWBJsYS4qNzAUze2OAJQ==" + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/eth-parse-uri/-/eth-parse-uri-0.6.7.tgz", + "integrity": "sha512-shYKNcutyYFaJJQLIvPpD58XOTkMoTaN7i39AN4GRNFZIRoRF/TlHUjwbt2NNXPe9wK3K/7IoK2egYkj096kfg==" }, "events": { "version": "1.1.1", @@ -4374,6 +4383,16 @@ "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "dev": true }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "dev": true, + "requires": { + "node-fetch": "^1.0.1", + "whatwg-fetch": ">=0.10.0" + } + }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -6033,6 +6052,16 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dev": true, + "requires": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -8587,6 +8616,12 @@ "iconv-lite": "0.4.23" } }, + "whatwg-fetch": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz", + "integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==", + "dev": true + }, "whatwg-mimetype": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.2.0.tgz", diff --git a/packages/walletconnect-react-native/package.json b/packages/walletconnect-react-native/package.json index 15583f719..628730f53 100644 --- a/packages/walletconnect-react-native/package.json +++ b/packages/walletconnect-react-native/package.json @@ -5,7 +5,7 @@ "scripts": { "clean": "rm -rf dist", "build": "webpack --config webpack.config.js", - "test": "BABEL_ENV=test mocha --require @babel/register --require @babel/polyfill --colors test/**/*.spec.js", + "test": "BABEL_ENV=test mocha --require @babel/register --require @babel/polyfill --require isomorphic-fetch --colors test/**/*.spec.js", "test:watch": "npm run test -- -w" }, "keywords": [ @@ -43,6 +43,7 @@ "babel-jest": "^23.6.0", "babel-loader": "^8.0.2", "chai": "^4.1.2", + "isomorphic-fetch": "^2.2.1", "jest": "^23.6.0", "mocha": "5.2.0", "webpack": "^4.18.0", diff --git a/packages/walletconnect-react-native/test/index.spec.js b/packages/walletconnect-react-native/test/index.spec.js index fa7aa1cd7..936cace4c 100644 --- a/packages/walletconnect-react-native/test/index.spec.js +++ b/packages/walletconnect-react-native/test/index.spec.js @@ -2,6 +2,7 @@ import { expect } from 'chai' +import { Connector } from 'js-walletconnect-core' import RNWalletConnect from '../src' function testEncoding(testString, encoding) { @@ -10,20 +11,58 @@ function testEncoding(testString, encoding) { return result === testString } -const testURI = - 'ethereum:wc-8a5e5bdc-a0e4-4702-ba63-8f1a5655744f@1?name=DappExample&bridge=https://bridge.example.com&symKey=KzpSTk1pezg5eTJRNmhWJmoxdFo6UDk2WlhaOyQ5N0U=' +async function mockCreateSession(connector) { + connector.symKey = await connector.generateKey() + const { sessionId } = await connector._fetchBridge('/session/new', { + method: 'POST' + }) + connector.sessionId = sessionId + const uri = connector._formatWalletConnectURI() + return uri +} + +// const testURI = +// 'ethereum:wc-8a5e5bdc-a0e4-4702-ba63-8f1a5655744f@1?name=DappExample&bridge=https://bridge.example.com&symKey=KzpSTk1pezg5eTJRNmhWJmoxdFo6UDk2WlhaOyQ5N0U=' describe('// ------------- rn-walletconnect-wallet ------------- //', () => { let walletConnector = null + let connector = null + + let config = { + bridgeUrl: 'https://bridge.walletconnect.org', + dappName: 'Example' + } beforeEach(async() => { - walletConnector = new RNWalletConnect(testURI) + connector = new Connector(config) + + const uri = await mockCreateSession(connector) + + walletConnector = new RNWalletConnect(uri) }) it('creates an instance using URI string', () => { expect(walletConnector).to.exist }) + describe('sendSessionStatus', () => { + const sessionStatus = { + fcmToken: + 'cSgGd8BWURk:APA91bGXsLd_ga4wnUqtO5O8CQqe6RRdyb4LuJ1h-TAwVRFha1PDe6LPAr5irb0ZRYtEkGvrJ38LsvG9INiqlx4KBx9ATCHkc2dWwsncN4YkkZnSPwsaJNABVYdFbutyfc8pScl0Qe8-', + pushEndpoint: + 'https://us-central1-walletconnect-app.cloudfunctions.net/push', + data: { + accounts: ['0x89205a3a3b2a69de6dbf7f01ed13b2108b2c43e7'] + } + } + + it('successfully posts session status to bridge', async() => { + const result = await walletConnector.sendSessionStatus(sessionStatus) + + expect(result).to.be.true + }) + }) + describe('symKey', () => { let symKey = null diff --git a/packages/walletconnect-react-native/webpack.config.js b/packages/walletconnect-react-native/webpack.config.js index afd6ae799..b4e7e7d89 100644 --- a/packages/walletconnect-react-native/webpack.config.js +++ b/packages/walletconnect-react-native/webpack.config.js @@ -1,15 +1,16 @@ /* eslint-disable */ -var path = require('path') +const path = require('path') +const pkg = require('./package.json') module.exports = { mode: 'production', - entry: ['@babel/polyfill', './src/index.js'], + entry: ['./src/index.js'], output: { path: path.resolve(__dirname, 'dist'), - filename: 'rn-walletconnect-wallet.js', - library: 'rn-walletconnect-wallet', - libraryTarget: 'umd' + filename: `${pkg.name}.js`, + library: pkg.name, + libraryTarget: 'commonjs2' }, module: { rules: [ diff --git a/packages/walletconnect/src/index.js b/packages/walletconnect/src/index.js index a3d2006b9..bc1514727 100644 --- a/packages/walletconnect/src/index.js +++ b/packages/walletconnect/src/index.js @@ -96,7 +96,7 @@ export default class WalletConnect extends Connector { expires: this.expires } - const uri = this._formatWalletConnectURI(sessionData) + const uri = this._formatWalletConnectURI() return { ...sessionData, uri } } diff --git a/packages/walletconnect/webpack.config.js b/packages/walletconnect/webpack.config.js index 4d39f000f..b4e7e7d89 100644 --- a/packages/walletconnect/webpack.config.js +++ b/packages/walletconnect/webpack.config.js @@ -1,15 +1,16 @@ /* eslint-disable */ -var path = require('path') +const path = require('path') +const pkg = require('./package.json') module.exports = { mode: 'production', - entry: ['@babel/polyfill', './src/index.js'], + entry: ['./src/index.js'], output: { path: path.resolve(__dirname, 'dist'), - filename: 'walletconnect.js', - library: 'walletconnect', - libraryTarget: 'umd' + filename: `${pkg.name}.js`, + library: pkg.name, + libraryTarget: 'commonjs2' }, module: { rules: [