Skip to content

Commit

Permalink
refactor(wallet-rpc)!: inline resolveOnAccount helper
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 25, 2022
1 parent 1775e91 commit 1277b5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 1 addition & 10 deletions src/utils/aepp-wallet-communication/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Browser helper functions
*/
import { isAccountBase } from '../../account/base'
import { TypeError, NoBrowserFoundError } from '../errors'
import { NoBrowserFoundError } from '../errors'

export const getBrowserAPI = (force = false) => {
const { chrome, browser } = window
Expand Down Expand Up @@ -61,11 +60,3 @@ export const sendResponseMessage = (client) => (id, method, data) =>
export const voidFn = () => undefined

export const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3

export const resolveOnAccount = (addresses, onAccount, opt = {}) => {
if (!addresses.find(a => a === onAccount)) {
if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new TypeError('Provided onAccount should be an AccountBase')
onAccount = opt.onAccount
}
return onAccount
}
11 changes: 10 additions & 1 deletion src/utils/aepp-wallet-communication/rpc/wallet-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ import verifyTransaction from '../../../tx/validator'
import AccountMultiple from '../../../account/multiple'
import TxObject from '../../../tx/tx-object'
import RpcClient from './rpc-client'
import { getBrowserAPI, getHandler, isValidAccounts, message, resolveOnAccount, sendResponseMessage } from '../helpers'
import { getBrowserAPI, getHandler, isValidAccounts, message, sendResponseMessage } from '../helpers'
import { ERRORS, METHODS, RPC_STATUS, VERSION, WALLET_TYPE } from '../schema'
import {
IllegalArgumentError,
TypeError,
UnknownRpcClientError
} from '../../errors'
import { isAccountBase } from '../../../account/base'

const resolveOnAccount = (addresses, onAccount, opt = {}) => {
if (!addresses.find(a => a === onAccount)) {
if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new TypeError('Provided onAccount should be an AccountBase')
onAccount = opt.onAccount
}
return onAccount
}

const NOTIFICATIONS = {
[METHODS.closeConnection]: (instance, { client }) =>
Expand Down

0 comments on commit 1277b5b

Please sign in to comment.