Skip to content

Commit

Permalink
fix: fixes missing analytics data for non-web dapps that don't have a…
Browse files Browse the repository at this point in the history
… url (no… (MetaMask#10232)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
Fixes missing analytics data for non-web dapps that don't have a url
(non-web dapps) connecting via SDK or WalletConnect

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
andreahaku authored Jul 18, 2024
1 parent 0abb822 commit 96d6399
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
38 changes: 21 additions & 17 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,30 @@ class AccountApproval extends PureComponent {
};

getAnalyticsParams = () => {
const { currentPageInformation, chainId, selectedAddress, accountsLength } =
this.props;
let urlHostName = 'N/A';

try {
const {
currentPageInformation,
chainId,
selectedAddress,
accountsLength,
} = this.props;
const url = new URL(currentPageInformation?.url);
return {
account_type: getAddressAccountType(selectedAddress),
dapp_host_name: url?.host,
chain_id: getDecimalChainId(chainId),
number_of_accounts: accountsLength,
number_of_accounts_connected: 1,
source: 'SDK / WalletConnect',
...currentPageInformation?.analytics,
};
if (currentPageInformation?.url) {
const url = new URL(currentPageInformation.url);
urlHostName = url.host;
}
} catch (error) {
return {};
console.error('URL conversion error:', error);
}

return {
account_type: selectedAddress
? getAddressAccountType(selectedAddress)
: null,
dapp_host_name: urlHostName,
chain_id: chainId ? getDecimalChainId(chainId) : null,
number_of_accounts: accountsLength,
number_of_accounts_connected: 1,
source: 'SDK / WalletConnect',
...currentPageInformation?.analytics,
};
};

componentDidMount = () => {
Expand Down
13 changes: 11 additions & 2 deletions app/components/UI/AccountApproval/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('../../../core/Engine', () => ({
state: {
keyrings: [
{
accounts: ['0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272'],
accounts: ['0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756'],
},
],
},
Expand All @@ -30,7 +30,16 @@ const mockInitialState = {
engine: {
backgroundState: {
...backgroundState,
AccountsController: MOCK_ACCOUNTS_CONTROLLER_STATE,
AccountsController: {
...MOCK_ACCOUNTS_CONTROLLER_STATE,
accounts: {
'0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756': {
balance: '0x0',
name: 'Account 1',
address: '0xC4966c0D659D99699BFD7EB54D8fafEE40e4a756',
},
},
},
},
},
};
Expand Down

0 comments on commit 96d6399

Please sign in to comment.