-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/tldr-readme
- Loading branch information
Showing
266 changed files
with
1,598 additions
and
1,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { trackDappVisitedEvent } from './index'; | ||
import { MetaMetricsEvents } from '../core/Analytics'; | ||
import AnalyticsV2 from '../util/analyticsV2'; | ||
|
||
// Mock AnalyticsV2 | ||
jest.mock('../util/analyticsV2', () => ({ | ||
trackEvent: jest.fn(), | ||
})); | ||
|
||
// Mock store.getState | ||
let mockGetState: jest.Mock; | ||
jest.mock('../store', () => { | ||
mockGetState = jest.fn(); | ||
mockGetState.mockImplementation(() => ({ | ||
browser: { | ||
visitedDappsByHostname: {}, | ||
}, | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
identities: { '0x1': true, '0x2': true }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
return { | ||
store: { | ||
getState: mockGetState, | ||
dispatch: jest.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
describe('trackDappVisitedEvent', () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should track with isFirstVisit = true', () => { | ||
mockGetState.mockImplementation(() => ({ | ||
browser: { | ||
visitedDappsByHostname: {}, | ||
}, | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
identities: { '0x1': true, '0x2': true }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
const expectedMetrics = { | ||
is_first_visit: true, | ||
number_of_accounts: 2, | ||
number_of_accounts_connected: 1, | ||
source: 'in-app browser', | ||
}; | ||
|
||
trackDappVisitedEvent({ | ||
hostname: 'uniswap.org', | ||
numberOfConnectedAccounts: 1, | ||
}); | ||
|
||
expect(AnalyticsV2.trackEvent).toBeCalledWith( | ||
MetaMetricsEvents.DAPP_VISITED, | ||
expectedMetrics, | ||
); | ||
}); | ||
|
||
it('should track with isFirstVisit = false', () => { | ||
mockGetState.mockImplementation(() => ({ | ||
browser: { | ||
visitedDappsByHostname: { 'uniswap.org': true }, | ||
}, | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
identities: { '0x1': true, '0x2': true }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
const expectedMetrics = { | ||
is_first_visit: false, | ||
number_of_accounts: 2, | ||
number_of_accounts_connected: 1, | ||
source: 'in-app browser', | ||
}; | ||
|
||
trackDappVisitedEvent({ | ||
hostname: 'uniswap.org', | ||
numberOfConnectedAccounts: 1, | ||
}); | ||
|
||
expect(AnalyticsV2.trackEvent).toBeCalledWith( | ||
MetaMetricsEvents.DAPP_VISITED, | ||
expectedMetrics, | ||
); | ||
}); | ||
|
||
it('should track with the correct number of connected accounts', () => { | ||
mockGetState.mockImplementation(() => ({ | ||
browser: { | ||
visitedDappsByHostname: { 'uniswap.org': true }, | ||
}, | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
identities: { '0x1': true, '0x2': true }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
const expectedMetrics = { | ||
is_first_visit: false, | ||
number_of_accounts: 2, | ||
number_of_accounts_connected: 1, | ||
source: 'in-app browser', | ||
}; | ||
|
||
trackDappVisitedEvent({ | ||
hostname: 'uniswap.org', | ||
numberOfConnectedAccounts: 1, | ||
}); | ||
|
||
expect(AnalyticsV2.trackEvent).toBeCalledWith( | ||
MetaMetricsEvents.DAPP_VISITED, | ||
expectedMetrics, | ||
); | ||
}); | ||
|
||
it('should track with the correct number of wallet accounts', () => { | ||
mockGetState.mockImplementation(() => ({ | ||
browser: { | ||
visitedDappsByHostname: { 'uniswap.org': true }, | ||
}, | ||
engine: { | ||
backgroundState: { | ||
PreferencesController: { | ||
identities: { '0x1': true }, | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
const expectedMetrics = { | ||
is_first_visit: false, | ||
number_of_accounts: 1, | ||
number_of_accounts_connected: 1, | ||
source: 'in-app browser', | ||
}; | ||
|
||
trackDappVisitedEvent({ | ||
hostname: 'uniswap.org', | ||
numberOfConnectedAccounts: 1, | ||
}); | ||
|
||
expect(AnalyticsV2.trackEvent).toBeCalledWith( | ||
MetaMetricsEvents.DAPP_VISITED, | ||
expectedMetrics, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { selectIdentities } from '../selectors/preferencesController'; | ||
import { store } from '../store'; | ||
import { MetaMetricsEvents } from '../core/Analytics'; | ||
import AnalyticsV2 from '../util/analyticsV2'; | ||
import { addToVisitedDapp } from '../actions/browser'; | ||
|
||
/** | ||
* Tracks Dapp visited event | ||
* | ||
* @param hostname - Hostname of the Dapp | ||
* @param numberOfConnectedAccounts - Number of connected accounts that are connected to the Dapp | ||
*/ | ||
// This file will export more events in the future. | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const trackDappVisitedEvent = ({ | ||
hostname, | ||
numberOfConnectedAccounts, | ||
}: { | ||
hostname: string; | ||
numberOfConnectedAccounts: number; | ||
}) => { | ||
const visitedDappsByHostname = | ||
store.getState().browser.visitedDappsByHostname; | ||
const isFirstVisit = !visitedDappsByHostname[hostname]; | ||
const accountByAddress = selectIdentities(store.getState()); | ||
const numberOfWalletAccounts = Object.keys(accountByAddress).length; | ||
|
||
// Add Dapp hostname to visited dapps | ||
store.dispatch(addToVisitedDapp(hostname)); | ||
|
||
// Track DAPP_VISITED event | ||
AnalyticsV2.trackEvent(MetaMetricsEvents.DAPP_VISITED, { | ||
is_first_visit: isFirstVisit, | ||
number_of_accounts: numberOfWalletAccounts, | ||
number_of_accounts_connected: numberOfConnectedAccounts, | ||
source: 'in-app browser', | ||
}); | ||
}; |
4 changes: 2 additions & 2 deletions
4
app/components/Approvals/AddChainApproval/AddChainApproval.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/components/Approvals/ConnectApproval/ConnectApproval.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
app/components/Approvals/FlowLoaderModal/FlowLoaderModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/components/Approvals/InstallSnapApproval/InstallSnapApproval.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/components/Approvals/PermissionApproval/PermissionApproval.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/components/Approvals/SignatureApproval/SignatureApproval.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/components/Approvals/SignatureApproval/SignatureApproval.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.