Skip to content

Commit

Permalink
use host for name
Browse files Browse the repository at this point in the history
  • Loading branch information
skylarbarrera committed Apr 9, 2024
1 parent 56a7ce1 commit 9a75e24
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/components/DappBrowser/search-input/AccountIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { useAppSessionsStore } from '@/state/appSessions';
import { useBrowserContext } from '../BrowserContext';
import { getDappHost } from '../handleProviderRequest';
import { Address, toHex } from 'viem';
import { getMainnetNetworkObject } from '@/networks/mainnet';
import { handleDappBrowserConnectionPrompt } from '@/utils/requestNavigationHandlers';
import { getNetworkFromChainId } from '@/utils/ethereumUtils';

interface MenuItemIcon {
iconType: 'ASSET' | 'SYSTEM';
Expand Down Expand Up @@ -193,25 +194,35 @@ export const AccountIcon = () => {
}, [currentNetwork, isConnected]);

const handleOnPressMenuItem = useCallback(
({ nativeEvent: { actionKey } }: { nativeEvent: { actionKey: string } }) => {
async ({ nativeEvent: { actionKey } }: { nativeEvent: { actionKey: string } }) => {
if (actionKey === 'connect') {
if (!isConnected) {
const url = getActiveTabState()?.url;
const mainnet = getMainnetNetworkObject();
appSessions.addSession({
host: getDappHost(url) || '',
// @ts-ignore
address: currentAddress,
// @ts-ignore
network: mainnet,
// @ts-ignore
url: url || '',
const name = getDappHost(url);

const response = await handleDappBrowserConnectionPrompt({
dappName: name || '',
dappUrl: url || '',
});
setIsConnected(true);
if (!(response instanceof Error)) {
appSessions.addSession({
host: getDappHost(url) || '',
// @ts-ignore
address: response.address,
// @ts-ignore
network: getNetworkFromChainId(response.chainId),
// @ts-ignore
url: url || '',
});

setIsConnected(true);

activeTabRef.current?.injectJavaScript(
`window.ethereum.emit('accountsChanged', ['${currentAddress}']); window.ethereum.emit('connect', { address: '${currentAddress}', chainId: '${toHex(mainnet.id)}' }); true;`
);
activeTabRef.current?.injectJavaScript(
`window.ethereum.emit('accountsChanged', ['${currentAddress}']); window.ethereum.emit('connect', { address: '${currentAddress}', chainId: '${toHex(response.chainId)}' }); true;`
);
} else {
console.log('error: !!!!!!!!! ', response);
}
} else {
const activeTabHost = getDappHost(getActiveTabState()?.url);
if (activeTabHost) {
Expand Down

0 comments on commit 9a75e24

Please sign in to comment.