Skip to content

Commit

Permalink
Merge pull request #574 from lidofinance/develop
Browse files Browse the repository at this point in the history
Develop to Main
  • Loading branch information
itaven authored Jan 23, 2025
2 parents a5156b1 + b4c8463 commit 7d46328
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 533 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@lidofinance/analytics-matomo": "^0.45.1",
"@lidofinance/api-metrics": "^0.45.1",
"@lidofinance/api-rpc": "^0.45.1",
"@lidofinance/eth-api-providers": "^0.45.1",
"@lidofinance/eth-providers": "^0.45.1",
"@lidofinance/analytics-matomo": "^0.48.0",
"@lidofinance/api-metrics": "^0.48.0",
"@lidofinance/api-rpc": "^0.48.0",
"@lidofinance/eth-api-providers": "^0.48.0",
"@lidofinance/eth-providers": "^0.48.0",
"@lidofinance/lido-ethereum-sdk": "4.1.0",
"@lidofinance/lido-ui": "^3.26.0",
"@lidofinance/next-api-wrapper": "^0.45.1",
"@lidofinance/next-ip-rate-limit": "^0.45.1",
"@lidofinance/next-pages": "^0.45.1",
"@lidofinance/rpc": "^0.45.1",
"@lidofinance/satanizer": "^0.45.1",
"@lidofinance/next-api-wrapper": "^0.48.0",
"@lidofinance/next-ip-rate-limit": "^0.48.0",
"@lidofinance/next-pages": "^0.48.0",
"@lidofinance/rpc": "^0.48.0",
"@lidofinance/satanizer": "^0.48.0",
"@reef-knot/types": "^4.0.0",
"@tanstack/react-query": "^5.51.21",
"copy-to-clipboard": "^3.3.1",
Expand Down Expand Up @@ -70,7 +70,7 @@
"@lidofinance/eslint-config": "^0.34.0",
"@next/bundle-analyzer": "^13.2.4",
"@next/eslint-plugin-next": "^13.4.13",
"@playwright/test": "^1.29.2",
"@playwright/test": "^1.49.1",
"@svgr/webpack": "^8.0.1",
"@types/jest": "28.1.6",
"@types/js-cookie": "^3.0.0",
Expand Down Expand Up @@ -103,7 +103,7 @@
"jest": "^29.5.0",
"jsonschema": "^1.4.1",
"lint-staged": "^13.2.3",
"playwright": "^1.29.2",
"playwright": "^1.49.1",
"prettier": "^3.0.1",
"ts-jest": "^29.1.0",
"typescript": "5.4.5",
Expand Down
2 changes: 1 addition & 1 deletion pages/api/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper';
import { trackedFetchRpcFactory } from '@lidofinance/api-rpc';
import { rpcFactory } from '@lidofinance/next-pages';

import { config, secretConfig } from 'config';
import { API_ROUTES } from 'consts/api';
Expand All @@ -14,7 +15,6 @@ import {
HttpMethod,
} from 'utilsApi';
import Metrics from 'utilsApi/metrics';
import { rpcFactory } from 'utilsApi/rpcFactory';
import {
METRIC_CONTRACT_ADDRESSES,
METRIC_CONTRACT_EVENT_ADDRESSES,
Expand Down
54 changes: 41 additions & 13 deletions shared/components/token-to-wallet/token-to-wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ToastInfo, Tooltip } from '@lidofinance/lido-ui';
import { usePublicClient, useWalletClient, useWatchAsset } from 'wagmi';
import { type Address, type PublicClient, getContract } from 'viem';

import { ToastError, ToastInfo, Tooltip } from '@lidofinance/lido-ui';
import { useIsLedgerLive } from 'shared/hooks/useIsLedgerLive';
import { TokenToWalletStyle } from './styles';

import { Component } from 'types';
import { useWalletClient, useWatchAsset } from 'wagmi';
import { Address, getContract } from 'viem';
import { useConnectorInfo } from 'reef-knot/core-react';
import type { Component } from 'types';

export type TokenToWalletComponent = Component<'button', { address?: string }>;

Expand All @@ -26,20 +27,19 @@ const ERC20_METADATA_ABI = [
] as const;

export const TokenToWallet: TokenToWalletComponent = ({ address, ...rest }) => {
const { watchAssetAsync } = useWatchAsset();
const { isInjected } = useConnectorInfo();
const { watchAssetAsync } = useWatchAsset({ mutation: { retry: false } });
const isLegerLive = useIsLedgerLive();
const client = usePublicClient();
const { data: walletClient } = useWalletClient();

if (!walletClient || !address || !isInjected) return null;
if (isLegerLive || !walletClient || !address) return null;

const onClickHandler = async () => {
if (!address) return;

try {
const tokenContract = getContract({
abi: ERC20_METADATA_ABI,
address: address as Address,
client: walletClient,
client: client as PublicClient,
});

const [decimals, symbol] = await Promise.all([
Expand All @@ -51,10 +51,38 @@ export const TokenToWallet: TokenToWalletComponent = ({ address, ...rest }) => {
type: 'ERC20',
options: { address, decimals, symbol },
});
if (!result) return;

ToastInfo('Tokens were successfully added to your wallet', {});
if (result) {
ToastInfo(`${symbol} token was successfully added to your wallet`);
} else {
ToastInfo(
`Request to watch ${symbol} token was rejected by your wallet`,
);
}
} catch (error) {
// Associating error code to UI messages
if (error && typeof error === 'object' && 'code' in error) {
if (
error?.code === -32602 // Trust
) {
ToastInfo('Token is already added');
} else if (
error?.code === 4001 || // Metamask, coin98, okx
error?.code === -32603 // Bitget
) {
ToastInfo(`Request to watch token was rejected by your wallet`);
} else if (
error?.code === -1 || // LL and Safe through WC
error?.code === -32601 // LL in Discover
) {
ToastError('The wallet does not support adding a token');
} else {
ToastError(
'An error occurred while adding token to wallet\nThe wallet might not support adding a token',
);
}
}

console.warn('[TokenToWallet] error adding token to wallet', error);
}
};
Expand Down
6 changes: 6 additions & 0 deletions shared/transaction-modal/transaction-modal-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { Text } from '@lidofinance/lido-ui';

export const Wrap = styled.div`
text-align: center;
margin-top: -34px;
${({ theme }) => theme.mediaQueries.md} {
margin-top: -26px;
padding-bottom: 12px;
}
`;

export const Title = styled(Text).attrs({
Expand Down
4 changes: 4 additions & 0 deletions utils/getErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const extractHumaneMessage = (error: unknown) => {
if (error instanceof SendCallsError) {
return error.message;
}

return null;
};

Expand Down Expand Up @@ -114,6 +115,9 @@ export const extractCodeFromError = (
normalizedMessage.includes('signed declined')
)
return 'ACTION_REJECTED';

if (normalizedMessage.includes('not enough ether for gas'))
return 'INSUFFICIENT_FUNDS';
}

if ('name' in error && typeof error.name == 'string') {
Expand Down
30 changes: 0 additions & 30 deletions utilsApi/rpcFactory/errors.ts

This file was deleted.

6 changes: 0 additions & 6 deletions utilsApi/rpcFactory/index.ts

This file was deleted.

155 changes: 0 additions & 155 deletions utilsApi/rpcFactory/rpc-factory.ts

This file was deleted.

Loading

0 comments on commit 7d46328

Please sign in to comment.