Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use hostname to fetch approvedhosts #7489

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/core/BackgroundBridge/BackgroundBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] : [];
};

Expand Down Expand Up @@ -907,5 +908,4 @@ export const getRpcMethodMiddleware = ({
}
await rpcMethods[req.method]();
});

export default getRpcMethodMiddleware;
16 changes: 10 additions & 6 deletions app/core/SDKConnect/AndroidSDK/AndroidService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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: ({
Expand All @@ -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: {
Expand Down
Loading