Skip to content
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
13 changes: 13 additions & 0 deletions .changeset/social-login-project-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@reown/appkit-react-native': patch
'@reown/appkit-bitcoin-react-native': patch
'@reown/appkit-coinbase-react-native': patch
'@reown/appkit-common-react-native': patch
'@reown/appkit-core-react-native': patch
'@reown/appkit-ethers-react-native': patch
'@reown/appkit-solana-react-native': patch
'@reown/appkit-ui-react-native': patch
'@reown/appkit-wagmi-react-native': patch
---

fix(core): attribute social & email logins to the app's project id
68 changes: 68 additions & 0 deletions packages/core/src/__tests__/utils/CoreHelperUtil.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { SocialProvider } from '@reown/appkit-common-react-native';

import { CoreHelperUtil } from '../../utils/CoreHelperUtil';
import { OptionsController } from '../../controllers/OptionsController';

const WEB_WALLET_URL = 'https://web-wallet.walletconnect.org';
const WC_URI = 'wc:topic@2?relay-protocol=irn&symKey=key';
const ENCODED_WC_URI = encodeURIComponent(WC_URI);

describe('CoreHelperUtil', () => {
afterEach(() => {
OptionsController.setProjectId('');
});

describe('formatUniversalUrl', () => {
it('should add the encoded provider and project id for social login', () => {
OptionsController.setProjectId('test-project-id');
const { redirect, href } = CoreHelperUtil.formatUniversalUrl(
WEB_WALLET_URL,
WC_URI,
'google'
);
expect(redirect).toBe(
Comment thread
skibitsky marked this conversation as resolved.
`${WEB_WALLET_URL}/wc?uri=${ENCODED_WC_URI}&provider=google&projectId=test-project-id`
);
expect(href).toBe(`${WEB_WALLET_URL}/`);
});

it('should encode special characters in the provider and project id', () => {
OptionsController.setProjectId('proj+id=1&x');
const { redirect } = CoreHelperUtil.formatUniversalUrl(
WEB_WALLET_URL,
WC_URI,
'email+test' as SocialProvider
);
expect(redirect).toBe(
`${WEB_WALLET_URL}/wc?uri=${ENCODED_WC_URI}&provider=email%2Btest&projectId=proj%2Bid%3D1%26x`
);
});

it('should omit the project id when it is blank', () => {
OptionsController.setProjectId(' ');
const { redirect } = CoreHelperUtil.formatUniversalUrl(WEB_WALLET_URL, WC_URI, 'email');
expect(redirect).toBe(`${WEB_WALLET_URL}/wc?uri=${ENCODED_WC_URI}&provider=email`);
});

it('should not add the project id without a provider', () => {
OptionsController.setProjectId('test-project-id');
const { redirect } = CoreHelperUtil.formatUniversalUrl('https://wallet.example.com', WC_URI);
expect(redirect).toBe(`https://wallet.example.com/wc?uri=${ENCODED_WC_URI}`);
});
});

describe('formatNativeUrl', () => {
it('should not add the project id to a native deep link', () => {
OptionsController.setProjectId('test-project-id');
const { redirect, href } = CoreHelperUtil.formatNativeUrl('wallet://', WC_URI);
expect(redirect).toBe(`wallet://wc?uri=${ENCODED_WC_URI}`);
expect(href).toBe('wallet://');
});

it('should not add the project id to a universal deep link', () => {
OptionsController.setProjectId('test-project-id');
const { redirect } = CoreHelperUtil.formatNativeUrl('https://wallet.example.com', WC_URI);
expect(redirect).toBe(`https://wallet.example.com/wc?uri=${ENCODED_WC_URI}`);
});
});
});
13 changes: 10 additions & 3 deletions packages/core/src/utils/CoreHelperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@ export const CoreHelperUtil = {
safeAppUrl = `${safeAppUrl}/`;
}
const encodedWcUrl = encodeURIComponent(wcUri);
let redirect = `${safeAppUrl}wc?uri=${encodedWcUrl}`;

if (provider) {
redirect = `${redirect}&provider=${encodeURIComponent(provider)}`;
const projectId = OptionsController.state.projectId.trim();
if (projectId) {
redirect = `${redirect}&projectId=${encodeURIComponent(projectId)}`;
}
}

return {
redirect: provider
? `${safeAppUrl}wc?uri=${encodedWcUrl}&provider=${provider}`
: `${safeAppUrl}wc?uri=${encodedWcUrl}`,
redirect,
href: safeAppUrl
};
},
Expand Down
Loading