Skip to content

Commit 46f0731

Browse files
Merge branch 'develop' into feat/swaps
2 parents ede9670 + b2f40ab commit 46f0731

File tree

9 files changed

+113
-48
lines changed

9 files changed

+113
-48
lines changed

packages/core/src/controllers/ConnectionController.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface ConnectionControllerState {
4949
wcError?: boolean;
5050
pressedWallet?: WcWallet;
5151
recentWallets?: WcWallet[];
52+
selectedSocialProvider?: SocialProvider;
5253
connectedWalletImageUrl?: string;
5354
connectedSocialProvider?: SocialProvider;
5455
}
@@ -123,6 +124,10 @@ export const ConnectionController = {
123124
state.recentWallets = wallets;
124125
},
125126

127+
setSelectedSocialProvider(provider: ConnectionControllerState['selectedSocialProvider']) {
128+
state.selectedSocialProvider = provider;
129+
},
130+
126131
async setConnectedWalletImageUrl(url: ConnectionControllerState['connectedWalletImageUrl']) {
127132
state.connectedWalletImageUrl = url;
128133

@@ -180,7 +185,7 @@ export const ConnectionController = {
180185
resetWcConnection() {
181186
this.clearUri();
182187
state.pressedWallet = undefined;
183-
ConnectionController.setConnectedSocialProvider(undefined);
188+
state.selectedSocialProvider = undefined;
184189
ConnectionController.setConnectedWalletImageUrl(undefined);
185190
ConnectorController.setConnectedConnector(undefined);
186191
StorageUtil.removeWalletConnectDeepLink();

packages/core/src/controllers/RouterController.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { proxy } from 'valtio';
22
import type { WcWallet, CaipNetwork, Connector, SwapInputTarget } from '../utils/TypeUtil';
3-
import type { SocialProvider } from '@reown/appkit-common-react-native';
43

54
// -- Types --------------------------------------------- //
65
type TransactionAction = {
@@ -54,7 +53,6 @@ export interface RouterControllerState {
5453
network?: CaipNetwork;
5554
email?: string;
5655
newEmail?: string;
57-
socialProvider?: SocialProvider;
5856
swapTarget?: SwapInputTarget;
5957
};
6058
transactionStack: TransactionAction[];

packages/core/src/utils/TypeUtil.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,20 @@ export type Event =
620620
provider: SocialProvider;
621621
};
622622
}
623+
| {
624+
type: 'track';
625+
event: 'SOCIAL_LOGIN_REQUEST_USER_DATA';
626+
properties: {
627+
provider: SocialProvider;
628+
};
629+
}
630+
| {
631+
type: 'track';
632+
event: 'SOCIAL_LOGIN_CANCELED';
633+
properties: {
634+
provider: SocialProvider;
635+
};
636+
}
623637
| {
624638
type: 'track';
625639
event: 'SOCIAL_LOGIN_ERROR';

packages/scaffold/src/partials/w3m-header/index.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
RouterController,
44
ModalController,
55
EventsController,
6-
type RouterControllerState
6+
type RouterControllerState,
7+
ConnectionController
78
} from '@reown/appkit-core-react-native';
89
import { IconLink, Text, FlexView } from '@reown/appkit-ui-react-native';
910
import { StringUtil } from '@reown/appkit-common-react-native';
@@ -21,8 +22,8 @@ export function Header() {
2122
const connectorName = _data?.connector?.name;
2223
const walletName = _data?.wallet?.name;
2324
const networkName = _data?.network?.name;
24-
const socialName = _data?.socialProvider
25-
? StringUtil.capitalize(_data?.socialProvider)
25+
const socialName = ConnectionController.state.selectedSocialProvider
26+
? StringUtil.capitalize(ConnectionController.state.selectedSocialProvider)
2627
: undefined;
2728

2829
return {
@@ -64,6 +65,29 @@ export function Header() {
6465

6566
const header = headings(data, view);
6667

68+
const checkSocial = () => {
69+
if (
70+
RouterController.state.view === 'ConnectingFarcaster' ||
71+
RouterController.state.view === 'ConnectingSocial'
72+
) {
73+
EventsController.sendEvent({
74+
type: 'track',
75+
event: 'SOCIAL_LOGIN_CANCELED',
76+
properties: { provider: ConnectionController.state.selectedSocialProvider! }
77+
});
78+
}
79+
};
80+
81+
const handleGoBack = () => {
82+
checkSocial();
83+
RouterController.goBack();
84+
};
85+
86+
const handleClose = () => {
87+
checkSocial();
88+
ModalController.close();
89+
};
90+
6791
const dynamicButtonTemplate = () => {
6892
const noButtonViews = ['ConnectingSiwe'];
6993

@@ -74,12 +98,7 @@ export function Header() {
7498
const showBack = RouterController.state.history.length > 1;
7599

76100
return showBack ? (
77-
<IconLink
78-
icon="chevronLeft"
79-
size="md"
80-
onPress={RouterController.goBack}
81-
testID="button-back"
82-
/>
101+
<IconLink icon="chevronLeft" size="md" onPress={handleGoBack} testID="button-back" />
83102
) : (
84103
<IconLink icon="helpCircle" size="md" onPress={onHelpPress} testID="button-help" />
85104
);
@@ -100,7 +119,7 @@ export function Header() {
100119
<Text variant="paragraph-600" numberOfLines={1}>
101120
{header}
102121
</Text>
103-
<IconLink icon="close" size="md" onPress={ModalController.close} testID="button-close" />
122+
<IconLink icon="close" size="md" onPress={handleClose} testID="button-close" />
104123
</FlexView>
105124
);
106125
}

packages/scaffold/src/views/w3m-connect-socials-view/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSnapshot } from 'valtio';
33
import { ScrollView } from 'react-native';
44
import { StringUtil, type SocialProvider } from '@reown/appkit-common-react-native';
55
import {
6+
ConnectionController,
67
EventsController,
78
OptionsController,
89
RouterController,
@@ -19,15 +20,16 @@ export function ConnectSocialsView() {
1920
const socialProviders = (features?.socials ?? []) as SocialProvider[];
2021

2122
const onItemPress = (provider: SocialProvider) => {
23+
ConnectionController.setSelectedSocialProvider(provider);
2224
EventsController.sendEvent({
2325
type: 'track',
2426
event: 'SOCIAL_LOGIN_STARTED',
2527
properties: { provider }
2628
});
2729
if (provider === 'farcaster') {
28-
RouterController.push('ConnectingFarcaster', { socialProvider: provider });
30+
RouterController.push('ConnectingFarcaster');
2931
} else {
30-
RouterController.push('ConnectingSocial', { socialProvider: provider });
32+
RouterController.push('ConnectingSocial');
3133
}
3234
};
3335

packages/scaffold/src/views/w3m-connect-view/components/social-login-list.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { StyleSheet } from 'react-native';
22
import { FlexView, ListSocial, LogoSelect, Spacing, Text } from '@reown/appkit-ui-react-native';
33
import { type SocialProvider, StringUtil } from '@reown/appkit-common-react-native';
44
import {
5+
ConnectionController,
56
EventsController,
67
RouterController,
78
WebviewController
@@ -21,18 +22,19 @@ export function SocialLoginList({ options, disabled }: SocialLoginListProps) {
2122
let bottomSocials = showBigSocial ? options.slice(1) : options;
2223
bottomSocials = showMoreButton ? bottomSocials.slice(0, MAX_OPTIONS - 2) : bottomSocials;
2324

24-
const onItemPress = (social: SocialProvider) => {
25+
const onItemPress = (provider: SocialProvider) => {
26+
ConnectionController.setSelectedSocialProvider(provider);
2527
EventsController.sendEvent({
2628
type: 'track',
2729
event: 'SOCIAL_LOGIN_STARTED',
28-
properties: { provider: social }
30+
properties: { provider }
2931
});
3032
WebviewController.setConnecting(false);
3133

32-
if (social === 'farcaster') {
33-
RouterController.push('ConnectingFarcaster', { socialProvider: social });
34+
if (provider === 'farcaster') {
35+
RouterController.push('ConnectingFarcaster');
3436
} else {
35-
RouterController.push('ConnectingSocial', { socialProvider: social });
37+
RouterController.push('ConnectingSocial');
3638
}
3739
};
3840

packages/scaffold/src/views/w3m-connecting-farcaster-view/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import {
66
EventsController,
77
ModalController,
88
OptionsController,
9-
RouterController,
109
SnackController,
11-
WebviewController,
1210
type AppKitFrameProvider
1311
} from '@reown/appkit-core-react-native';
1412
import {
@@ -24,47 +22,51 @@ import { useCustomDimensions } from '../../hooks/useCustomDimensions';
2422
import styles from './styles';
2523

2624
export function ConnectingFarcasterView() {
27-
const { data } = RouterController.state;
2825
const { maxWidth: width } = useCustomDimensions();
2926
const authConnector = ConnectorController.getAuthConnector();
3027
const [error, setError] = useState(false);
3128
const [processing, setProcessing] = useState(false);
3229
const [url, setUrl] = useState<string | undefined>();
3330
const showCopy = OptionsController.isClipboardAvailable();
34-
const socialProvider = data?.socialProvider;
3531
const provider = authConnector?.provider as AppKitFrameProvider;
3632

3733
const onConnect = useCallback(async () => {
3834
try {
39-
if (!WebviewController.state.connecting && provider && socialProvider && authConnector) {
35+
if (provider && authConnector) {
4036
setError(false);
4137
const { url: farcasterUrl } = await provider.getFarcasterUri();
4238
setUrl(farcasterUrl);
4339
Linking.openURL(farcasterUrl);
40+
4441
await provider.connectFarcaster();
42+
EventsController.sendEvent({
43+
type: 'track',
44+
event: 'SOCIAL_LOGIN_REQUEST_USER_DATA',
45+
properties: { provider: 'farcaster' }
46+
});
4547
setProcessing(true);
4648
await ConnectionController.connectExternal(authConnector);
47-
ConnectionController.setConnectedSocialProvider(socialProvider);
49+
ConnectionController.setConnectedSocialProvider('farcaster');
4850
EventsController.sendEvent({
4951
type: 'track',
5052
event: 'SOCIAL_LOGIN_SUCCESS',
51-
properties: { provider: socialProvider }
53+
properties: { provider: 'farcaster' }
5254
});
53-
WebviewController.setConnecting(false);
55+
5456
setProcessing(false);
5557
ModalController.close();
5658
}
5759
} catch (e) {
5860
EventsController.sendEvent({
5961
type: 'track',
6062
event: 'SOCIAL_LOGIN_ERROR',
61-
properties: { provider: socialProvider! }
63+
properties: { provider: 'farcaster' }
6264
});
6365
SnackController.showError('Something went wrong');
6466
setError(true);
6567
setProcessing(false);
6668
}
67-
}, [provider, socialProvider, authConnector]);
69+
}, [provider, authConnector]);
6870

6971
const onCopyUrl = () => {
7072
if (url) {

packages/scaffold/src/views/w3m-connecting-social-view/index.tsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,31 @@ import { useCustomDimensions } from '../../hooks/useCustomDimensions';
1818
import styles from './styles';
1919

2020
export function ConnectingSocialView() {
21-
const { data } = RouterController.state;
2221
const { maxWidth: width } = useCustomDimensions();
2322
const { processingAuth } = useSnapshot(WebviewController.state);
23+
const { selectedSocialProvider } = useSnapshot(ConnectionController.state);
2424
const authConnector = ConnectorController.getAuthConnector();
2525
const [error, setError] = useState(false);
26-
const socialProvider = data?.socialProvider;
2726
const provider = authConnector?.provider as AppKitFrameProvider;
2827

2928
const onConnect = useCallback(async () => {
3029
try {
31-
if (!WebviewController.state.connecting && provider && socialProvider) {
30+
if (
31+
!WebviewController.state.connecting &&
32+
provider &&
33+
ConnectionController.state.selectedSocialProvider
34+
) {
3235
const { uri } = await provider.getSocialRedirectUri({
33-
provider: socialProvider
36+
provider: ConnectionController.state.selectedSocialProvider
3437
});
3538
WebviewController.setWebviewUrl(uri);
3639

37-
const isNativeApple = socialProvider === 'apple' && Platform.OS === 'ios';
40+
const isNativeApple =
41+
ConnectionController.state.selectedSocialProvider === 'apple' && Platform.OS === 'ios';
3842

3943
WebviewController.setWebviewVisible(!isNativeApple);
4044
WebviewController.setConnecting(true);
41-
WebviewController.setConnectingProvider(socialProvider);
45+
WebviewController.setConnectingProvider(ConnectionController.state.selectedSocialProvider);
4246
}
4347
} catch (e) {
4448
WebviewController.setWebviewVisible(false);
@@ -48,29 +52,38 @@ export function ConnectingSocialView() {
4852
SnackController.showError('Something went wrong');
4953
setError(true);
5054
}
51-
}, [provider, socialProvider]);
55+
}, [provider]);
5256

5357
const socialMessageHandler = useCallback(
5458
async (url: string) => {
5559
try {
5660
if (
5761
url.includes('/sdk/oauth') &&
58-
socialProvider &&
62+
ConnectionController.state.selectedSocialProvider &&
5963
authConnector &&
6064
!WebviewController.state.processingAuth
6165
) {
6266
WebviewController.setProcessingAuth(true);
6367
WebviewController.setWebviewVisible(false);
6468
const parsedUrl = new URL(url);
69+
70+
EventsController.sendEvent({
71+
type: 'track',
72+
event: 'SOCIAL_LOGIN_REQUEST_USER_DATA',
73+
properties: { provider: ConnectionController.state.selectedSocialProvider }
74+
});
75+
6576
await provider?.connectSocial(parsedUrl.search);
6677
await ConnectionController.connectExternal(authConnector);
67-
ConnectionController.setConnectedSocialProvider(socialProvider);
78+
ConnectionController.setConnectedSocialProvider(
79+
ConnectionController.state.selectedSocialProvider
80+
);
6881
WebviewController.setConnecting(false);
6982

7083
EventsController.sendEvent({
7184
type: 'track',
7285
event: 'SOCIAL_LOGIN_SUCCESS',
73-
properties: { provider: socialProvider }
86+
properties: { provider: ConnectionController.state.selectedSocialProvider }
7487
});
7588

7689
ModalController.close();
@@ -80,14 +93,14 @@ export function ConnectingSocialView() {
8093
EventsController.sendEvent({
8194
type: 'track',
8295
event: 'SOCIAL_LOGIN_ERROR',
83-
properties: { provider: socialProvider! }
96+
properties: { provider: ConnectionController.state.selectedSocialProvider! }
8497
});
8598
WebviewController.reset();
8699
RouterController.goBack();
87100
SnackController.showError('Something went wrong');
88101
}
89102
},
90-
[socialProvider, authConnector, provider]
103+
[authConnector, provider]
91104
);
92105

93106
useEffect(() => {
@@ -112,7 +125,7 @@ export function ConnectingSocialView() {
112125
style={{ width }}
113126
>
114127
<LoadingThumbnail paused={!!error}>
115-
<Logo logo={socialProvider ?? 'more'} height={72} width={72} />
128+
<Logo logo={selectedSocialProvider ?? 'more'} height={72} width={72} />
116129
{error && (
117130
<IconBox
118131
icon={'close'}
@@ -128,7 +141,7 @@ export function ConnectingSocialView() {
128141
<Text style={styles.continueText} variant="paragraph-500">
129142
{processingAuth
130143
? 'Loading user data'
131-
: `Continue with ${StringUtil.capitalize(socialProvider)}`}
144+
: `Continue with ${StringUtil.capitalize(selectedSocialProvider)}`}
132145
</Text>
133146
<Text variant="small-400" color="fg-200">
134147
{processingAuth

0 commit comments

Comments
 (0)