Skip to content

Commit 87b9ef9

Browse files
authored
feat(AEX_2): Allow to connect without node (#991)
* feat(AEX_2): Remove check for available network in Wallet `connect` handler * feat(AEX_2): Fix RPC example apps.
1 parent 4efd341 commit 87b9ef9

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

es/node.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ async function remoteSwag (url, axiosConfig) {
4848
* @rtype () => networkId: String
4949
* @return {String} NetworkId
5050
*/
51-
export function getNetworkId ({ networkId } = {}) {
52-
if (!networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided')
51+
export function getNetworkId ({ networkId, force = false } = {}) {
52+
if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided')
53+
if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null
5354
return networkId || this.networkId || this.selectedNode.networkId
5455
}
5556

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const AeppRpc = Ae.compose({
122122
if (this.rpcClient && this.rpcClient.isConnected()) throw new Error('You are already connected to wallet ' + this.rpcClient)
123123
this.rpcClient = RpcClient({
124124
connection,
125-
networkId: this.getNetworkId(),
125+
networkId: this.getNetworkId({ force: true }),
126126
...connection.connectionInfo,
127127
id: uuid(),
128128
handlers: [handleMessage(this), this.onDisconnect]
@@ -215,7 +215,7 @@ export const AeppRpc = Ae.compose({
215215
METHODS.aepp.connect, {
216216
name: this.name,
217217
version: VERSION,
218-
networkId: this.getNetworkId()
218+
networkId: this.getNetworkId({ force: true })
219219
}
220220
)
221221
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const REQUESTS = {
3333
async [METHODS.aepp.connect] (callInstance, instance, client, { name, networkId, version, icons }) {
3434
// Check if protocol and network is compatible with wallet
3535
if (version !== VERSION) return { error: ERRORS.unsupportedProtocol() }
36-
if (networkId !== instance.getNetworkId()) return { error: ERRORS.unsupportedNetwork() }
36+
// if (networkId !== instance.getNetworkId()) return { error: ERRORS.unsupportedNetwork() }
3737

3838
// Store new AEPP and wait for connection approve
3939
rpcClients.updateClientInfo(client.id, {
@@ -208,7 +208,7 @@ const handleMessage = (instance, id) => async (msg, origin) => {
208208
* @return {Object}
209209
*/
210210
export const WalletRpc = Ae.compose(Accounts, Selector, {
211-
init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign }) {
211+
init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign, forceValidation = false }) {
212212
const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']
213213
// CallBacks for events
214214
this.onConnection = onConnection
@@ -219,7 +219,7 @@ export const WalletRpc = Ae.compose(Accounts, Selector, {
219219
this.onMessageSign = onMessageSign
220220

221221
eventsHandlers.forEach(event => {
222-
if (typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
222+
if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
223223
})
224224
//
225225
this.name = name

examples/browser/vuejs/connect-two-ae/identity/src/components/Home.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@
130130
}[params.onAccount]
131131
accept(null, { onAccount }) // provide this account for signing
132132
},
133-
onMessageSign: genConfirmCallback(() => 'sign message'),
133+
onMessageSign (aepp, { accept, deny, params }, origin) {
134+
// Get account outside of SDK if needed
135+
const onAccount = {
136+
[keypair.publicKey]: MemoryAccount({ keypair }),
137+
[keypair2.publicKey]: MemoryAccount({ keypair: keypair2 }),
138+
}[params.onAccount]
139+
accept({ onAccount }) // provide this account for signing
140+
},
134141
onAskAccounts: genConfirmCallback(() => 'get accounts'),
135142
onDisconnect (message, client) {
136143
this.shareWalletInfo(connection.sendMessage.bind(connection))

0 commit comments

Comments
 (0)