Skip to content

Commit 22c452c

Browse files
authored
feat(AEX-2): Add debug option for getHandler (#1021)
* feat(AEX-2): Add debug option for `getHandler` * feat(AEX-2): Regenerate locks for examples
1 parent c03b862 commit 22c452c

File tree

7 files changed

+3512
-4215
lines changed

7 files changed

+3512
-4215
lines changed

es/utils/aepp-wallet-communication/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export const receive = (handler) => (msg, origin) => {
6262
handler(msg, origin)
6363
}
6464

65-
export const getHandler = (schema, msg) => {
65+
export const getHandler = (schema, msg, { debug = false } = {}) => {
6666
const handler = schema[msg.method]
6767
if (!handler || typeof handler !== 'function') {
68-
console.log(`Unknown message method ${msg.method}`)
68+
debug && console.log(`Unknown message method ${msg.method}`)
6969
return () => () => true
7070
}
7171
return handler

es/utils/aepp-wallet-communication/rpc/aepp-rpc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ const REQUESTS = {}
6262

6363
const handleMessage = (instance) => async (msg) => {
6464
if (!msg.id) {
65-
return getHandler(NOTIFICATIONS, msg)(instance)(msg)
65+
return getHandler(NOTIFICATIONS, msg, { debug: instance.debug })(instance)(msg)
6666
} else if (Object.prototype.hasOwnProperty.call(instance.rpcClient.callbacks, msg.id)) {
67-
return getHandler(RESPONSES, msg)(instance)(msg)
67+
return getHandler(RESPONSES, msg, { debug: instance.debug })(instance)(msg)
6868
} else {
69-
return getHandler(REQUESTS, msg)(instance)(msg)
69+
return getHandler(REQUESTS, msg, { debug: instance.debug })(instance)(msg)
7070
}
7171
}
7272

@@ -84,10 +84,11 @@ const handleMessage = (instance) => async (msg) => {
8484
* @return {Object}
8585
*/
8686
export const AeppRpc = Ae.compose({
87-
async init ({ name, onAddressChange = voidFn, onDisconnect = voidFn, onNetworkChange = voidFn, connection, forceValidation = false }) {
87+
async init ({ name, onAddressChange = voidFn, onDisconnect = voidFn, onNetworkChange = voidFn, connection, forceValidation = false, debug = false }) {
8888
const eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange']
8989
this.connection = connection
9090
this.name = name
91+
this.debug = debug
9192

9293
if (connection) {
9394
// Init RPCClient

es/utils/aepp-wallet-communication/rpc/wallet-rpc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ const REQUESTS = {
173173
const handleMessage = (instance, id) => async (msg, origin) => {
174174
const client = rpcClients.getClient(id)
175175
if (!msg.id) {
176-
return getHandler(NOTIFICATIONS, msg)(instance, { client })(msg, origin)
176+
return getHandler(NOTIFICATIONS, msg, { debug: instance.debug })(instance, { client })(msg, origin)
177177
}
178178
if (Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
179-
return getHandler(RESPONSES, msg)(instance, { client })(msg, origin)
179+
return getHandler(RESPONSES, msg, { debug: instance.debug })(instance, { client })(msg, origin)
180180
} else {
181181
const { id, method } = msg
182182
const callInstance = (methodName, params, accept, deny) => new Promise(resolve => {
@@ -188,7 +188,7 @@ const handleMessage = (instance, id) => async (msg, origin) => {
188188
origin
189189
)
190190
})
191-
const response = await getHandler(REQUESTS, msg)(callInstance, instance, client, msg.params)
191+
const response = await getHandler(REQUESTS, msg, { debug: instance.debug })(callInstance, instance, client, msg.params)
192192
sendResponseMessage(client)(id, method, response)
193193
}
194194
}
@@ -209,7 +209,8 @@ const handleMessage = (instance, id) => async (msg, origin) => {
209209
* @return {Object}
210210
*/
211211
export const WalletRpc = Ae.compose(Accounts, Selector, {
212-
init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign, forceValidation = false }) {
212+
init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign, forceValidation = false, debug = false }) {
213+
this.debug = debug
213214
const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']
214215
// CallBacks for events
215216
this.onConnection = onConnection

es/utils/aepp-wallet-communication/wallet-detector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function getWallets () {
112112
* @return {WalletDetector}
113113
*/
114114
export const WalletDetector = AsyncInit.compose({
115-
async init ({ connection }) {
115+
async init ({ connection } = {}) {
116116
if (!window) throw new Error('Window object not found, you can run wallet detector only in browser')
117117
this.connection = connection || BrowserWindowMessageConnection({ connectionInfo: { id: 'spy' }})
118118
},

0 commit comments

Comments
 (0)