Skip to content

Commit

Permalink
fix _fetchBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrouid committed Sep 19, 2018
1 parent abc1d71 commit 17bee15
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 27 deletions.
6 changes: 3 additions & 3 deletions packages/walletconnect-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/walletconnect-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"webpack-cli": "^3.1.0"
},
"dependencies": {
"eth-parse-uri": "^0.6.6"
"eth-parse-uri": "^0.6.7"
}
}
4 changes: 2 additions & 2 deletions packages/walletconnect-core/src/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class Connector {
let _config = {
method: 'GET',
headers: {
Accept: 'application/json',
// Accept: 'application/json',
'Content-Type': 'application/json'
}
}
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions packages/walletconnect-core/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand Down
41 changes: 38 additions & 3 deletions packages/walletconnect-react-native/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/walletconnect-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
45 changes: 42 additions & 3 deletions packages/walletconnect-react-native/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { expect } from 'chai'

import { Connector } from 'js-walletconnect-core'
import RNWalletConnect from '../src'

function testEncoding(testString, encoding) {
Expand All @@ -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

Expand Down
11 changes: 6 additions & 5 deletions packages/walletconnect-react-native/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion packages/walletconnect/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
11 changes: 6 additions & 5 deletions packages/walletconnect/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down

0 comments on commit 17bee15

Please sign in to comment.