Skip to content

Commit

Permalink
fix(dcellar-web-ui): trustwallet load err
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Oct 12, 2023
1 parent c223021 commit 4e1bb0e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions apps/dcellar-web-ui/src/components/ConnectWallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setConnectWallet } from '@/store/slices/global';
import { useAppSelector } from '@/store';
import { useRouter } from 'next/router';
import { InternalRoutePaths } from '@/utils/constant';
import { useAccount } from 'wagmi';

interface ConnectWalletProps extends DCButtonProps {
icon?: ReactElement;
Expand All @@ -17,23 +18,23 @@ export const ConnectWallet = memo<Partial<ConnectWalletProps>>(function ConnectB
const dispatch = useDispatch();
const router = useRouter();
const { loginAccount } = useAppSelector((root) => root.persist);
const { isConnected } = useAccount();
const { icon, text, ...restProps } = props;
const onOpen = () => {
if (loginAccount) {
const originPathname = decodeURIComponent(router.query.originAsPath as string);
setTimeout(
() =>
router.push(
!!originPathname && originPathname !== 'undefined'
? originPathname
: InternalRoutePaths.buckets,
),
100,
);
return;
};
dispatch(setConnectWallet(true));
// The window.trustwallet.request method is undefined when the app is loaded. So add a delay to avoid.
setTimeout(() => {
if (loginAccount && isConnected) {
const originPathname = decodeURIComponent(router.query.originAsPath as string);
return router.push(
!!originPathname && originPathname !== 'undefined'
? originPathname
: InternalRoutePaths.buckets,
);
};
dispatch(setConnectWallet(true));
}, 200)
}

return (
<>
<DCButton
Expand Down

0 comments on commit 4e1bb0e

Please sign in to comment.