mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* redesign "add chain" button * fix wallet detection * [skip ci] update default value for ENV * fix tests * return button to the footer and add source to mixpanel event * regcred from helmfile for review * [skip ci] remove wallets env from values for demo stand * use react-query to cache detection result * add cookie to hide button in the topbar * add prefix to svg ids to fix rabby icon * update screenshot * remove unnecessary comment --------- Co-authored-by: Nick Zenchik <[email protected]>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
|
|
import * as mixpanel from 'lib/mixpanel/index';
|
|
import { toaster } from 'toolkit/chakra/toaster';
|
|
|
|
import useAddChain from './useAddChain';
|
|
import useProvider from './useProvider';
|
|
import useSwitchChain from './useSwitchChain';
|
|
|
|
interface Props {
|
|
source: 'Footer' | 'Top bar' | 'Chain widget';
|
|
onSuccess?: () => void;
|
|
}
|
|
|
|
export default function useAddChainClick({ source, onSuccess }: Props) {
|
|
const { data: { wallet, provider } = {} } = useProvider();
|
|
const addChain = useAddChain();
|
|
const switchChain = useSwitchChain();
|
|
|
|
return React.useCallback(async() => {
|
|
if (!wallet || !provider) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await addChain();
|
|
await switchChain();
|
|
|
|
toaster.success({
|
|
title: 'Success',
|
|
description: 'Successfully added network to your wallet',
|
|
});
|
|
|
|
mixpanel.logEvent(mixpanel.EventTypes.ADD_TO_WALLET, {
|
|
Target: 'network',
|
|
Wallet: wallet,
|
|
Source: source,
|
|
});
|
|
|
|
onSuccess?.();
|
|
} catch (error) {
|
|
toaster.error({
|
|
title: 'Error',
|
|
description: (error as Error)?.message || 'Something went wrong',
|
|
});
|
|
}
|
|
}, [ addChain, provider, wallet, switchChain, source, onSuccess ]);
|
|
}
|