mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* debug wallet client error * Support raw text/html for NFT animation on the token instance page Resolves #2609 * fix writing to a contract with dynamic provider * change default interval for hot contracts * wait for load event of NFT embed frame * update screenshots * add network validation mode to dynamic provider * add rootstock mainnet preset * update preset for rootsrock mainnet * [skip ci] disable essential dapps for rootstock mainnet * pass required flag to FormFieldSelect controller * bump dynamic version * fix rabby wallet tx write
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { useDynamicContext, useDynamicEvents, useUserWallets } from '@dynamic-labs/sdk-react-core';
|
|
import React from 'react';
|
|
import { useAccountEffect } from 'wagmi';
|
|
|
|
import type { Params, Result } from './types';
|
|
|
|
import * as mixpanel from 'lib/mixpanel/index';
|
|
|
|
import useAccountDynamic from '../account/useAccountDynamic';
|
|
|
|
export default function useWalletDynamic({ source, onConnect }: Params): Result {
|
|
const isConnectionStarted = React.useRef(false);
|
|
const [ isOpen ] = React.useState(false);
|
|
const [ isClientLoaded, setIsClientLoaded ] = React.useState(false);
|
|
|
|
const { setShowDynamicUserProfile, setShowAuthFlow, setAuthMode, removeWallet, primaryWallet } = useDynamicContext();
|
|
|
|
const openModal = React.useCallback(() => {
|
|
setShowDynamicUserProfile(true);
|
|
mixpanel.logEvent(mixpanel.EventTypes.ACCOUNT_ACCESS, { Action: 'Dropdown open' });
|
|
}, [ setShowDynamicUserProfile ]);
|
|
|
|
useDynamicEvents('authFlowOpen', async() => {
|
|
if (!isConnectionStarted.current) {
|
|
mixpanel.logEvent(mixpanel.EventTypes.WALLET_CONNECT, { Source: source, Status: 'Started' });
|
|
isConnectionStarted.current = true;
|
|
}
|
|
});
|
|
|
|
const handleAccountConnected = React.useCallback(({ isReconnected }: { isReconnected: boolean }) => {
|
|
if (!isReconnected && isConnectionStarted.current) {
|
|
mixpanel.logEvent(mixpanel.EventTypes.WALLET_CONNECT, { Source: source, Status: 'Connected' });
|
|
mixpanel.userProfile.setOnce({
|
|
'With Connected Wallet': true,
|
|
});
|
|
onConnect?.();
|
|
}
|
|
isConnectionStarted.current = false;
|
|
}, [ source, onConnect ]);
|
|
|
|
const handleConnect = React.useCallback(() => {
|
|
setAuthMode('connect-only');
|
|
setShowAuthFlow(true);
|
|
}, [ setAuthMode, setShowAuthFlow ]);
|
|
|
|
const userWallets = useUserWallets();
|
|
const primaryWalletId = userWallets[0]?.id;
|
|
|
|
const handleDisconnect = React.useCallback(() => {
|
|
primaryWalletId && removeWallet(primaryWalletId);
|
|
}, [ primaryWalletId, removeWallet ]);
|
|
|
|
useAccountEffect({ onConnect: handleAccountConnected });
|
|
|
|
React.useEffect(() => {
|
|
setIsClientLoaded(true);
|
|
}, []);
|
|
|
|
const account = useAccountDynamic();
|
|
const address = account.address;
|
|
const isConnected = isClientLoaded && !account.isDisconnected && account.address !== undefined;
|
|
const isDynamicWaaS = primaryWallet?.key === 'dynamicwaas';
|
|
|
|
return React.useMemo(() => ({
|
|
connect: handleConnect,
|
|
disconnect: handleDisconnect,
|
|
isOpen,
|
|
isConnected,
|
|
isReconnecting: false,
|
|
address,
|
|
openModal,
|
|
type: isDynamicWaaS ? 'dynamicwaas' : undefined,
|
|
}), [ handleConnect, handleDisconnect, isOpen, isConnected, address, openModal, isDynamicWaaS ]);
|
|
}
|