@reown/appkit-react-native 0.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/AppKit.js +105 -52
- package/lib/commonjs/AppKit.js.map +1 -1
- package/lib/commonjs/client.js +0 -4
- package/lib/commonjs/client.js.map +1 -1
- package/lib/commonjs/connectors/WalletConnectConnector.js +37 -24
- package/lib/commonjs/connectors/WalletConnectConnector.js.map +1 -1
- package/lib/commonjs/hooks/useAccount.js +5 -2
- package/lib/commonjs/hooks/useAccount.js.map +1 -1
- package/lib/commonjs/hooks/useAppKit.js +7 -1
- package/lib/commonjs/hooks/useAppKit.js.map +1 -1
- package/lib/commonjs/hooks/useAppKitEvents.js +4 -12
- package/lib/commonjs/hooks/useAppKitEvents.js.map +1 -1
- package/lib/commonjs/hooks/useProvider.js +14 -4
- package/lib/commonjs/hooks/useProvider.js.map +1 -1
- package/lib/commonjs/hooks/useWalletInfo.js +2 -6
- package/lib/commonjs/hooks/useWalletInfo.js.map +1 -1
- package/lib/commonjs/index.js +37 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modal/w3m-modal/index.js +9 -4
- package/lib/commonjs/modal/w3m-modal/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-account-activity/index.js +9 -0
- package/lib/commonjs/partials/w3m-account-activity/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-account-wallet-features/index.js +15 -16
- package/lib/commonjs/partials/w3m-account-wallet-features/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-send-input-token/index.js +1 -1
- package/lib/commonjs/partials/w3m-send-input-token/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-swap-details/index.js +1 -1
- package/lib/commonjs/partials/w3m-swap-details/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-swap-input/index.js +1 -1
- package/lib/commonjs/utils/HelpersUtil.js +5 -9
- package/lib/commonjs/utils/HelpersUtil.js.map +1 -1
- package/lib/commonjs/utils/NetworkUtil.js +22 -19
- package/lib/commonjs/utils/NetworkUtil.js.map +1 -1
- package/lib/commonjs/utils/UiUtil.js +5 -4
- package/lib/commonjs/utils/UiUtil.js.map +1 -1
- package/lib/commonjs/views/w3m-account-default-view/index.js +17 -18
- package/lib/commonjs/views/w3m-account-default-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-connect-view/index.js +1 -0
- package/lib/commonjs/views/w3m-connect-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-connecting-view/index.js +10 -4
- package/lib/commonjs/views/w3m-connecting-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-swap-preview-view/index.js +3 -3
- package/lib/commonjs/views/w3m-swap-preview-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-swap-view/index.js +7 -2
- package/lib/commonjs/views/w3m-swap-view/index.js.map +1 -1
- package/lib/module/AppKit.js +106 -52
- package/lib/module/AppKit.js.map +1 -1
- package/lib/module/client.js +0 -4
- package/lib/module/client.js.map +1 -1
- package/lib/module/connectors/WalletConnectConnector.js +37 -24
- package/lib/module/connectors/WalletConnectConnector.js.map +1 -1
- package/lib/module/hooks/useAccount.js +5 -2
- package/lib/module/hooks/useAccount.js.map +1 -1
- package/lib/module/hooks/useAppKit.js +7 -1
- package/lib/module/hooks/useAppKit.js.map +1 -1
- package/lib/module/hooks/useAppKitEvents.js +5 -13
- package/lib/module/hooks/useAppKitEvents.js.map +1 -1
- package/lib/module/hooks/useProvider.js +14 -4
- package/lib/module/hooks/useProvider.js.map +1 -1
- package/lib/module/hooks/useWalletInfo.js +3 -7
- package/lib/module/hooks/useWalletInfo.js.map +1 -1
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modal/w3m-modal/index.js +9 -4
- package/lib/module/modal/w3m-modal/index.js.map +1 -1
- package/lib/module/partials/w3m-account-activity/index.js +10 -1
- package/lib/module/partials/w3m-account-activity/index.js.map +1 -1
- package/lib/module/partials/w3m-account-wallet-features/index.js +16 -17
- package/lib/module/partials/w3m-account-wallet-features/index.js.map +1 -1
- package/lib/module/partials/w3m-send-input-token/index.js +1 -1
- package/lib/module/partials/w3m-send-input-token/index.js.map +1 -1
- package/lib/module/partials/w3m-swap-details/index.js +2 -2
- package/lib/module/partials/w3m-swap-details/index.js.map +1 -1
- package/lib/module/partials/w3m-swap-input/index.js +1 -1
- package/lib/module/utils/HelpersUtil.js +1 -5
- package/lib/module/utils/HelpersUtil.js.map +1 -1
- package/lib/module/utils/NetworkUtil.js +22 -19
- package/lib/module/utils/NetworkUtil.js.map +1 -1
- package/lib/module/utils/UiUtil.js +5 -4
- package/lib/module/utils/UiUtil.js.map +1 -1
- package/lib/module/views/w3m-account-default-view/index.js +17 -18
- package/lib/module/views/w3m-account-default-view/index.js.map +1 -1
- package/lib/module/views/w3m-connect-view/index.js +1 -0
- package/lib/module/views/w3m-connect-view/index.js.map +1 -1
- package/lib/module/views/w3m-connecting-view/index.js +10 -4
- package/lib/module/views/w3m-connecting-view/index.js.map +1 -1
- package/lib/module/views/w3m-swap-preview-view/index.js +3 -3
- package/lib/module/views/w3m-swap-preview-view/index.js.map +1 -1
- package/lib/module/views/w3m-swap-view/index.js +8 -3
- package/lib/module/views/w3m-swap-view/index.js.map +1 -1
- package/lib/typescript/AppKit.d.ts +11 -7
- package/lib/typescript/AppKit.d.ts.map +1 -1
- package/lib/typescript/AppKitContext.d.ts +1 -1
- package/lib/typescript/client.d.ts.map +1 -1
- package/lib/typescript/connectors/WalletConnectConnector.d.ts +11 -13
- package/lib/typescript/connectors/WalletConnectConnector.d.ts.map +1 -1
- package/lib/typescript/hooks/useAccount.d.ts.map +1 -1
- package/lib/typescript/hooks/useAppKit.d.ts +1 -0
- package/lib/typescript/hooks/useAppKit.d.ts.map +1 -1
- package/lib/typescript/hooks/useAppKitEvents.d.ts.map +1 -1
- package/lib/typescript/hooks/useProvider.d.ts +7 -2
- package/lib/typescript/hooks/useProvider.d.ts.map +1 -1
- package/lib/typescript/hooks/useWalletInfo.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modal/w3m-modal/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-account-activity/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-account-wallet-features/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-swap-details/index.d.ts.map +1 -1
- package/lib/typescript/utils/HelpersUtil.d.ts.map +1 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +3 -2
- package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -1
- package/lib/typescript/utils/UiUtil.d.ts +1 -2
- package/lib/typescript/utils/UiUtil.d.ts.map +1 -1
- package/lib/typescript/views/w3m-account-default-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-connect-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-connecting-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-swap-preview-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-swap-view/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/AppKit.ts +135 -55
- package/src/client.ts +0 -5
- package/src/connectors/WalletConnectConnector.ts +58 -33
- package/src/hooks/useAccount.ts +5 -2
- package/src/hooks/useAppKit.ts +7 -1
- package/src/hooks/useAppKitEvents.ts +3 -10
- package/src/hooks/useProvider.ts +16 -6
- package/src/hooks/useWalletInfo.ts +3 -6
- package/src/index.ts +7 -1
- package/src/modal/w3m-modal/index.tsx +7 -4
- package/src/partials/w3m-account-activity/index.tsx +15 -0
- package/src/partials/w3m-account-wallet-features/index.tsx +17 -20
- package/src/partials/w3m-send-input-token/index.tsx +1 -1
- package/src/partials/w3m-swap-details/index.tsx +6 -2
- package/src/partials/w3m-swap-input/index.tsx +1 -1
- package/src/utils/HelpersUtil.ts +1 -5
- package/src/utils/NetworkUtil.ts +25 -25
- package/src/utils/UiUtil.ts +5 -11
- package/src/views/w3m-account-default-view/index.tsx +25 -21
- package/src/views/w3m-connect-view/index.tsx +1 -0
- package/src/views/w3m-connecting-view/index.tsx +10 -4
- package/src/views/w3m-swap-preview-view/index.tsx +6 -3
- package/src/views/w3m-swap-view/index.tsx +9 -5
- package/CHANGELOG.md +0 -153
- package/lib/commonjs/networks/bitcoin.js +0 -40
- package/lib/commonjs/networks/bitcoin.js.map +0 -1
- package/lib/commonjs/networks/index.js +0 -28
- package/lib/commonjs/networks/index.js.map +0 -1
- package/lib/commonjs/networks/solana.js +0 -78
- package/lib/commonjs/networks/solana.js.map +0 -1
- package/lib/module/networks/bitcoin.js +0 -34
- package/lib/module/networks/bitcoin.js.map +0 -1
- package/lib/module/networks/index.js +0 -6
- package/lib/module/networks/index.js.map +0 -1
- package/lib/module/networks/solana.js +0 -72
- package/lib/module/networks/solana.js.map +0 -1
- package/lib/typescript/networks/bitcoin.d.ts +0 -4
- package/lib/typescript/networks/bitcoin.d.ts.map +0 -1
- package/lib/typescript/networks/index.d.ts +0 -4
- package/lib/typescript/networks/index.d.ts.map +0 -1
- package/lib/typescript/networks/solana.d.ts +0 -27
- package/lib/typescript/networks/solana.d.ts.map +0 -1
- package/src/networks/bitcoin.ts +0 -32
- package/src/networks/index.ts +0 -6
- package/src/networks/solana.ts +0 -44
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConnectionController } from '@reown/appkit-core-react-native';
|
|
2
2
|
import { UniversalProvider, type IUniversalProvider } from '@walletconnect/universal-provider';
|
|
3
3
|
import {
|
|
4
4
|
WalletConnector,
|
|
5
5
|
type AppKitNetwork,
|
|
6
6
|
type Namespaces,
|
|
7
|
-
type ProposalNamespaces,
|
|
8
7
|
type Provider,
|
|
9
8
|
type WalletInfo,
|
|
10
9
|
type ChainNamespace,
|
|
11
|
-
type CaipNetworkId
|
|
10
|
+
type CaipNetworkId,
|
|
11
|
+
type ConnectOptions,
|
|
12
|
+
type ConnectorInitOptions,
|
|
13
|
+
type Metadata
|
|
12
14
|
} from '@reown/appkit-common-react-native';
|
|
13
15
|
|
|
16
|
+
interface WalletConnectConnectorConfig {
|
|
17
|
+
projectId: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
export class WalletConnectConnector extends WalletConnector {
|
|
15
|
-
private
|
|
21
|
+
private readonly config: WalletConnectConnectorConfig;
|
|
22
|
+
|
|
23
|
+
constructor(config: WalletConnectConnectorConfig) {
|
|
24
|
+
super({ type: 'walletconnect' });
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override async init(ops: ConnectorInitOptions) {
|
|
29
|
+
super.init(ops);
|
|
30
|
+
|
|
31
|
+
const provider = await this.getUniversalProvider({
|
|
32
|
+
projectId: this.config.projectId,
|
|
33
|
+
metadata: ops.metadata
|
|
34
|
+
});
|
|
16
35
|
|
|
17
|
-
|
|
18
|
-
|
|
36
|
+
this.provider = provider as Provider;
|
|
37
|
+
|
|
38
|
+
await this.restoreSession();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private async restoreSession(): Promise<boolean> {
|
|
42
|
+
const provider = this.getProvider() as IUniversalProvider;
|
|
43
|
+
if (!provider) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
19
46
|
|
|
20
47
|
if (provider.session?.namespaces) {
|
|
21
48
|
this.namespaces = provider.session.namespaces as Namespaces;
|
|
@@ -31,50 +58,41 @@ export class WalletConnectConnector extends WalletConnector {
|
|
|
31
58
|
};
|
|
32
59
|
}
|
|
33
60
|
}
|
|
61
|
+
|
|
62
|
+
return true;
|
|
34
63
|
}
|
|
35
64
|
|
|
36
|
-
private
|
|
65
|
+
private async getUniversalProvider({
|
|
37
66
|
projectId,
|
|
38
67
|
metadata
|
|
39
68
|
}: {
|
|
40
69
|
projectId: string;
|
|
41
70
|
metadata: Metadata;
|
|
42
71
|
}): Promise<IUniversalProvider> {
|
|
43
|
-
if (!
|
|
44
|
-
|
|
72
|
+
if (!this.provider) {
|
|
73
|
+
this.provider = (await UniversalProvider.init({
|
|
45
74
|
projectId,
|
|
46
|
-
metadata
|
|
47
|
-
|
|
75
|
+
metadata,
|
|
76
|
+
storage: this.storage
|
|
77
|
+
})) as Provider;
|
|
48
78
|
}
|
|
49
79
|
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public static async create({
|
|
54
|
-
projectId,
|
|
55
|
-
metadata
|
|
56
|
-
}: {
|
|
57
|
-
projectId: string;
|
|
58
|
-
metadata: Metadata;
|
|
59
|
-
}): Promise<WalletConnectConnector> {
|
|
60
|
-
const provider = await WalletConnectConnector.getUniversalProvider({
|
|
61
|
-
projectId,
|
|
62
|
-
metadata
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return new WalletConnectConnector(provider);
|
|
80
|
+
return this.provider as IUniversalProvider;
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
override disconnect(): Promise<void> {
|
|
69
|
-
return this.
|
|
84
|
+
return this.getProvider().disconnect();
|
|
70
85
|
}
|
|
71
86
|
|
|
72
|
-
override async connect(opts:
|
|
87
|
+
override async connect(opts: ConnectOptions) {
|
|
73
88
|
function onUri(uri: string) {
|
|
74
89
|
ConnectionController.setWcUri(uri);
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
this.
|
|
92
|
+
const provider = this.getProvider() as IUniversalProvider;
|
|
93
|
+
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
provider.on('display_uri', onUri);
|
|
78
96
|
|
|
79
97
|
const session = await (this.provider as IUniversalProvider).connect({
|
|
80
98
|
namespaces: {},
|
|
@@ -87,12 +105,16 @@ export class WalletConnectConnector extends WalletConnector {
|
|
|
87
105
|
|
|
88
106
|
this.namespaces = session?.namespaces as Namespaces;
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
provider.off('display_uri', onUri);
|
|
91
109
|
|
|
92
110
|
return this.namespaces;
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
override getProvider(): Provider {
|
|
114
|
+
if (!this.provider) {
|
|
115
|
+
throw new Error('WalletConnectConnector: Provider not initialized. Call init() first.');
|
|
116
|
+
}
|
|
117
|
+
|
|
96
118
|
return this.provider;
|
|
97
119
|
}
|
|
98
120
|
|
|
@@ -101,8 +123,11 @@ export class WalletConnectConnector extends WalletConnector {
|
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
override switchNetwork(network: AppKitNetwork): Promise<void> {
|
|
104
|
-
if (!network
|
|
105
|
-
|
|
126
|
+
if (!network) throw new Error('No network provided');
|
|
127
|
+
|
|
128
|
+
let caipNetworkId = network.caipNetworkId ?? `eip155:${network.id}`;
|
|
129
|
+
|
|
130
|
+
(this.provider as IUniversalProvider).setDefaultChain(caipNetworkId);
|
|
106
131
|
|
|
107
132
|
return Promise.resolve();
|
|
108
133
|
}
|
package/src/hooks/useAccount.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { useSnapshot } from 'valtio';
|
|
2
2
|
import { ConnectionsController } from '@reown/appkit-core-react-native';
|
|
3
|
+
import { useAppKit } from './useAppKit';
|
|
3
4
|
|
|
4
5
|
export function useAccount() {
|
|
6
|
+
useAppKit(); // Use the hook for checks
|
|
7
|
+
|
|
5
8
|
const {
|
|
6
9
|
activeAddress: address,
|
|
7
10
|
activeNamespace,
|
|
8
11
|
connections
|
|
9
12
|
} = useSnapshot(ConnectionsController.state);
|
|
10
13
|
|
|
11
|
-
const connection = connections
|
|
14
|
+
const connection = activeNamespace ? connections.get(activeNamespace) : undefined;
|
|
12
15
|
|
|
13
16
|
return {
|
|
14
17
|
address: address?.split(':')[2],
|
|
15
18
|
isConnected: !!address,
|
|
16
|
-
chainId: connection?.
|
|
19
|
+
chainId: connection?.caipNetwork
|
|
17
20
|
};
|
|
18
21
|
}
|
package/src/hooks/useAppKit.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
+
import { useSnapshot } from 'valtio';
|
|
3
|
+
import { ModalController } from '@reown/appkit-core-react-native';
|
|
4
|
+
|
|
2
5
|
import type { AppKit } from '../AppKit';
|
|
3
6
|
import { AppKitContext } from '../AppKitContext';
|
|
4
7
|
|
|
@@ -7,10 +10,12 @@ interface UseAppKitReturn {
|
|
|
7
10
|
close: AppKit['close'];
|
|
8
11
|
disconnect: (namespace?: string) => void;
|
|
9
12
|
switchNetwork: AppKit['switchNetwork'];
|
|
13
|
+
isOpen: boolean;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export const useAppKit = (): UseAppKitReturn => {
|
|
13
17
|
const context = useContext(AppKitContext);
|
|
18
|
+
const { open } = useSnapshot(ModalController.state);
|
|
14
19
|
|
|
15
20
|
if (context === undefined) {
|
|
16
21
|
throw new Error('useAppKit must be used within an AppKitProvider');
|
|
@@ -24,6 +29,7 @@ export const useAppKit = (): UseAppKitReturn => {
|
|
|
24
29
|
open: context.appKit.open.bind(context.appKit),
|
|
25
30
|
close: context.appKit.close.bind(context.appKit),
|
|
26
31
|
disconnect: (namespace?: string) => context.appKit?.disconnect.bind(context.appKit)(namespace),
|
|
27
|
-
switchNetwork: context.appKit.switchNetwork.bind(context.appKit)
|
|
32
|
+
switchNetwork: context.appKit.switchNetwork.bind(context.appKit),
|
|
33
|
+
isOpen: open
|
|
28
34
|
};
|
|
29
35
|
};
|
|
@@ -2,19 +2,15 @@ import { useEffect } from 'react';
|
|
|
2
2
|
import { useSnapshot } from 'valtio';
|
|
3
3
|
import {
|
|
4
4
|
EventsController,
|
|
5
|
-
OptionsController,
|
|
6
5
|
type EventName,
|
|
7
6
|
type EventsControllerState
|
|
8
7
|
} from '@reown/appkit-core-react-native';
|
|
8
|
+
import { useAppKit } from './useAppKit';
|
|
9
9
|
|
|
10
10
|
export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
|
|
11
|
-
|
|
11
|
+
useAppKit(); // Use the hook for checks
|
|
12
12
|
const { data, timestamp } = useSnapshot(EventsController.state);
|
|
13
13
|
|
|
14
|
-
if (!projectId) {
|
|
15
|
-
throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
useEffect(() => {
|
|
19
15
|
const unsubscribe = EventsController.subscribe(newEvent => {
|
|
20
16
|
callback?.(newEvent);
|
|
@@ -32,10 +28,7 @@ export function useAppKitEventSubscription(
|
|
|
32
28
|
event: EventName,
|
|
33
29
|
callback: (newEvent: EventsControllerState) => void
|
|
34
30
|
) {
|
|
35
|
-
|
|
36
|
-
if (!projectId) {
|
|
37
|
-
throw new Error('Please call "createAppKit" before using "useAppKitEventSubscription" hook');
|
|
38
|
-
}
|
|
31
|
+
useAppKit(); // Use the hook for checks
|
|
39
32
|
|
|
40
33
|
useEffect(() => {
|
|
41
34
|
const unsubscribe = EventsController?.subscribeEvent(event, callback);
|
package/src/hooks/useProvider.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { useSnapshot } from 'valtio';
|
|
2
2
|
import { ConnectionsController } from '@reown/appkit-core-react-native';
|
|
3
|
-
import type { Provider } from '@reown/appkit-common-react-native';
|
|
3
|
+
import type { Provider, ChainNamespace } from '@reown/appkit-common-react-native';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface ProviderResult {
|
|
6
|
+
provider?: Provider;
|
|
7
|
+
providerType?: ChainNamespace;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useProvider(namespace?: ChainNamespace): ProviderResult {
|
|
6
11
|
const { connections, activeNamespace } = useSnapshot(ConnectionsController.state);
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
const targetNamespace = namespace ?? activeNamespace;
|
|
14
|
+
|
|
15
|
+
if (!targetNamespace) return { provider: undefined, providerType: undefined };
|
|
9
16
|
|
|
10
|
-
const connection = connections
|
|
17
|
+
const connection = connections.get(targetNamespace);
|
|
11
18
|
|
|
12
|
-
if (!connection) return undefined;
|
|
19
|
+
if (!connection) return { provider: undefined, providerType: undefined };
|
|
13
20
|
|
|
14
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
provider: connection.adapter.connector?.getProvider(),
|
|
23
|
+
providerType: connection.adapter.getSupportedNamespace()
|
|
24
|
+
};
|
|
15
25
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { useSnapshot } from 'valtio';
|
|
2
|
-
import { ConnectionsController
|
|
2
|
+
import { ConnectionsController } from '@reown/appkit-core-react-native';
|
|
3
|
+
import { useAppKit } from './useAppKit';
|
|
3
4
|
|
|
4
5
|
export function useWalletInfo() {
|
|
5
|
-
|
|
6
|
+
useAppKit(); // Use the hook for checks
|
|
6
7
|
const { walletInfo } = useSnapshot(ConnectionsController.state);
|
|
7
8
|
|
|
8
|
-
if (!projectId) {
|
|
9
|
-
throw new Error('Please call "createAppKit" before using "useWalletInfo" hook');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
9
|
return { walletInfo };
|
|
13
10
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,8 +21,10 @@ export type * from '@reown/appkit-core-react-native';
|
|
|
21
21
|
export { CoreHelperUtil } from '@reown/appkit-core-react-native';
|
|
22
22
|
|
|
23
23
|
export * from './AppKit';
|
|
24
|
-
export * from './networks';
|
|
25
24
|
export { AppKitProvider } from './AppKitContext';
|
|
25
|
+
|
|
26
|
+
export type { AppKitNetwork, Storage } from '@reown/appkit-common-react-native';
|
|
27
|
+
|
|
26
28
|
export { WalletConnectConnector } from './connectors/WalletConnectConnector';
|
|
27
29
|
|
|
28
30
|
/****** Hooks *******/
|
|
@@ -31,3 +33,7 @@ export { useProvider } from './hooks/useProvider';
|
|
|
31
33
|
export { useAccount } from './hooks/useAccount';
|
|
32
34
|
export { useWalletInfo } from './hooks/useWalletInfo';
|
|
33
35
|
export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents';
|
|
36
|
+
|
|
37
|
+
/********** Networks **********/
|
|
38
|
+
export { solana, solanaDevnet, solanaTestnet } from '@reown/appkit-common-react-native';
|
|
39
|
+
export { bitcoin, bitcoinTestnet } from '@reown/appkit-common-react-native';
|
|
@@ -33,6 +33,7 @@ export function AppKit() {
|
|
|
33
33
|
const { caipAddress, isConnected } = useSnapshot(AccountController.state);
|
|
34
34
|
const { frameViewVisible, webviewVisible } = useSnapshot(WebviewController.state);
|
|
35
35
|
const { themeMode, themeVariables } = useSnapshot(ThemeController.state);
|
|
36
|
+
const { projectId } = useSnapshot(OptionsController.state);
|
|
36
37
|
const { height } = useWindowDimensions();
|
|
37
38
|
const { isLandscape } = useCustomDimensions();
|
|
38
39
|
const portraitHeight = height - 80;
|
|
@@ -50,10 +51,10 @@ export function AppKit() {
|
|
|
50
51
|
return handleClose();
|
|
51
52
|
};
|
|
52
53
|
|
|
53
|
-
const prefetch = async () => {
|
|
54
|
+
const prefetch = useCallback(async () => {
|
|
54
55
|
await ApiController.prefetch();
|
|
55
56
|
EventsController.sendEvent({ type: 'track', event: 'MODAL_LOADED' });
|
|
56
|
-
};
|
|
57
|
+
}, []);
|
|
57
58
|
|
|
58
59
|
const handleClose = async () => {
|
|
59
60
|
if (OptionsController.state.isSiweEnabled) {
|
|
@@ -117,8 +118,10 @@ export function AppKit() {
|
|
|
117
118
|
};
|
|
118
119
|
|
|
119
120
|
useEffect(() => {
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
if (projectId) {
|
|
122
|
+
prefetch();
|
|
123
|
+
}
|
|
124
|
+
}, [projectId, prefetch]);
|
|
122
125
|
|
|
123
126
|
useEffect(() => {
|
|
124
127
|
onNewAddress(caipAddress);
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
AccountController,
|
|
16
16
|
AssetUtil,
|
|
17
17
|
ConnectionsController,
|
|
18
|
+
ConstantsUtil,
|
|
18
19
|
EventsController,
|
|
19
20
|
OptionsController,
|
|
20
21
|
TransactionsController
|
|
@@ -34,6 +35,9 @@ export function AccountActivity({ style }: Props) {
|
|
|
34
35
|
const { loading, transactions, next } = useSnapshot(TransactionsController.state);
|
|
35
36
|
const { activeNetwork } = useSnapshot(ConnectionsController.state);
|
|
36
37
|
const networkImage = AssetUtil.getNetworkImage(activeNetwork?.id);
|
|
38
|
+
const isSupported =
|
|
39
|
+
activeNetwork?.caipNetworkId &&
|
|
40
|
+
ConstantsUtil.ACTIVITY_SUPPORTED_CHAINS.includes(activeNetwork.caipNetworkId);
|
|
37
41
|
|
|
38
42
|
const handleLoadMore = () => {
|
|
39
43
|
const address = ConnectionsController.state.activeAddress?.split(':')[2];
|
|
@@ -81,6 +85,17 @@ export function AccountActivity({ style }: Props) {
|
|
|
81
85
|
);
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
if (!isSupported) {
|
|
89
|
+
return (
|
|
90
|
+
<Placeholder
|
|
91
|
+
icon="infoCircle"
|
|
92
|
+
title="Unsupported network"
|
|
93
|
+
description="Activity list is not available for this network"
|
|
94
|
+
style={[styles.placeholder, style]}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
// Only show placeholder when we're not in initial load or loading state
|
|
85
100
|
if (!Object.keys(transactionsByYear).length && !loading && !initialLoad) {
|
|
86
101
|
return (
|
|
@@ -3,10 +3,10 @@ import { useSnapshot } from 'valtio';
|
|
|
3
3
|
import { Balance, FlexView, IconLink, Tabs } from '@reown/appkit-ui-react-native';
|
|
4
4
|
import {
|
|
5
5
|
AccountController,
|
|
6
|
+
ConnectionsController,
|
|
6
7
|
ConstantsUtil,
|
|
7
8
|
CoreHelperUtil,
|
|
8
9
|
EventsController,
|
|
9
|
-
NetworkController,
|
|
10
10
|
OnRampController,
|
|
11
11
|
OptionsController,
|
|
12
12
|
RouterController,
|
|
@@ -25,8 +25,12 @@ export function AccountWalletFeatures() {
|
|
|
25
25
|
const [activeTab, setActiveTab] = useState(0);
|
|
26
26
|
const { tokenBalance } = useSnapshot(AccountController.state);
|
|
27
27
|
const { features, isOnRampEnabled } = useSnapshot(OptionsController.state);
|
|
28
|
+
const { activeNetwork } = useSnapshot(ConnectionsController.state);
|
|
28
29
|
const balance = CoreHelperUtil.calculateAndFormatBalance(tokenBalance as BalanceType[]);
|
|
29
|
-
const isSwapsEnabled =
|
|
30
|
+
const isSwapsEnabled =
|
|
31
|
+
features?.swaps &&
|
|
32
|
+
activeNetwork?.caipNetworkId &&
|
|
33
|
+
ConstantsUtil.SWAP_SUPPORTED_NETWORKS.includes(activeNetwork.caipNetworkId);
|
|
30
34
|
|
|
31
35
|
const onTabChange = (index: number) => {
|
|
32
36
|
setActiveTab(index);
|
|
@@ -46,23 +50,16 @@ export function AccountWalletFeatures() {
|
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
const onSwapPress = () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
properties: {
|
|
60
|
-
network: NetworkController.state.caipNetwork?.id || '',
|
|
61
|
-
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
RouterController.push('Swap');
|
|
65
|
-
}
|
|
53
|
+
SwapController.resetState();
|
|
54
|
+
EventsController.sendEvent({
|
|
55
|
+
type: 'track',
|
|
56
|
+
event: 'OPEN_SWAP',
|
|
57
|
+
properties: {
|
|
58
|
+
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
|
|
59
|
+
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
RouterController.push('Swap');
|
|
66
63
|
};
|
|
67
64
|
|
|
68
65
|
const onSendPress = () => {
|
|
@@ -70,7 +67,7 @@ export function AccountWalletFeatures() {
|
|
|
70
67
|
type: 'track',
|
|
71
68
|
event: 'OPEN_SEND',
|
|
72
69
|
properties: {
|
|
73
|
-
network:
|
|
70
|
+
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
|
|
74
71
|
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
75
72
|
}
|
|
76
73
|
});
|
|
@@ -43,7 +43,7 @@ export function SendInputToken({
|
|
|
43
43
|
const isNetworkToken =
|
|
44
44
|
token.address === undefined ||
|
|
45
45
|
Object.values(ConstantsUtil.NATIVE_TOKEN_ADDRESS).some(
|
|
46
|
-
nativeAddress => token?.address === nativeAddress
|
|
46
|
+
nativeAddress => token?.address?.split(':')[2] === nativeAddress
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const numericGas = NumberUtil.bigNumber(gasPrice).shiftedBy(-token.quantity.decimals);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useSnapshot } from 'valtio';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ConnectionsController,
|
|
5
|
+
ConstantsUtil,
|
|
6
|
+
SwapController
|
|
7
|
+
} from '@reown/appkit-core-react-native';
|
|
4
8
|
import {
|
|
5
9
|
FlexView,
|
|
6
10
|
Text,
|
|
@@ -80,7 +84,7 @@ export function SwapDetails({ initialOpen, canClose }: SwapDetailsProps) {
|
|
|
80
84
|
setModalData(
|
|
81
85
|
getModalData('networkCost', {
|
|
82
86
|
networkSymbol: SwapController.state.networkTokenSymbol,
|
|
83
|
-
networkName:
|
|
87
|
+
networkName: ConnectionsController.state.activeNetwork?.name
|
|
84
88
|
})
|
|
85
89
|
);
|
|
86
90
|
};
|
|
@@ -128,7 +128,7 @@ export function SwapInput({
|
|
|
128
128
|
>
|
|
129
129
|
<Text variant="small-400" color="fg-200" numberOfLines={1}>
|
|
130
130
|
{isMarketValueGreaterThanZero
|
|
131
|
-
? `~$${UiUtil.formatNumberToLocalString(marketValue,
|
|
131
|
+
? `~$${UiUtil.formatNumberToLocalString(marketValue, 6)}`
|
|
132
132
|
: ''}
|
|
133
133
|
</Text>
|
|
134
134
|
{showMax && (
|
package/src/utils/HelpersUtil.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { Namespace, NamespaceConfig } from '@walletconnect/universal-provider';
|
|
2
|
-
|
|
3
2
|
import type {
|
|
4
3
|
AppKitNetwork,
|
|
5
4
|
CaipNetworkId,
|
|
6
5
|
ChainNamespace
|
|
7
6
|
} from '@reown/appkit-common-react-native';
|
|
8
|
-
import { solana, solanaDevnet } from '
|
|
9
|
-
// import { EnsController, type OptionsControllerState } from '@reown/appkit-controllers'
|
|
10
|
-
|
|
11
|
-
// import { solana, solanaDevnet } from '../networks/index.js'
|
|
7
|
+
import { solana, solanaDevnet } from '@reown/appkit-common-react-native';
|
|
12
8
|
|
|
13
9
|
export const DEFAULT_METHODS = {
|
|
14
10
|
solana: [
|
package/src/utils/NetworkUtil.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { ConstantsUtil } from '@reown/appkit-common-react-native';
|
|
2
|
-
import type { AppKitNetwork, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
2
|
+
import type { AppKitNetwork, CaipNetworkId, Network } from '@reown/appkit-common-react-native';
|
|
3
3
|
|
|
4
4
|
export const NetworkUtil = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
projectId
|
|
22
|
-
)
|
|
23
|
-
]
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return formattedNetwork;
|
|
5
|
+
formatNetwork(network: Network, projectId: string): AppKitNetwork {
|
|
6
|
+
const formattedNetwork = {
|
|
7
|
+
...network,
|
|
8
|
+
rpcUrls: { ...network.rpcUrls },
|
|
9
|
+
chainNamespace: network.chainNamespace ?? 'eip155',
|
|
10
|
+
caipNetworkId: network.caipNetworkId ?? `${network.chainNamespace ?? 'eip155'}:${network.id}`
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
Object.keys(formattedNetwork.rpcUrls).forEach(key => {
|
|
14
|
+
const rpcConfig = formattedNetwork.rpcUrls[key];
|
|
15
|
+
if (rpcConfig?.http?.some(url => url.includes(ConstantsUtil.BLOCKCHAIN_API_RPC_URL))) {
|
|
16
|
+
formattedNetwork.rpcUrls[key] = {
|
|
17
|
+
...rpcConfig,
|
|
18
|
+
http: [this.getBlockchainApiRpcUrl(formattedNetwork.caipNetworkId, projectId)]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
29
21
|
});
|
|
22
|
+
|
|
23
|
+
return formattedNetwork;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
formatNetworks(networks: Network[], projectId: string): AppKitNetwork[] {
|
|
27
|
+
const formattedNetworks = networks.map(network => this.formatNetwork(network, projectId));
|
|
28
|
+
|
|
29
|
+
return formattedNetworks;
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
getBlockchainApiRpcUrl(caipNetworkId: CaipNetworkId, projectId: string) {
|
package/src/utils/UiUtil.ts
CHANGED
|
@@ -4,24 +4,18 @@ import {
|
|
|
4
4
|
StorageUtil,
|
|
5
5
|
type WcWallet
|
|
6
6
|
} from '@reown/appkit-core-react-native';
|
|
7
|
-
import {
|
|
8
|
-
LayoutAnimation,
|
|
9
|
-
type LayoutAnimationProperty,
|
|
10
|
-
type LayoutAnimationType
|
|
11
|
-
} from 'react-native';
|
|
12
7
|
|
|
13
8
|
export const UiUtil = {
|
|
14
9
|
TOTAL_VISIBLE_WALLETS: 4,
|
|
15
10
|
|
|
16
11
|
createViewTransition: () => {
|
|
17
|
-
|
|
12
|
+
//TODO: replace this with reanimated
|
|
13
|
+
// LayoutAnimation.configureNext(LayoutAnimation.create(200, 'easeInEaseOut', 'opacity'));
|
|
18
14
|
},
|
|
19
15
|
|
|
20
|
-
animateChange: (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
) => {
|
|
24
|
-
LayoutAnimation.configureNext(LayoutAnimation.create(150, type, creationProp));
|
|
16
|
+
animateChange: () => {
|
|
17
|
+
//TODO: replace this with reanimated
|
|
18
|
+
// LayoutAnimation.configureNext(LayoutAnimation.create(150, type, creationProp));
|
|
25
19
|
},
|
|
26
20
|
|
|
27
21
|
storeConnectedWallet: async (
|