Skip to content

Commit

Permalink
Fix(AEX-2): Get browser API helper (#853)
Browse files Browse the repository at this point in the history
* feat(Chain): Add more info to transaction verification error message

* docs(Wallet): Fix typo in wallet guide. Replace deprecate node params.

* fix(helpers): Fix getBrowserAPI helper

* test(helpers): Add tests for rpc helper

* fix(rpc): Fix condition
  • Loading branch information
nduchak authored Jan 14, 2020
1 parent cf29054 commit 39b0b94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions es/utils/aepp-wallet-communication/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Browser helper functions
*/
/* eslint-disable no-undef */
export const getBrowserAPI = () => {
if (chrome && chrome.runtime) return chrome
if (browser && browser.runtime) return browser
throw new Error('Browser is not detected')
export const getBrowserAPI = (force = false) => {
if (chrome === Object(chrome) && chrome.runtime) return chrome
if (browser === Object(browser) && browser.runtime) return browser
if (!force) throw new Error('Browser is not detected')
return {}
}

export const isInIframe = () => window !== window.parent
Expand Down
5 changes: 3 additions & 2 deletions es/utils/aepp-wallet-communication/rpc/wallet-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,13 @@ export const WalletRpc = Ae.compose(Accounts, Selector, {
* @return {Object} Object with wallet information(id, name, network, ...)
*/
getWalletInfo () {
const runtime = getBrowserAPI(true).runtime
return {
id: getBrowserAPI().runtime.id || this.id,
id: runtime ? runtime.id : this.id,
name: this.name,
networkId: this.getNetworkId(),
origin: window.location.origin,
type: getBrowserAPI().runtime.id ? WALLET_TYPE.extension : WALLET_TYPE.window
type: runtime && runtime.id ? WALLET_TYPE.extension : WALLET_TYPE.window
}
},
/**
Expand Down
6 changes: 6 additions & 0 deletions test/integration/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ describe('Aepp<->Wallet', function () {
e.message.should.be.equal('Browser is not detected')
}
})
it('getBrowserAPI: not in browser(force error)', () => {
global.chrome = null
global.browser = null
global.window = null
getBrowserAPI(true).should.be.an('object')
})
it('getBrowserAPI: chrome', () => {
global.chrome = { runtime: {}, chrome: true }
getBrowserAPI().chrome.should.be.equal(true)
Expand Down

0 comments on commit 39b0b94

Please sign in to comment.