diff --git a/app/core/BackgroundBridge/BackgroundBridge.js b/app/core/BackgroundBridge/BackgroundBridge.js index 2d06aaa46b8..fad72e2d4f7 100644 --- a/app/core/BackgroundBridge/BackgroundBridge.js +++ b/app/core/BackgroundBridge/BackgroundBridge.js @@ -195,7 +195,12 @@ export class BackgroundBridge extends EventEmitter { notifySelectedAddressChanged(selectedAddress) { if (this.isRemoteConn) { - if (!this.getApprovedHosts?.()?.[this.remoteConnHost]) return; + // Pass the remoteConnHost to getApprovedHosts as AndroidSDK requires it + if ( + !this.getApprovedHosts?.(this.remoteConnHost)?.[this.remoteConnHost] + ) { + return; + } } this.sendNotification({ method: NOTIFICATION_NAMES.accountsChanged, diff --git a/app/core/RPCMethods/RPCMethodMiddleware.ts b/app/core/RPCMethods/RPCMethodMiddleware.ts index a08767c6e5d..6e52dc91d06 100644 --- a/app/core/RPCMethods/RPCMethodMiddleware.ts +++ b/app/core/RPCMethods/RPCMethodMiddleware.ts @@ -244,7 +244,8 @@ export const getRpcMethodMiddleware = ({ const getAccounts = (): string[] => { const selectedAddress = Engine.context.PreferencesController.state.selectedAddress?.toLowerCase(); - const isEnabled = isWalletConnect || getApprovedHosts()[hostname]; + const approvedHosts = getApprovedHosts(hostname) || {}; + const isEnabled = isWalletConnect || approvedHosts[hostname]; return isEnabled && selectedAddress ? [selectedAddress] : []; }; @@ -907,5 +908,4 @@ export const getRpcMethodMiddleware = ({ } await rpcMethods[req.method](); }); - export default getRpcMethodMiddleware; diff --git a/app/core/SDKConnect/AndroidSDK/AndroidService.ts b/app/core/SDKConnect/AndroidSDK/AndroidService.ts index f69d38efd31..a3e4c8ca6a3 100644 --- a/app/core/SDKConnect/AndroidSDK/AndroidService.ts +++ b/app/core/SDKConnect/AndroidSDK/AndroidService.ts @@ -125,11 +125,11 @@ export default class AndroidService extends EventEmitter2 { try { if (!this.connectedClients?.[clientInfo.clientId]) { - await this.requestApproval(clientInfo); this.setupBridge(clientInfo); // Save session to SDKConnect SDKConnect.getInstance().addAndroidConnection({ id: clientInfo.clientId, + lastAuthorized: Date.now(), origin: AppConstants.MM_SDK.ANDROID_SDK, originatorInfo: clientInfo.originatorInfo, otherPublicKey: '', @@ -331,11 +331,13 @@ export default class AndroidService extends EventEmitter2 { const bridge = new BackgroundBridge({ webview: null, - isMMSDK: false, + isMMSDK: true, url: PROTOCOLS.METAMASK + '://' + AppConstants.MM_SDK.SDK_REMOTE_ORIGIN, isRemoteConn: true, sendMessage: this.sendMessage.bind(this), - getApprovedHosts: () => false, + getApprovedHosts: (host: string) => ({ + [host]: true, + }), remoteConnHost: clientInfo.originatorInfo.url ?? clientInfo.originatorInfo.title, getRpcMethodMiddleware: ({ @@ -348,10 +350,12 @@ export default class AndroidService extends EventEmitter2 { hostname: clientInfo.originatorInfo.url ?? clientInfo.originatorInfo.title, getProviderState, - isMMSDK: false, + isMMSDK: true, navigation: null, //props.navigation, - getApprovedHosts: () => ({}), - setApprovedHosts: () => ({}), + getApprovedHosts: (host: string) => ({ + [host]: true, + }), + setApprovedHosts: () => true, approveHost: () => ({}), // Website info url: {