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: loader can display on top of login screen #11325

Merged
merged 22 commits into from
Oct 3, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ const SDKSessionModal = ({ route }: SDKSEssionMoodalProps) => {
[accounts, permittedAccountsAddresses],
);

DevLogger.log(`permittedAccountsAddresses`, permittedAccountsAddresses);
DevLogger.log(
`permittedAccounts state`,
JSON.stringify(permittedAccountsList, null, 2),
);

useEffect(() => {
if (channelId) {
const origin = channelId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export const SDKSessionItem = ({
string[]
>([]);

DevLogger.log(
`Rendering SDKSessionItem connected=${connection.connected} ${connection.id}`,
);
useEffect(() => {
let _sessionName = connection.id;

Expand Down
24 changes: 15 additions & 9 deletions app/core/BackgroundBridge/BackgroundBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class BackgroundBridge extends EventEmitter {
try {
let approvedAccounts = [];
DevLogger.log(
`notifySelectedAddressChanged: ${selectedAddress} wc=${this.isWalletConnect} url=${this.url}`,
`notifySelectedAddressChanged: ${selectedAddress} channelId=${this.channelId} wc=${this.isWalletConnect} url=${this.url}`,
);
if (this.isWalletConnect) {
approvedAccounts = await getPermittedAccounts(this.url);
Expand All @@ -294,15 +294,21 @@ export class BackgroundBridge extends EventEmitter {
(addr) => addr.toLowerCase() !== selectedAddress.toLowerCase(),
),
];

DevLogger.log(
`notifySelectedAddressChanged url: ${this.url} hostname: ${this.hostname}: ${selectedAddress}`,
approvedAccounts,
);
this.sendNotification({
method: NOTIFICATION_NAMES.accountsChanged,
params: approvedAccounts,
});
} else {
DevLogger.log(
`notifySelectedAddressChanged: selectedAddress ${selectedAddress} not found in approvedAccounts`,
approvedAccounts,
);
}
DevLogger.log(
`notifySelectedAddressChanged url: ${this.url} hostname: ${this.hostname}: ${selectedAddress}`,
approvedAccounts,
);
this.sendNotification({
method: NOTIFICATION_NAMES.accountsChanged,
params: approvedAccounts,
});
} catch (err) {
console.error(`notifySelectedAddressChanged: ${err}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import DeeplinkManager from '../DeeplinkManager';
import extractURLParams from './extractURLParams';
import handleMetaMaskDeeplink from './handleMetaMaskDeeplink';
import handleDeeplink from '../../SDKConnect/handlers/handleDeeplink';
import Device from '../../../util/device';
import { Platform } from 'react-native';
import Routes from '../../../constants/navigation/Routes';

jest.mock('../../../core/AppConstants');
jest.mock('../../../core/SDKConnect/handlers/handleDeeplink');
Expand All @@ -30,6 +33,7 @@ describe('handleMetaMaskProtocol', () => {
const mockWC2ManagerConnect = jest.fn();
const mockGetApprovedHosts = jest.fn();
const mockBindAndroidSDK = jest.fn();
const mockNavigate = jest.fn();

const mockHandleDeeplink = handleDeeplink as jest.Mock;
const mockSDKConnectGetInstance = SDKConnect.getInstance as jest.Mock;
Expand All @@ -44,6 +48,7 @@ describe('handleMetaMaskProtocol', () => {

const handled = jest.fn();


let url = '';

let params = {
Expand All @@ -70,6 +75,11 @@ describe('handleMetaMaskProtocol', () => {
reconnect: mockReconnect,
getApprovedHosts: mockGetApprovedHosts,
bindAndroidSDK: mockBindAndroidSDK,
state: {
navigation: {
navigate: mockNavigate,
},
}
}));

mockWC2ManagerGetInstance.mockResolvedValue({
Expand Down Expand Up @@ -259,21 +269,73 @@ describe('handleMetaMaskProtocol', () => {
url = `${PREFIXES.METAMASK}${ACTIONS.CONNECT}`;
});

it('should call Minimizer.goBack when params.redirect is truthy', () => {
params.redirect = 'ABC';
it('should call Minimizer.goBack if params.redirect is truthy on android', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(false);

// Set Platform.Version to '16' to ensure it's less than 17
Object.defineProperty(Platform, 'Version', { get: () => '16' });

handleMetaMaskDeeplink({
instance,
handled,
params,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
origin,
});

expect(handled).toHaveBeenCalled();
expect(Minimizer.goBack).toHaveBeenCalled();
});

it('should call Minimizer.goBack if params.redirect is truthy on ios <17', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(true);

// Set Platform.Version to '16' to ensure it's less than 17
Object.defineProperty(Platform, 'Version', { get: () => '16' });

handleMetaMaskDeeplink({
instance,
handled,
params,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});

expect(handled).toHaveBeenCalled();
expect(Minimizer.goBack).toHaveBeenCalled();
});

it('should displays RETURN_TO_DAPP_MODAL if params.redirect is truthy on ios >17', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(true);

// Set Platform.Version to '16' to ensure it's less than 17
Object.defineProperty(Platform, 'Version', { get: () => '17' });

handleMetaMaskDeeplink({
instance,
handled,
params,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});

expect(handled).toHaveBeenCalled();
expect(mockNavigate).toHaveBeenCalledWith(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.RETURN_TO_DAPP_MODAL,
});
expect(Minimizer.goBack).not.toHaveBeenCalled();
});


it('should call handleDeeplink when channel exists and params.redirect is falsy', () => {
origin = AppConstants.DEEPLINKS.ORIGIN_DEEPLINK;
params.channelId = 'ABC';
Expand All @@ -296,13 +358,20 @@ describe('handleMetaMaskProtocol', () => {
context: 'deeplink_scheme',
otherPublicKey: params.pubkey,
protocolVersion: 1,
originatorInfo: undefined,
rpc: undefined,
sdkConnect: {
getConnections: mockGetConnections,
connectToChannel: mockConnectToChannel,
revalidateChannel: mockRevalidateChannel,
reconnect: mockReconnect,
getApprovedHosts: mockGetApprovedHosts,
bindAndroidSDK: mockBindAndroidSDK,
state: {
navigation: {
navigate: mockNavigate,
},
},
},
});
});
Expand Down
15 changes: 12 additions & 3 deletions app/core/DeeplinkManager/ParseManager/handleMetaMaskDeeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import WC2Manager from '../../WalletConnect/WalletConnectV2';
import DeeplinkManager from '../DeeplinkManager';
import extractURLParams from './extractURLParams';
import parseOriginatorInfo from '../parseOriginatorInfo';

import { Platform } from 'react-native';
import Device from '../../../util/device';
import Routes from '../../../constants/navigation/Routes';
import AppConstants from '../../AppConstants';
export function handleMetaMaskDeeplink({
instance,
handled,
Expand Down Expand Up @@ -39,8 +42,14 @@ export function handleMetaMaskDeeplink({
}

if (url.startsWith(`${PREFIXES.METAMASK}${ACTIONS.CONNECT}`)) {
if (params.redirect) {
Minimizer.goBack();
if (params.redirect && origin === AppConstants.DEEPLINKS.ORIGIN_DEEPLINK) {
abretonc7s marked this conversation as resolved.
Show resolved Hide resolved
if (Device.isIos() && parseInt(Platform.Version as string) >= 17) {
SDKConnect.getInstance().state.navigation?.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.RETURN_TO_DAPP_MODAL,
});
} else {
Minimizer.goBack();
}
} else if (params.channelId) {
// differentiate between deeplink callback and socket connection
if (params.comm === 'deeplinking') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Platform } from 'react-native';
import { ACTIONS } from '../../../constants/deeplinks';
import Device from '../../../util/device';
import AppConstants from '../../AppConstants';
import { Minimizer } from '../../NativeModules';
import SDKConnect from '../../SDKConnect/SDKConnect';
Expand All @@ -8,6 +10,7 @@ import WC2Manager from '../../WalletConnect/WalletConnectV2';
import DeeplinkManager from '../DeeplinkManager';
import extractURLParams from './extractURLParams';
import handleUniversalLink from './handleUniversalLink';
import Routes from '../../../constants/navigation/Routes';

jest.mock('../../../core/SDKConnect/handlers/handleDeeplink');
jest.mock('../../../core/AppConstants');
Expand Down Expand Up @@ -105,7 +108,7 @@ describe('handleUniversalLinks', () => {
urlObj,
params,
browserCallBack: mockBrowserCallBack,
origin,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});
Expand All @@ -119,8 +122,13 @@ describe('handleUniversalLinks', () => {
});

describe('ACTIONS.CONNECT', () => {
it('should call Minimizer.goBack if params.redirect is truthy', () => {
params.redirect = 'ABC';
it('should call Minimizer.goBack if params.redirect is truthy on android', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(false);

// Set Platform.Version to '16' to ensure it's less than 17
Object.defineProperty(Platform, 'Version', { get: () => '16' });

urlObj = {
hostname: AppConstants.MM_UNIVERSAL_LINK_HOST,
Expand All @@ -133,7 +141,35 @@ describe('handleUniversalLinks', () => {
urlObj,
params,
browserCallBack: mockBrowserCallBack,
origin,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});

expect(handled).toHaveBeenCalled();
expect(Minimizer.goBack).toHaveBeenCalled();
});

it('should call Minimizer.goBack if params.redirect is truthy on ios <17', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(false);

// Set Platform.Version to '16' to ensure it's less than 17
Object.defineProperty(Platform, 'Version', { get: () => '16' });

urlObj = {
hostname: AppConstants.MM_UNIVERSAL_LINK_HOST,
pathname: `/${ACTIONS.CONNECT}/additional/path`,
} as ReturnType<typeof extractURLParams>['urlObj'];

handleUniversalLink({
instance,
handled,
urlObj,
params,
browserCallBack: mockBrowserCallBack,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});
Expand All @@ -142,6 +178,46 @@ describe('handleUniversalLinks', () => {
expect(Minimizer.goBack).toHaveBeenCalled();
});

it('should displays RETURN_TO_DAPP_MODAL if params.redirect is truthy on ios >17', () => {
params.redirect = 'true';
// Mock Device.isIos() to return true
jest.spyOn(Device, 'isIos').mockReturnValue(true);

// Set Platform.Version to '17' to ensure it's greater than 17
Object.defineProperty(Platform, 'Version', { get: () => '17' });

const mockNavigate = jest.fn();
mockSDKConnectGetInstance.mockImplementation(() => ({
state: {
navigation: {
navigate: mockNavigate,
},
},
}));

urlObj = {
hostname: AppConstants.MM_UNIVERSAL_LINK_HOST,
pathname: `/${ACTIONS.CONNECT}/additional/path`,
} as ReturnType<typeof extractURLParams>['urlObj'];

handleUniversalLink({
instance,
handled,
urlObj,
params,
browserCallBack: mockBrowserCallBack,
origin: AppConstants.DEEPLINKS.ORIGIN_DEEPLINK,
wcURL,
url,
});

expect(handled).toHaveBeenCalled();
expect(mockNavigate).toHaveBeenCalledWith(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.RETURN_TO_DAPP_MODAL,
});
expect(Minimizer.goBack).not.toHaveBeenCalled();
});

it('should NOT call Minimizer.goBack if params.redirect is falsy', () => {
params.redirect = '';

Expand Down
13 changes: 11 additions & 2 deletions app/core/DeeplinkManager/ParseManager/handleUniversalLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import DeeplinkManager from '../DeeplinkManager';
import extractURLParams from './extractURLParams';
import { OriginatorInfo } from '@metamask/sdk-communication-layer';
import parseOriginatorInfo from '../parseOriginatorInfo';
import Device from '../../../util/device';
import { Platform } from 'react-native';
import Routes from '../../../constants/navigation/Routes';

function handleUniversalLink({
instance,
Expand Down Expand Up @@ -53,8 +56,14 @@ function handleUniversalLink({
}

if (action === ACTIONS.CONNECT) {
if (params.redirect) {
Minimizer.goBack();
if (params.redirect && origin === AppConstants.DEEPLINKS.ORIGIN_DEEPLINK) {
if (Device.isIos() && parseInt(Platform.Version as string) >= 17) {
SDKConnect.getInstance().state.navigation?.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.SHEET.RETURN_TO_DAPP_MODAL,
});
} else {
Minimizer.goBack();
}
} else if (params.channelId) {
const protocolVersion = parseInt(params.v ?? '1', 10);

Expand Down
6 changes: 3 additions & 3 deletions app/core/SDKConnect/Connection/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export interface ConnectionProps {
lastAuthorized?: number; // timestamp of last received activity
}

// eslint-disable-next-line
const { version } = require('../../../../package.json');
import packageJSON from '../../../../package.json';
const { version: walletVersion } = packageJSON;

export class Connection extends EventEmitter2 {
channelId;
Expand Down Expand Up @@ -207,7 +207,7 @@ export class Connection extends EventEmitter2 {
transports: ['websocket'],
walletInfo: {
type: 'MetaMask Mobile',
version,
version: walletVersion,
},
ecies: {
debug: true,
Expand Down
Loading
Loading