Skip to content
Merged
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
52 changes: 45 additions & 7 deletions packages/appkit/src/AppKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class AppKit {
* @param namespace - The namespace to disconnect from.
* @param isInternal - Whether the disconnect is internal (i.e. from the AppKit) or external (i.e. from wallet side).
*/
async disconnect(namespace?: string, isInternal?: boolean): Promise<void> {
async disconnect(namespace?: ChainNamespace, isInternal?: boolean): Promise<void> {
try {
const activeNamespace = namespace ?? ConnectionsController.state.activeNamespace;

Expand Down Expand Up @@ -220,7 +220,10 @@ export class AppKit {

EventsController.sendEvent({
type: 'track',
event: 'DISCONNECT_SUCCESS'
event: 'DISCONNECT_SUCCESS',
properties: {
namespace: activeNamespace
}
});
} catch (error) {
LogController.sendError(error, 'AppKit.ts', 'disconnect');
Expand Down Expand Up @@ -270,7 +273,7 @@ export class AppKit {
type: 'track',
event: 'SWITCH_NETWORK',
properties: {
network: network.id
network: network.caipNetworkId
}
});

Expand Down Expand Up @@ -385,6 +388,10 @@ export class AppKit {
*/
private async initConnectors() {
ModalController.setLoading(true);

//Always init the walletconnect connector
await this.createWalletConnectConnector();

const connectedConnectors = await StorageUtil.getConnectedConnectors();
if (connectedConnectors.length > 0) {
for (const connected of connectedConnectors) {
Expand All @@ -401,10 +408,22 @@ export class AppKit {
await StorageUtil.removeConnectedConnectors(connected.type);
}
}

const address = ConnectionsController.state.activeAddress;
const walletInfo = ConnectionsController.state.walletInfo;
if (address) {
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
address: CoreHelperUtil.getPlainAddress(address),
properties: {
name: walletInfo?.name ?? 'Unknown',
reconnect: true
}
});
}
}

//Always init the walletconnect connector
await this.createWalletConnectConnector();
ModalController.setLoading(false);
}

Expand Down Expand Up @@ -644,6 +663,7 @@ export class AppKit {

private async initControllers(options: AppKitConfig) {
await this.initStorageAndValues(options);
let defaultNetwork;

OptionsController.setProjectId(options.projectId);
OptionsController.setMetadata(options.metadata);
Expand All @@ -667,8 +687,8 @@ export class AppKit {
OptionsController.setRequestedNetworks(this.networks);

if (options.defaultNetwork) {
const network = NetworkUtil.formatNetwork(options.defaultNetwork, this.projectId);
OptionsController.setDefaultNetwork(network);
defaultNetwork = NetworkUtil.formatNetwork(options.defaultNetwork, this.projectId);
OptionsController.setDefaultNetwork(defaultNetwork);
}

ThemeController.setDefaultThemeMode(options.themeMode);
Expand All @@ -694,6 +714,24 @@ export class AppKit {
) {
OptionsController.setIsOnRampEnabled(true);
}

EventsController.sendEvent({
type: 'track',
event: 'INITIALIZE',
properties: {
showWallets: options.features?.showWallets,
themeMode: options.themeMode,
themeVariables: options.themeVariables,
networks: this.networks.map(network => network.caipNetworkId).filter(Boolean),
defaultNetwork: defaultNetwork?.caipNetworkId,
metadata: options.metadata,
enableAnalytics: options.enableAnalytics,
features: options.features,
adapters: this.adapters.map(adapter => adapter?.constructor?.name).filter(Boolean),
extraConnectors: this.extraConnectors.map(connector => connector?.type).filter(Boolean),
siwx: !!options.siwx
}
});
}

private async initActiveNamespace() {
Expand Down
5 changes: 3 additions & 2 deletions packages/appkit/src/hooks/useAppKit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useContext, useMemo } from 'react';
import type { ChainNamespace } from '@reown/appkit-common-react-native';

import type { AppKit } from '../AppKit';
import { AppKitContext } from '../AppKitContext';

interface UseAppKitReturn {
open: AppKit['open'];
close: AppKit['close'];
disconnect: (namespace?: string) => void;
disconnect: (namespace?: ChainNamespace) => void;
switchNetwork: AppKit['switchNetwork'];
}

Expand All @@ -30,7 +31,7 @@ export const useAppKit = (): UseAppKitReturn => {
return {
open: context.appKit.open.bind(context.appKit),
close: context.appKit.close.bind(context.appKit),
disconnect: (namespace?: string) =>
disconnect: (namespace?: ChainNamespace) =>
context.appKit!.disconnect.bind(context.appKit!)(namespace),
switchNetwork: context.appKit.switchNetwork.bind(context.appKit)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function AccountWalletFeatures() {
const { features, isOnRampEnabled } = useSnapshot(OptionsController.state);
const { activeNetwork, balances, activeNamespace } = useSnapshot(ConnectionsController.state);
const balance = CoreHelperUtil.calculateAndFormatBalance(balances as BalanceType[]);
const network = ConnectionsController.state.activeNetwork?.caipNetworkId || '';
const network = ConnectionsController.state.activeNetwork?.caipNetworkId;
const isSmartAccount = ConnectionsController.state.accountType === 'smartAccount';
const showSend =
activeNamespace && ConstantsUtil.SEND_SUPPORTED_NAMESPACES.includes(activeNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ import { memo } from 'react';

interface WalletItemProps {
item: WcWallet;
displayIndex: number;
imageHeaders?: Record<string, string>;
onItemPress: (wallet: WcWallet) => void;
onItemPress: (wallet: WcWallet, displayIndex: number) => void;
style?: StyleProp<ViewStyle>;
testID?: string;
}

export function WalletItem({ item, imageHeaders, onItemPress, style, testID }: WalletItemProps) {
export function WalletItem({
item,
displayIndex,
imageHeaders,
onItemPress,
style,
testID
}: WalletItemProps) {
const { walletImages } = useSnapshot(AssetController.state);
const isInstalled = ApiController.state.installed.find(wallet => wallet?.id === item?.id);
const imageSrc = AssetUtil.getWalletImage(item, walletImages);
Expand All @@ -28,7 +36,7 @@ export function WalletItem({ item, imageHeaders, onItemPress, style, testID }: W
style={style}
imageHeaders={imageHeaders}
name={item?.name ?? 'Unknown'}
onPress={() => onItemPress(item)}
onPress={() => onItemPress(item, displayIndex)}
installed={!!isInstalled}
testID={testID}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ITEM_HEIGHT_WITH_GAP = ITEM_HEIGHT + Spacing['3xs'];

interface Props {
data: WcWallet[];
onItemPress: (wallet: WcWallet) => void;
onItemPress: (wallet: WcWallet, displayIndex: number) => void;
onEndReached?: () => void;
onEndReachedThreshold?: number;
isLoading?: boolean;
Expand Down Expand Up @@ -52,7 +52,7 @@ export function WalletList({
data={displayData}
style={[styles.list, { height: maxHeight }, style]}
columnWrapperStyle={styles.columnWrapperStyle}
renderItem={({ item }) => {
renderItem={({ item, index }) => {
if (isLoading) {
return <CardSelectLoader style={styles.itemContainer} />;
}
Expand All @@ -61,6 +61,7 @@ export function WalletList({
<WalletItem
item={item}
imageHeaders={imageHeaders}
displayIndex={index}
onItemPress={onItemPress}
style={styles.itemContainer}
testID={testIDKey ? `${testIDKey}-${item?.id}` : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Loading } from './components/Loading';
import { WalletList } from './components/WalletList';

interface AllWalletsListProps {
onItemPress: (wallet: WcWallet) => void;
onItemPress: (wallet: WcWallet, displayIndex: number) => void;
headerHeight?: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Loading } from '../w3m-all-wallets-list/components/Loading';
import { WalletList } from '../w3m-all-wallets-list/components/WalletList';

export interface AllWalletsSearchProps {
onItemPress: (wallet: WcWallet) => void;
onItemPress: (wallet: WcWallet, displayIndex: number) => void;
searchQuery?: string;
}

Expand Down
24 changes: 22 additions & 2 deletions packages/appkit/src/partials/w3m-connecting-mobile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
EventsController,
ConstantsUtil,
AssetController,
LogController
LogController,
ConnectionsController
} from '@reown/appkit-core-react-native';
import {
Button,
Expand Down Expand Up @@ -61,6 +62,21 @@ export function ConnectingMobile({ onRetry, onCopyUri, isInstalled }: Props) {
const onStorePress = () => {
if (storeUrl) {
CoreHelperUtil.openLink(storeUrl);
EventsController.sendEvent({
type: 'track',
event: 'GET_WALLET',
properties: {
name: data?.wallet?.name ?? 'Unknown',
link: storeUrl,
linkType: Platform.select({
ios: 'appstore',
android: 'playstore',
default: undefined
}),
explorerId: data?.wallet?.id,
walletRank: data?.wallet?.order
}
});
}
};

Expand All @@ -75,13 +91,17 @@ export function ConnectingMobile({ onRetry, onCopyUri, isInstalled }: Props) {
await CoreHelperUtil.openLink(redirect);
await WcController.state.wcPromise;
WcController.setConnectedWallet(wcLinking, data?.wallet);
const address = ConnectionsController.state.activeAddress;
const caipNetworkId = ConnectionsController.state.activeNetwork?.caipNetworkId;
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
address: CoreHelperUtil.getPlainAddress(address),
properties: {
method: 'mobile',
name: data?.wallet?.name ?? 'Unknown',
explorer_id: data?.wallet?.id
explorerId: data?.wallet?.id,
caipNetworkId
}
});
}
Expand Down
10 changes: 8 additions & 2 deletions packages/appkit/src/partials/w3m-connecting-qrcode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
WcController,
EventsController,
OptionsController,
SnackController
SnackController,
ConnectionsController,
CoreHelperUtil
} from '@reown/appkit-core-react-native';
import {
FlexView,
Expand Down Expand Up @@ -35,13 +37,17 @@ export function ConnectingQrCode() {

const onConnect = async () => {
await WcController.state.wcPromise;
const address = ConnectionsController.state.activeAddress;
const caipNetworkId = ConnectionsController.state.activeNetwork?.caipNetworkId;

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
address: CoreHelperUtil.getPlainAddress(address),
properties: {
method: 'qrcode',
name: 'WalletConnect'
name: 'WalletConnect',
caipNetworkId
}
});
};
Expand Down
9 changes: 7 additions & 2 deletions packages/appkit/src/partials/w3m-connecting-web/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
OptionsController,
EventsController,
AssetController,
LogController
LogController,
ConnectionsController
} from '@reown/appkit-core-react-native';
import {
Button,
Expand Down Expand Up @@ -51,14 +52,18 @@ export function ConnectingWeb({ onCopyUri }: ConnectingWebProps) {
await Linking.openURL(redirect);
await WcController.state.wcPromise;
WcController.setConnectedWallet(wcLinking, data?.wallet);
const address = ConnectionsController.state.activeAddress;
const caipNetworkId = ConnectionsController.state.activeNetwork?.caipNetworkId;

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
address: CoreHelperUtil.getPlainAddress(address),
properties: {
method: 'web',
name: data?.wallet?.name ?? 'Unknown',
explorer_id: data?.wallet?.id
explorerId: data?.wallet?.id,
caipNetworkId
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/appkit/src/utils/SIWXUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export const SIWXUtil = {
},
getSIWXEventProperties(error?: unknown) {
return {
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
network: ConnectionsController.state.activeNetwork?.caipNetworkId,
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
message: error ? CoreHelperUtil.parseError(error) : undefined
};
Expand Down
4 changes: 2 additions & 2 deletions packages/appkit/src/views/w3m-account-default-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function AccountDefaultView() {
type: 'track',
event: 'OPEN_SWAP',
properties: {
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
network: ConnectionsController.state.activeNetwork?.caipNetworkId,
isSmartAccount: false
}
});
Expand Down Expand Up @@ -158,7 +158,7 @@ export function AccountDefaultView() {
};

const onSendPress = () => {
const network = ConnectionsController.state.activeNetwork?.caipNetworkId || '';
const network = ConnectionsController.state.activeNetwork?.caipNetworkId;
const isSmartAccount = ConnectionsController.state.accountType === 'smartAccount';

EventsController.sendEvent({
Expand Down
11 changes: 9 additions & 2 deletions packages/appkit/src/views/w3m-all-wallets-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function AllWalletsView() {

const { debouncedCallback: onInputChange } = useDebounceCallback({ callback: setSearchQuery });

const onWalletPress = (wallet: WcWallet) => {
const onWalletPress = (wallet: WcWallet, displayIndex: number) => {
const isExternal = WcHelpersUtil.isExternalWallet(wallet);
if (isExternal) {
RouterController.push('ConnectingExternal', { wallet });
Expand All @@ -33,7 +33,14 @@ export function AllWalletsView() {
EventsController.sendEvent({
type: 'track',
event: 'SELECT_WALLET',
properties: { name: wallet.name ?? 'Unknown', platform: 'mobile', explorer_id: wallet.id }
properties: {
name: wallet.name ?? 'Unknown',
platform: 'mobile',
explorerId: wallet.id,
walletRank: wallet.order,
displayIndex,
view: 'AllWallets'
}
});
};

Expand Down
Loading