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

feat(dcellar-web-ui): support walletConnect old #311

Closed
wants to merge 5 commits into from
Closed
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { useWalletSwitchNetWork } from '@/context/WalletConnectContext';
import { useLogin } from '@/hooks/useLogin';
import { IconFont } from '@/components/IconFont';
import { CHAIN_NAMES } from '@/constants/wallet';
import { useAccount } from 'wagmi';

export const WrongNetworkModal = ({ isOpen, onClose }: any) => {
const { logout } = useLogin();

const { address, connector, isConnected } = useAccount();
const { switchNetwork } = useWalletSwitchNetWork({
onSuccess() {
onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { reverseVisibilityType } from '@/constants/legacy';
import { resolve } from '@/facade/common';
import { broadcastFault, commonFault, createTxFault, simulateFault } from '@/facade/error';
import { parseErrorXml } from '@/utils/common';
import { isEmpty, keyBy } from 'lodash-es';
import { isEmpty } from 'lodash-es';
import { setupSpMeta } from '@/store/slices/sp';
import { AuthType } from '@bnb-chain/greenfield-js-sdk/dist/esm/clients/spclient/spClient';
import { setupAccountInfo } from '@/store/slices/accounts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bscChain, greenFieldChain } from '@/context/WalletConnectContext/chains
import { getDefaultConfig, WalletKitOptions, WalletKitProvider } from '@totejs/walletkit';
import { Text } from '@totejs/uikit';
import { GREENFIELD_CHAIN_ID } from '@/base/env';
import { metaMask, trustWallet } from '@totejs/walletkit/wallets';
import { metaMask, trustWallet, walletConnect } from '@totejs/walletkit/wallets';
import * as Sentry from '@sentry/nextjs';
import { reportEvent } from '@/utils/gtag';
import * as process from 'process';
Expand All @@ -18,10 +18,11 @@ const config = createConfig(
appName: 'Connect a Wallet',
autoConnect: true,
/* WC 2.0 requires a project ID (get one here: https://cloud.walletconnect.com/sign-in) */
// walletConnectProjectId: '7c6812d64a55a1438dce3c5b650dca8c',
connectors: [trustWallet(), metaMask()],
walletConnectProjectId: '89848e3205cafe0bf76c91aa1aaa71d0',
connectors: [trustWallet(), metaMask(), walletConnect()],
}),
);

const options: WalletKitOptions = {
initialChainId: GREENFIELD_CHAIN_ID,
closeModalAfterConnected: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ErrorMsgMap } from '@/context/WalletConnectContext/error/error';
import { toast } from '@totejs/uikit';
import { ConnectorNotFoundError } from 'wagmi';
import * as Sentry from '@sentry/nextjs';
import { disconnect } from '@wagmi/core';
import { parseWCMessage } from '@/utils/common';

export function handleWalletError(err: any, args: any, context: unknown) {
let text = '';
Expand All @@ -18,15 +20,23 @@ export function handleWalletError(err: any, args: any, context: unknown) {
}
break;
}

const code = err.cause?.code ?? err.code;
const message = err.cause?.message ?? err.message;
const message = parseWCMessage(err.cause?.message) ?? err.message;
const description = text || ErrorMsgMap[code] || message;

Sentry.withScope((scope) => {
scope.setTag('Component', 'handleWalletError');
Sentry.captureMessage(JSON.stringify(err));
});

// Compatible the walletConnect cannot switch network
if (JSON.stringify(err).includes("Cannot set properties of undefined (setting 'defaultChain')")) {
toast.error({
description: 'Sorry, it seems like we lost the connection of your wallet, please login again to continue.'
});
return disconnect()
}

toast.error({
description,
});
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/facade/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ErrorMsgMap } from '@/context/WalletConnectContext/error/error';
import { parseWCMessage } from '@/utils/common';

export type ErrorMsg = string;

Expand Down Expand Up @@ -58,11 +59,10 @@ export const simulateFault = (e: any): ErrorResponse => {

export const broadcastFault = (e: BroadcastTxError): ErrorResponse => {
const { code = '' } = e;
console.error('BroadcastFault', e, e.code);
if (String(code) === E_USER_REJECT_STATUS_NUM) {
return [null, ErrorMsgMap[E_USER_REJECT_STATUS_NUM]];
}
return [null, e?.message || E_UNKNOWN_ERROR];
return [null, parseWCMessage(e?.message) || E_UNKNOWN_ERROR];
};

export const createTxFault = (e: any): ErrorResponse => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const Banner = () => {
<Flex justifySelf={'flex-end'} alignSelf={'flex-end'}>
<Image
alt="dcellar function screenshot"
src={`${assetPrefix}/images/welcome/banner_3.png`}
src={`${assetPrefix}/images/welcome/banner_3_new.png`}
w={553}
sx={{
[mdMedia]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const FeatureItem = ({ title, desc, tag, introImg, introImgSm }: TFeature
<Text
fontFamily={INTER_FONT}
sx={{
fontWeight: 400,
fontSize: 16,
color: 'readable.secondary'
}}
>
{desc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export const keyFeatureList: TFeatureItem[] = [
},
{
label: 'Data Dashboard',
tag: '(coming soon)',
// tag: '(coming soon)',
title: 'Comprehensive Data Dashboard ',
desc: 'Comprehensive data dashboard displays storage usage, cost usage, and other relevant metrics.',
introImg: `${assetPrefix}/images/welcome/dashboard.png`,
introImgSm: `${assetPrefix}/images/welcome/dashboard_sm.png`,
introImg: `${assetPrefix}/images/welcome/dashboard_new.png`,
introImgSm: `${assetPrefix}/images/welcome/dashboard_sm_new.png`,
gaClickName: 'dc_lp.homepage.key_f.dashboard.click'
},
];
Expand Down
1 change: 1 addition & 0 deletions apps/dcellar-web-ui/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { OffChainAuthProvider } from '@/context/off-chain-auth/OffChainAuthConte
import { register } from 'swiper/element/bundle';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import '@totejs/walletkit/styles.css';

register();
export const ssrLandingRoutes = ['/', '/pricing-calculator', '/terms'];
Expand Down
9 changes: 9 additions & 0 deletions apps/dcellar-web-ui/src/utils/common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ export function scrollToId(id: string, top?: number) {
top: (rect?.top || 0) + document.documentElement.scrollTop - 65 - (top || 0),
behavior: 'smooth',
});
}

// because the walletConnect return message is: `{code: xx, message: 'xxx'}
export function parseWCMessage(jsonStr: string) {
try {
return JSON.parse(jsonStr)?.message ?? jsonStr;
} catch (e) {
return jsonStr
}
}
Loading