Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet connect fix #5387

Merged
merged 9 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 56 additions & 58 deletions src/components/walletconnect-list/WalletConnectV2ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function WalletConnectV2ListItem({
const { chains } = requiredNamespaces.eip155;
const eip155Account = namespaces.eip155?.accounts?.[0] || undefined;

if (!eip155Account || !chains || !chains.length) {
if (!eip155Account) {
const e = new RainbowError(
`WalletConnectV2ListItem: unsupported namespace`
);
Expand All @@ -99,14 +99,11 @@ export function WalletConnectV2ListItem({
throw e;
}

const [ns, rawChainId, address] = eip155Account?.split(':') as [
string,
string,
string
];
const chainIds = chains
.map(chain => parseInt(chain.split(':')[1]))
.filter(isSupportedChain);
const address = eip155Account?.split(':')?.[2];
const chainIds =
chains
?.map(chain => parseInt(chain.split(':')[1]))
?.filter(isSupportedChain) ?? [];

if (!address) {
const e = new RainbowError(
Expand All @@ -122,8 +119,8 @@ export function WalletConnectV2ListItem({
dappName: metadata.name || 'Unknown Dapp',
dappUrl: metadata.url || 'Unknown URL',
dappLogo: metadata && metadata.icons ? metadata.icons[0] : undefined,
address,
chainIds,
address: address,
chainIds: chainIds,
};
}, [session]);

Expand Down Expand Up @@ -264,55 +261,56 @@ export function WalletConnectV2ListItem({
</Centered>
</SessionRow>
</ColumnWithMargins>

<Box
borderRadius={99}
paddingVertical="8px"
paddingHorizontal="12px"
justifyContent="center"
>
<RadialGradient
{...radialGradientProps}
// @ts-expect-error overloaded props RadialGradient
{!!availableNetworks?.length && (
<Box
borderRadius={99}
radius={600}
/>
<Inline alignVertical="center" alignHorizontal="justify">
<Inline alignVertical="center">
<Box style={{ flexDirection: 'row' }}>
{availableNetworks?.map((network, index) => {
return (
<Box
background="body (Deprecated)"
key={`availableNetwork-${network}`}
marginLeft={{ custom: index > 0 ? -4 : 0 }}
style={{
backgroundColor: colors.transparent,
zIndex: availableNetworks?.length - index,
borderRadius: 30,
}}
>
{network !== Network.mainnet ? (
<ChainBadge
network={network}
position="relative"
size="small"
/>
) : (
<CoinIcon
address={ETH_ADDRESS}
size={20}
symbol={ETH_SYMBOL}
network={network}
/>
)}
</Box>
);
})}
</Box>
paddingVertical="8px"
paddingHorizontal="12px"
justifyContent="center"
>
<RadialGradient
{...radialGradientProps}
// @ts-expect-error overloaded props RadialGradient
borderRadius={99}
radius={600}
/>
<Inline alignVertical="center" alignHorizontal="justify">
<Inline alignVertical="center">
<Box style={{ flexDirection: 'row' }}>
{availableNetworks?.map((network, index) => {
return (
<Box
background="body (Deprecated)"
key={`availableNetwork-${network}`}
marginLeft={{ custom: index > 0 ? -4 : 0 }}
style={{
backgroundColor: colors.transparent,
zIndex: availableNetworks?.length - index,
borderRadius: 30,
}}
>
{network !== Network.mainnet ? (
<ChainBadge
network={network}
position="relative"
size="small"
/>
) : (
<CoinIcon
address={ETH_ADDRESS}
size={20}
symbol={ETH_SYMBOL}
network={network}
/>
)}
</Box>
);
})}
</Box>
</Inline>
</Inline>
</Inline>
</Box>
</Box>
)}
</Row>
</Row>
</ContextMenuButton>
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,8 @@
"request_invalid": "The request contained invalid parameters. Please try again or contact Rainbow and/or dapp support teams.",
"eth_sign": "Rainbow does not support legacy eth_sign due to security concerns. \n Please contact Rainbow and/or dapp support teams if you have any questions.",
"request_unsupported_network": "The network specified in this request is not supported by Rainbow.",
"request_unsupported_methods": "The RPC method(s) specified in this request are not supported by Rainbow."
"request_unsupported_methods": "The RPC method(s) specified in this request are not supported by Rainbow.",
"no_accounts_found": "No accounts found in approved namespaces."
},
"dapp_warnings": {
"info_alert": {
Expand Down
21 changes: 20 additions & 1 deletion src/model/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { queryClient } from '@/react-query';
import { favoritesQueryKey } from '@/resources/favorites';
import { EthereumAddress, RainbowToken } from '@/entities';
import { getUniqueId } from '@/utils/ethereumUtils';
import { disconnectSession, getAllActiveSessions } from '@/walletConnect';

export default async function runMigrations() {
// get current version
Expand Down Expand Up @@ -702,10 +703,28 @@ export default async function runMigrations() {

migrations.push(v18);

/**
*************** Migration v19 ******************
Purge walletconnect v2 sessions with no accounts
*/
const v19 = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this to the new migrations flow that our king @estrattonbailey made? wanna deleeet these at some point

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally forgot that existed lol

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I having a stroke or did I respond to a notification like this months ago lmao

miss you guysssss ❤️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@estrattonbailey !!!!!

hope all is well over at bsky

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill never miss a chance to tag my king

const walletConnectV2Sessions = await getAllActiveSessions();
await Promise.all(
walletConnectV2Sessions.map(session => {
if (!session.namespaces.eip155.accounts.length) {
disconnectSession(session);
}
return Promise.resolve();
})
);
};

migrations.push(v19);

logger.sentry(
`Migrations: ready to run migrations starting on number ${currentVersion}`
);
// await setMigrationVersion(17);

if (migrations.length === currentVersion) {
logger.sentry(`Migrations: Nothing to run`);
return;
Expand Down
128 changes: 72 additions & 56 deletions src/screens/WalletConnectApprovalSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,8 @@ export default function WalletConnectApprovalSheet() {
const handleConnect = useCallback(() => {
handled.current = true;
goBack();
if (IS_IOS) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this inside wc approval callback. i noticed that this was causing the "connection successful" modal to pop up even if there was an error

navigate(Routes.WALLET_CONNECT_REDIRECT_SHEET, {
type: 'connect',
});
}
handleSuccess(true);
}, [handleSuccess, goBack, navigate]);
}, [handleSuccess, goBack]);

const handleCancel = useCallback(() => {
handled.current = true;
Expand Down Expand Up @@ -431,6 +426,76 @@ export default function WalletConnectApprovalSheet() {
const sheetHeight =
type === WalletConnectApprovalSheetType.connect ? 408 : 438;

const renderNetworks = useCallback(() => {
if (isWalletConnectV2) {
if (!chainIds?.length) {
return (
<Box height={{ custom: 38 }} justifyContent="center" width="full">
<LabelText>None</LabelText>
</Box>
);
} else {
return <NetworkPill chainIds={chainIds} />;
}
} else {
return (
<NetworkSwitcherParent
activeOpacity={0}
isMenuPrimaryAction
{...(android ? { onPress: onPressAndroid } : {})}
menuConfig={{
menuItems,
menuTitle: lang.t('walletconnect.available_networks'),
}}
onPressMenuItem={handleOnPressNetworksMenuItem}
useActionSheetFallback={false}
wrapNativeComponent={false}
>
<ButtonPressAnimation
style={{
alignItems: 'center',
flexDirection: 'row',
height: 38,
}}
>
<Centered marginRight={5}>
<ChainLogo
network={
type === WalletConnectApprovalSheetType.connect
? approvalNetworkInfo.value
: ethereumUtils.getNetworkFromChainId(Number(chainId))
}
/>
</Centered>
<LabelText align="right" numberOfLines={1}>
{`${
type === WalletConnectApprovalSheetType.connect
? approvalNetworkInfo.name
: ethereumUtils.getNetworkNameFromChainId(Number(chainId))
} ${
type === WalletConnectApprovalSheetType.connect &&
menuItems.length > 1
? '􀁰'
: ''
}`}
</LabelText>
</ButtonPressAnimation>
</NetworkSwitcherParent>
);
}
}, [
NetworkSwitcherParent,
approvalNetworkInfo.name,
approvalNetworkInfo.value,
chainId,
chainIds,
handleOnPressNetworksMenuItem,
isWalletConnectV2,
menuItems,
onPressAndroid,
type,
]);

return (
<Sheet>
{!Object.keys(meta).length ? (
Expand Down Expand Up @@ -585,56 +650,7 @@ export default function WalletConnectApprovalSheet() {
: lang.t(lang.l.walletconnect.approval_sheet_network)}
</SwitchText>
</Flex>
{isWalletConnectV2 ? (
<NetworkPill chainIds={chainIds} />
) : (
<NetworkSwitcherParent
activeOpacity={0}
isMenuPrimaryAction
{...(android ? { onPress: onPressAndroid } : {})}
menuConfig={{
menuItems,
menuTitle: lang.t('walletconnect.available_networks'),
}}
onPressMenuItem={handleOnPressNetworksMenuItem}
useActionSheetFallback={false}
wrapNativeComponent={false}
>
<ButtonPressAnimation
style={{
alignItems: 'center',
flexDirection: 'row',
height: 38,
}}
>
<Centered marginRight={5}>
<ChainLogo
network={
type === WalletConnectApprovalSheetType.connect
? approvalNetworkInfo.value
: ethereumUtils.getNetworkFromChainId(
Number(chainId)
)
}
/>
</Centered>
<LabelText align="right" numberOfLines={1}>
{`${
type === WalletConnectApprovalSheetType.connect
? approvalNetworkInfo.name
: ethereumUtils.getNetworkNameFromChainId(
Number(chainId)
)
} ${
type === WalletConnectApprovalSheetType.connect &&
menuItems.length > 1
? '􀁰'
: ''
}`}
</LabelText>
</ButtonPressAnimation>
</NetworkSwitcherParent>
)}
{renderNetworks()}
</RDSColumn>
</Columns>
</Box>
Expand Down
13 changes: 13 additions & 0 deletions src/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ export function getApprovedNamespaces(
try {
const namespaces = buildApprovedNamespaces(props);

if (!namespaces.eip155.accounts.length) {
return {
success: false,
result: undefined,
error: new Error(lang.t(T.errors.no_accounts_found)),
};
}

return {
success: true,
result: namespaces,
Expand Down Expand Up @@ -568,6 +576,11 @@ export async function onSessionProposal(
});

maybeGoBackAndClearHasPendingRedirect();
if (IS_IOS) {
Navigation.handleAction(Routes.WALLET_CONNECT_REDIRECT_SHEET, {
type: 'connect',
});
}
} else {
await rejectProposal({
proposal,
Expand Down