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/cool-parks-slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@reown/appkit-react-native': patch
'@reown/appkit-common-react-native': patch
'@reown/appkit-bitcoin-react-native': patch
'@reown/appkit-coinbase-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: renew uri after failure
4 changes: 3 additions & 1 deletion packages/appkit/src/partials/w3m-connecting-body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export interface ConnectingBodyProps {
export function ConnectingBody({ title, description }: ConnectingBodyProps) {
return (
<FlexView padding={['3xs', '2xl', '0', '2xl']} alignItems="center" style={styles.textContainer}>
<Text variant="paragraph-500">{title}</Text>
<Text center numberOfLines={1} variant="paragraph-500">
{title}
</Text>
{description ? (
<Text center variant="small-400" color="fg-200" style={styles.descriptionText}>
{description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function StoreLink({ visible, walletName = 'Wallet', onPress }: StoreLink

return (
<ActionEntry style={styles.storeButton}>
<Text numberOfLines={1} variant="paragraph-500" color="fg-200">
<Text numberOfLines={1} style={styles.storeText} variant="paragraph-500" color="fg-200">
{`Don't have ${walletName}?`}
</Text>
<Button
Expand All @@ -34,5 +34,8 @@ const styles = StyleSheet.create({
paddingHorizontal: Spacing.l,
marginHorizontal: Spacing.xl,
marginTop: Spacing.l
},
storeText: {
flexShrink: 1
}
});
7 changes: 6 additions & 1 deletion packages/appkit/src/partials/w3m-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ export function Header() {
padding={['l', 'xl', bottomPadding, 'xl']}
>
{dynamicButtonTemplate()}
<Text variant="paragraph-600" numberOfLines={1} testID="header-text">
<Text
variant="paragraph-600"
numberOfLines={1}
style={styles.headerText}
testID="header-text"
>
{header}
</Text>
{showClose ? (
Expand Down
3 changes: 3 additions & 0 deletions packages/appkit/src/partials/w3m-header/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export default StyleSheet.create({
iconPlaceholder: {
height: 32,
width: 32
},
headerText: {
flexShrink: 1
}
});
12 changes: 4 additions & 8 deletions packages/appkit/src/views/w3m-connecting-external-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import styles from './styles';
import { useInternalAppKit } from '../../AppKitContext';
import { StoreLink } from '../../partials/w3m-connecting-mobile/components/StoreLink';
import { WcHelpersUtil } from '../../utils/HelpersUtil';
import { ErrorUtil } from '@reown/appkit-common-react-native';

export function ConnectingExternalView() {
const { data } = useSnapshot(RouterController.state);
Expand Down Expand Up @@ -94,16 +95,11 @@ export function ConnectingExternalView() {
}
} catch (error) {
LogController.sendError(error, 'ConnectingExternalView.tsx', 'onConnect');
if (/(Wallet not found)/i.test((error as Error).message)) {
setErrorType('not_installed');
} else if (/(rejected)/i.test((error as Error).message)) {
setErrorType('declined');
} else {
setErrorType('default');
}
const type = ErrorUtil.categorizeConnectionError(error);
setErrorType(type);
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_ERROR',
event: type === 'declined' ? 'USER_REJECTED' : 'CONNECT_ERROR',
properties: { message: (error as Error)?.message ?? 'Unknown' }
});
}
Expand Down
32 changes: 24 additions & 8 deletions packages/appkit/src/views/w3m-connecting-view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSnapshot } from 'valtio';
import { useEffect, useLayoutEffect, useState } from 'react';
import { type Platform } from '@reown/appkit-common-react-native';
import { ErrorUtil, type Platform } from '@reown/appkit-common-react-native';
import {
WcController,
ConstantsUtil,
Expand Down Expand Up @@ -39,30 +39,46 @@ export function ConnectingView() {
}
};

const initializeConnection = async (retry = false) => {
const initializeConnection = async (retry = false, retryTimestamp?: number) => {
try {
const { wcPairingExpiry } = WcController.state;
const { data: routeData } = RouterController.state;
if (retry || CoreHelperUtil.isPairingExpired(wcPairingExpiry)) {
const isPairingExpired = CoreHelperUtil.isPairingExpired(wcPairingExpiry);
if (retry || isPairingExpired) {
WcController.setWcError(false);

const connectPromise = connect({
wallet: routeData?.wallet
});
WcController.setWcPromise(connectPromise);
await connectPromise;
}
} catch (error) {
LogController.sendError(error, 'ConnectingView.tsx', 'initializeConnection');
WcController.setWcError(true);
WcController.clearUri();
SnackController.showError('Declined');
if (isQr && CoreHelperUtil.isAllowedRetry(lastRetry)) {
setLastRetry(Date.now());
initializeConnection(true);

Comment thread
ignaciosantise marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.
const currentRetryTime = retryTimestamp ?? lastRetry;

if (isQr && CoreHelperUtil.isAllowedRetry(currentRetryTime)) {
const newRetryTime = Date.now();
setLastRetry(newRetryTime);
initializeConnection(true, newRetryTime);

return;
}

const isUserRejected = ErrorUtil.isUserRejectedRequestError(error);
const isProposalExpired = ErrorUtil.isProposalExpiredError(error);
if (!isProposalExpired) {
SnackController.showError(
isUserRejected ? 'User rejected the request' : 'Something went wrong'
);
}

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_ERROR',
event: isUserRejected ? 'USER_REJECTED' : 'CONNECT_ERROR',
Comment thread
ignaciosantise marked this conversation as resolved.
properties: {
message: (error as Error)?.message ?? 'Unknown'
}
Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/types/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type EventName =
| 'SELECT_WALLET'
| 'CONNECT_SUCCESS'
| 'CONNECT_ERROR'
| 'USER_REJECTED'
| 'DISCONNECT_SUCCESS'
| 'DISCONNECT_ERROR'
| 'CLICK_WALLET_HELP'
Expand Down Expand Up @@ -153,6 +154,14 @@ export type Event =
message: string;
};
}
| {
type: 'track';
address?: string;
event: 'USER_REJECTED';
properties: {
message: string;
};
}
| {
type: 'track';
event: 'DISCONNECT_SUCCESS';
Expand Down
78 changes: 78 additions & 0 deletions packages/common/src/utils/ErrorUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const ErrorUtil = {
RPC_ERROR_CODE: {
USER_REJECTED_REQUEST: 4001,
USER_REJECTED_METHODS: 5002
} as const,
UniversalProviderErrors: {
UNAUTHORIZED_DOMAIN_NOT_ALLOWED: {
message: 'Unauthorized: origin not allowed',
Expand Down Expand Up @@ -31,5 +35,79 @@ export const ErrorUtil = {
shortMessage: 'Project ID Not Configured',
longMessage: 'Project ID Not Configured - update configuration'
}
},
isRpcProviderError(error: any): error is { message: string; code: number } {
try {
if (typeof error === 'object' && error !== null) {
const objErr = error as Record<string, unknown>;

const hasMessage = typeof objErr['message'] === 'string';
const hasCode = typeof objErr['code'] === 'number';

return hasMessage && hasCode;
}

return false;
} catch {
return false;
}
},
isUserRejectedMessage(message: string) {
return (
message.toLowerCase().includes('rejected') ||
message.toLowerCase().includes('user cancelled') ||
message.toLowerCase().includes('user canceled')
);
},
isUserRejectedRequestError(error: any) {
if (ErrorUtil.isRpcProviderError(error)) {
const isUserRejectedCode = error.code === ErrorUtil.RPC_ERROR_CODE.USER_REJECTED_REQUEST;
const isUserRejectedMethodsCode =
error.code === ErrorUtil.RPC_ERROR_CODE.USER_REJECTED_METHODS;

return (
isUserRejectedCode ||
isUserRejectedMethodsCode ||
ErrorUtil.isUserRejectedMessage(error.message)
);
}

if (error instanceof Error) {
return ErrorUtil.isUserRejectedMessage(error.message);
}

return false;
},
isProposalExpiredError(error: any) {
if (ErrorUtil.isRpcProviderError(error)) {
return error.message?.toLowerCase().includes('proposal expired');
}

if (error) {
return (
typeof error?.message === 'string' &&
error.message?.toLowerCase().includes('proposal expired')
);
}

return false;
},
isWalletNotFoundError(error: any) {
if (error && typeof error?.message === 'string') {
return /wallet not found/i.test(error.message);
}

return false;
},
categorizeConnectionError(error: any): 'not_installed' | 'declined' | 'default' {
if (ErrorUtil.isWalletNotFoundError(error)) {
return 'not_installed';
}

if (ErrorUtil.isUserRejectedRequestError(error)) {
return 'declined';
}

return 'default';
}
};
Loading