@reown/appkit-core-react-native 2.0.0 → 2.0.1
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/controllers/ApiController.js +148 -82
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/AssetController.js +0 -4
- package/lib/commonjs/controllers/AssetController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +127 -134
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +280 -60
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/EnsController.js +6 -4
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +55 -5
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +9 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +134 -53
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +20 -7
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +7 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +115 -99
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SnackController.js +29 -5
- package/lib/commonjs/controllers/SnackController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +119 -119
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +5 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +25 -19
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/controllers/WcController.js +73 -0
- package/lib/commonjs/controllers/WcController.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/index.js +28 -0
- package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
- package/lib/commonjs/index.js +30 -37
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +1 -1
- package/lib/commonjs/utils/ApiUtil.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +8 -17
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +14 -431
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +33 -10
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/EventUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +41 -12
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +119 -172
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +2 -17
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +150 -82
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/AssetController.js +2 -4
- package/lib/module/controllers/AssetController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +128 -133
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +282 -60
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/EnsController.js +6 -2
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +54 -2
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +11 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +135 -52
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +22 -7
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/PublicStateController.js +2 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +9 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +114 -96
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +31 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +121 -119
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +7 -0
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +25 -17
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/controllers/WcController.js +70 -0
- package/lib/module/controllers/WcController.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/module/features/reown-authentication/index.js +5 -0
- package/lib/module/features/reown-authentication/index.js.map +1 -0
- package/lib/module/index.js +12 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ApiUtil.js +3 -1
- package/lib/module/utils/ApiUtil.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +10 -17
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +16 -431
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +35 -8
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/EventUtil.js +2 -0
- package/lib/module/utils/EventUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +44 -12
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +122 -172
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +4 -17
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/utils/SwapCalculationUtil.js +3 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +8 -7
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/AssetController.d.ts +0 -2
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +21 -13
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +22 -18
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/EnsController.d.ts +1 -1
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
- package/lib/typescript/controllers/EventsController.d.ts +13 -1
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
- package/lib/typescript/controllers/LogController.d.ts +65 -0
- package/lib/typescript/controllers/LogController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +1 -1
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +4 -3
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +8 -6
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +6 -21
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts +5 -7
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SnackController.d.ts +3 -3
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +11 -11
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +2 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/WcController.d.ts +27 -0
- package/lib/typescript/controllers/WcController.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
- package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ApiUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +3 -4
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +7 -416
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/EventUtil.d.ts +1 -1
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +3 -3
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/LogUtils.d.ts +15 -0
- package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +8 -19
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +12 -25
- package/src/controllers/ApiController.ts +158 -80
- package/src/controllers/AssetController.ts +0 -6
- package/src/controllers/BlockchainApiController.ts +109 -144
- package/src/controllers/ConnectionsController.ts +372 -88
- package/src/controllers/EnsController.ts +5 -3
- package/src/controllers/EventsController.ts +74 -3
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +11 -9
- package/src/controllers/OnRampController.ts +195 -82
- package/src/controllers/OptionsController.ts +40 -13
- package/src/controllers/RouterController.ts +20 -58
- package/src/controllers/SendController.ts +148 -112
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +140 -148
- package/src/controllers/ThemeController.ts +7 -0
- package/src/controllers/TransactionsController.ts +26 -18
- package/src/controllers/WcController.ts +93 -0
- package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
- package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
- package/src/features/reown-authentication/index.ts +2 -0
- package/src/index.ts +15 -22
- package/src/utils/ApiUtil.ts +1 -1
- package/src/utils/AssetUtil.ts +9 -20
- package/src/utils/ConstantsUtil.ts +16 -435
- package/src/utils/CoreHelperUtil.ts +62 -11
- package/src/utils/EventUtil.ts +1 -1
- package/src/utils/FetchUtil.ts +50 -14
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +171 -199
- package/src/utils/SwapApiUtil.ts +18 -37
- package/src/utils/SwapCalculationUtil.ts +1 -2
- package/src/utils/WalletUtil.ts +14 -0
- package/lib/commonjs/controllers/AccountController.js +0 -93
- package/lib/commonjs/controllers/AccountController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectionController.js +0 -132
- package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectorController.js +0 -50
- package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
- package/lib/commonjs/controllers/NetworkController.js +0 -90
- package/lib/commonjs/controllers/NetworkController.js.map +0 -1
- package/lib/commonjs/controllers/WebviewController.js +0 -52
- package/lib/commonjs/controllers/WebviewController.js.map +0 -1
- package/lib/commonjs/utils/NetworkUtil.js +0 -46
- package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
- package/lib/commonjs/utils/RouterUtil.js +0 -25
- package/lib/commonjs/utils/RouterUtil.js.map +0 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -6
- package/lib/commonjs/utils/TypeUtil.js.map +0 -1
- package/lib/module/controllers/AccountController.js +0 -88
- package/lib/module/controllers/AccountController.js.map +0 -1
- package/lib/module/controllers/ConnectionController.js +0 -127
- package/lib/module/controllers/ConnectionController.js.map +0 -1
- package/lib/module/controllers/ConnectorController.js +0 -45
- package/lib/module/controllers/ConnectorController.js.map +0 -1
- package/lib/module/controllers/NetworkController.js +0 -85
- package/lib/module/controllers/NetworkController.js.map +0 -1
- package/lib/module/controllers/WebviewController.js +0 -47
- package/lib/module/controllers/WebviewController.js.map +0 -1
- package/lib/module/utils/NetworkUtil.js +0 -40
- package/lib/module/utils/NetworkUtil.js.map +0 -1
- package/lib/module/utils/RouterUtil.js +0 -19
- package/lib/module/utils/RouterUtil.js.map +0 -1
- package/lib/module/utils/TypeUtil.js +0 -2
- package/lib/module/utils/TypeUtil.js.map +0 -1
- package/lib/typescript/controllers/AccountController.d.ts +0 -33
- package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
- package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
- package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
- package/lib/typescript/controllers/NetworkController.d.ts +0 -34
- package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
- package/lib/typescript/controllers/WebviewController.d.ts +0 -21
- package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
- package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
- package/lib/typescript/utils/RouterUtil.d.ts +0 -5
- package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
- package/lib/typescript/utils/TypeUtil.d.ts +0 -817
- package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
- package/src/controllers/AccountController.ts +0 -128
- package/src/controllers/ConnectionController.ts +0 -208
- package/src/controllers/ConnectorController.ts +0 -64
- package/src/controllers/NetworkController.ts +0 -120
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/NetworkUtil.ts +0 -33
- package/src/utils/RouterUtil.ts +0 -21
- package/src/utils/TypeUtil.ts +0 -995
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { proxy } from 'valtio';
|
|
2
|
-
import type { CaipNetwork } from '@reown/appkit-common-react-native';
|
|
3
|
-
|
|
4
2
|
import type {
|
|
3
|
+
AppKitNetwork,
|
|
4
|
+
SocialProvider,
|
|
5
5
|
WcWallet,
|
|
6
|
-
Connector,
|
|
7
|
-
SwapInputTarget,
|
|
8
6
|
OnRampTransactionResult
|
|
9
|
-
} from '
|
|
7
|
+
} from '@reown/appkit-common-react-native';
|
|
10
8
|
|
|
11
9
|
// -- Types --------------------------------------------- //
|
|
12
|
-
type TransactionAction = {
|
|
13
|
-
goBack: boolean;
|
|
14
|
-
view: RouterControllerState['view'] | null;
|
|
15
|
-
close?: boolean;
|
|
16
|
-
replace?: boolean;
|
|
17
|
-
onSuccess?: () => void;
|
|
18
|
-
onCancel?: () => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
10
|
export interface RouterControllerState {
|
|
22
11
|
view:
|
|
23
12
|
| 'Account'
|
|
@@ -26,13 +15,7 @@ export interface RouterControllerState {
|
|
|
26
15
|
| 'Connect'
|
|
27
16
|
| 'ConnectSocials'
|
|
28
17
|
| 'ConnectingExternal'
|
|
29
|
-
| 'ConnectingSiwe'
|
|
30
18
|
| 'ConnectingSocial'
|
|
31
|
-
| 'ConnectingFarcaster'
|
|
32
|
-
| 'ConnectingWalletConnect'
|
|
33
|
-
| 'Create'
|
|
34
|
-
| 'EmailVerifyDevice'
|
|
35
|
-
| 'EmailVerifyOtp'
|
|
36
19
|
| 'GetWallet'
|
|
37
20
|
| 'Networks'
|
|
38
21
|
| 'OnRamp'
|
|
@@ -40,18 +23,15 @@ export interface RouterControllerState {
|
|
|
40
23
|
| 'OnRampLoading'
|
|
41
24
|
| 'OnRampSettings'
|
|
42
25
|
| 'OnRampTransaction'
|
|
43
|
-
| '
|
|
26
|
+
| 'SIWXSignMessage'
|
|
44
27
|
| 'Swap'
|
|
45
|
-
| 'SwapSelectToken'
|
|
46
28
|
| 'SwapPreview'
|
|
29
|
+
| 'SwitchNetwork'
|
|
47
30
|
| 'Transactions'
|
|
48
31
|
| 'UnsupportedChain'
|
|
49
|
-
| 'UpdateEmailPrimaryOtp'
|
|
50
|
-
| 'UpdateEmailSecondaryOtp'
|
|
51
|
-
| 'UpdateEmailWallet'
|
|
52
32
|
| 'UpgradeEmailWallet'
|
|
53
|
-
| 'UpgradeToSmartAccount'
|
|
54
33
|
| 'WalletCompatibleNetworks'
|
|
34
|
+
| 'WalletConnect'
|
|
55
35
|
| 'WalletReceive'
|
|
56
36
|
| 'WalletSend'
|
|
57
37
|
| 'WalletSendPreview'
|
|
@@ -59,62 +39,41 @@ export interface RouterControllerState {
|
|
|
59
39
|
| 'WhatIsANetwork'
|
|
60
40
|
| 'WhatIsAWallet';
|
|
61
41
|
history: RouterControllerState['view'][];
|
|
42
|
+
navigationDirection: 'forward' | 'backward' | 'none';
|
|
62
43
|
data?: {
|
|
63
|
-
connector?: Connector;
|
|
64
44
|
wallet?: WcWallet;
|
|
65
|
-
network?:
|
|
66
|
-
email?: string;
|
|
67
|
-
newEmail?: string;
|
|
68
|
-
swapTarget?: SwapInputTarget;
|
|
45
|
+
network?: AppKitNetwork;
|
|
69
46
|
onrampResult?: OnRampTransactionResult;
|
|
47
|
+
socialProvider?: SocialProvider;
|
|
70
48
|
};
|
|
71
|
-
transactionStack: TransactionAction[];
|
|
72
49
|
}
|
|
73
50
|
|
|
74
51
|
// -- State --------------------------------------------- //
|
|
75
52
|
const state = proxy<RouterControllerState>({
|
|
76
53
|
view: 'Connect',
|
|
77
54
|
history: ['Connect'],
|
|
78
|
-
|
|
55
|
+
navigationDirection: 'none'
|
|
79
56
|
});
|
|
80
57
|
|
|
81
58
|
// -- Controller ---------------------------------------- //
|
|
82
59
|
export const RouterController = {
|
|
83
60
|
state,
|
|
84
61
|
|
|
85
|
-
push(
|
|
62
|
+
push(
|
|
63
|
+
view: RouterControllerState['view'],
|
|
64
|
+
data?: RouterControllerState['data'],
|
|
65
|
+
direction: 'forward' | 'backward' = 'forward'
|
|
66
|
+
) {
|
|
86
67
|
if (view !== state.view) {
|
|
68
|
+
state.navigationDirection = direction;
|
|
87
69
|
state.view = view;
|
|
88
70
|
state.history = [...state.history, view];
|
|
89
71
|
state.data = data;
|
|
90
72
|
}
|
|
91
73
|
},
|
|
92
74
|
|
|
93
|
-
pushTransactionStack(action: TransactionAction) {
|
|
94
|
-
state.transactionStack = [...state.transactionStack, action];
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
popTransactionStack(cancel?: boolean) {
|
|
98
|
-
const action = state.transactionStack.pop();
|
|
99
|
-
|
|
100
|
-
if (!action) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (cancel) {
|
|
105
|
-
this.goBack();
|
|
106
|
-
action?.onCancel?.();
|
|
107
|
-
} else {
|
|
108
|
-
if (action.goBack) {
|
|
109
|
-
this.goBack();
|
|
110
|
-
} else if (action.view) {
|
|
111
|
-
this.reset(action.view);
|
|
112
|
-
}
|
|
113
|
-
action?.onSuccess?.();
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
|
|
117
75
|
reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
|
|
76
|
+
state.navigationDirection = 'none';
|
|
118
77
|
state.view = view;
|
|
119
78
|
state.history = [view];
|
|
120
79
|
state.data = data;
|
|
@@ -122,6 +81,7 @@ export const RouterController = {
|
|
|
122
81
|
|
|
123
82
|
replace(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
|
|
124
83
|
if (state.history.length >= 1 && state.history.at(-1) !== view) {
|
|
84
|
+
state.navigationDirection = 'none';
|
|
125
85
|
state.view = view;
|
|
126
86
|
state.history[state.history.length - 1] = view;
|
|
127
87
|
state.data = data;
|
|
@@ -133,6 +93,7 @@ export const RouterController = {
|
|
|
133
93
|
state.history.pop();
|
|
134
94
|
const [last] = state.history.slice(-1);
|
|
135
95
|
if (last) {
|
|
96
|
+
state.navigationDirection = 'backward';
|
|
136
97
|
state.view = last;
|
|
137
98
|
}
|
|
138
99
|
}
|
|
@@ -143,6 +104,7 @@ export const RouterController = {
|
|
|
143
104
|
state.history = state.history.slice(0, historyIndex + 1);
|
|
144
105
|
const [last] = state.history.slice(-1);
|
|
145
106
|
if (last) {
|
|
107
|
+
state.navigationDirection = 'backward';
|
|
146
108
|
state.view = last;
|
|
147
109
|
}
|
|
148
110
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { subscribeKey as subKey } from 'valtio/
|
|
2
|
-
import { proxy, ref, subscribe as sub } from 'valtio
|
|
1
|
+
import { subscribeKey as subKey } from 'valtio/utils';
|
|
2
|
+
import { proxy, ref, subscribe as sub } from 'valtio';
|
|
3
3
|
import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
|
|
4
|
-
|
|
5
|
-
import { ConnectionController } from './ConnectionController';
|
|
4
|
+
|
|
6
5
|
import { SnackController } from './SnackController';
|
|
7
6
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
8
7
|
import { EventsController } from './EventsController';
|
|
9
8
|
import { RouterController } from './RouterController';
|
|
10
9
|
import { ConnectionsController } from './ConnectionsController';
|
|
10
|
+
import { SwapController } from './SwapController';
|
|
11
|
+
import { ConstantsUtil as CoreConstantsUtil } from '../utils/ConstantsUtil';
|
|
12
|
+
import { LogController } from './LogController';
|
|
11
13
|
|
|
12
14
|
// -- Types --------------------------------------------- //
|
|
13
15
|
export interface TxParams {
|
|
14
16
|
receiverAddress: string;
|
|
15
17
|
sendTokenAmount: number;
|
|
16
|
-
gasPrice: bigint;
|
|
17
18
|
decimals: string;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -30,8 +31,6 @@ export interface SendControllerState {
|
|
|
30
31
|
receiverAddress?: string;
|
|
31
32
|
receiverProfileName?: string;
|
|
32
33
|
receiverProfileImageUrl?: string;
|
|
33
|
-
gasPrice?: bigint;
|
|
34
|
-
gasPriceInUSD?: number;
|
|
35
34
|
loading: boolean;
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -78,152 +77,189 @@ export const SendController = {
|
|
|
78
77
|
state.receiverProfileName = receiverProfileName;
|
|
79
78
|
},
|
|
80
79
|
|
|
81
|
-
setGasPrice(gasPrice: SendControllerState['gasPrice']) {
|
|
82
|
-
state.gasPrice = gasPrice;
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
setGasPriceInUsd(gasPriceInUSD: SendControllerState['gasPriceInUSD']) {
|
|
86
|
-
state.gasPriceInUSD = gasPriceInUSD;
|
|
87
|
-
},
|
|
88
|
-
|
|
89
80
|
setLoading(loading: SendControllerState['loading']) {
|
|
90
81
|
state.loading = loading;
|
|
91
82
|
},
|
|
92
83
|
|
|
93
|
-
sendToken() {
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
async sendToken() {
|
|
85
|
+
const isAuth = !!ConnectionsController.state.connection?.properties?.provider;
|
|
86
|
+
const eventProperties = {
|
|
87
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
88
|
+
token: this.state.token?.address ?? this.state.token?.symbol ?? '',
|
|
89
|
+
amount: this.state.sendTokenAmount || 0,
|
|
90
|
+
network: ConnectionsController.state.activeNetwork?.caipNetworkId
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
this.state.loading = true;
|
|
95
|
+
|
|
96
96
|
EventsController.sendEvent({
|
|
97
97
|
type: 'track',
|
|
98
98
|
event: 'SEND_INITIATED',
|
|
99
|
-
properties:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
properties: eventProperties
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
switch (ConnectionsController.state.activeNamespace) {
|
|
103
|
+
case 'eip155':
|
|
104
|
+
await SendController.sendEvmToken();
|
|
105
|
+
|
|
106
|
+
break;
|
|
107
|
+
case 'solana':
|
|
108
|
+
await SendController.sendSolanaToken();
|
|
109
|
+
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
throw new Error('Unsupported chain');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
SnackController.showSuccess('Transaction started');
|
|
116
|
+
EventsController.sendEvent({
|
|
117
|
+
type: 'track',
|
|
118
|
+
event: 'SEND_SUCCESS',
|
|
119
|
+
properties: eventProperties
|
|
105
120
|
});
|
|
106
|
-
|
|
121
|
+
RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
|
|
122
|
+
this.resetState();
|
|
123
|
+
} catch (error: any) {
|
|
124
|
+
LogController.sendError(error, 'SendController.ts', 'sendToken');
|
|
125
|
+
EventsController.sendEvent({
|
|
126
|
+
type: 'track',
|
|
127
|
+
event: 'SEND_ERROR',
|
|
128
|
+
properties: eventProperties
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
error?.message &&
|
|
133
|
+
(error?.message.includes('user rejected') || error?.message.includes('canceled'))
|
|
134
|
+
) {
|
|
135
|
+
SnackController.showError('Transaction cancelled');
|
|
136
|
+
} else {
|
|
137
|
+
SnackController.showError('Something went wrong');
|
|
138
|
+
}
|
|
139
|
+
} finally {
|
|
140
|
+
this.state.loading = false;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
async sendEvmToken() {
|
|
145
|
+
if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
|
|
146
|
+
await this.sendERC20Token({
|
|
107
147
|
receiverAddress: this.state.receiverAddress,
|
|
108
148
|
tokenAddress: this.state.token.address,
|
|
109
149
|
sendTokenAmount: this.state.sendTokenAmount,
|
|
110
|
-
decimals: this.state.token.quantity
|
|
150
|
+
decimals: this.state.token.quantity?.decimals || '0'
|
|
111
151
|
});
|
|
112
152
|
} else if (
|
|
113
153
|
this.state.receiverAddress &&
|
|
114
154
|
this.state.sendTokenAmount &&
|
|
115
|
-
this.state.
|
|
116
|
-
this.state.token?.quantity.decimals
|
|
155
|
+
this.state.token?.quantity?.decimals
|
|
117
156
|
) {
|
|
118
|
-
|
|
119
|
-
EventsController.sendEvent({
|
|
120
|
-
type: 'track',
|
|
121
|
-
event: 'SEND_INITIATED',
|
|
122
|
-
properties: {
|
|
123
|
-
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
|
|
124
|
-
token: this.state.token?.symbol,
|
|
125
|
-
amount: this.state.sendTokenAmount,
|
|
126
|
-
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
this.sendNativeToken({
|
|
157
|
+
await this.sendNativeToken({
|
|
130
158
|
receiverAddress: this.state.receiverAddress,
|
|
131
159
|
sendTokenAmount: this.state.sendTokenAmount,
|
|
132
|
-
gasPrice: this.state.gasPrice,
|
|
133
160
|
decimals: this.state.token.quantity.decimals
|
|
134
161
|
});
|
|
135
162
|
}
|
|
136
163
|
},
|
|
137
164
|
|
|
138
165
|
async sendNativeToken(params: TxParams) {
|
|
139
|
-
RouterController.pushTransactionStack({
|
|
140
|
-
view: 'Account',
|
|
141
|
-
goBack: false
|
|
142
|
-
});
|
|
143
|
-
|
|
144
166
|
const to = params.receiverAddress as `0x${string}`;
|
|
145
|
-
const
|
|
146
|
-
const
|
|
167
|
+
const network = ConnectionsController.state.activeNetwork;
|
|
168
|
+
const address = CoreHelperUtil.getPlainAddress(
|
|
169
|
+
ConnectionsController.state.activeAddress
|
|
170
|
+
) as `0x${string}`;
|
|
171
|
+
if (!address) {
|
|
172
|
+
throw new Error('Invalid address');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const value = ConnectionsController.parseUnits(
|
|
147
176
|
params.sendTokenAmount.toString(),
|
|
148
177
|
Number(params.decimals)
|
|
149
178
|
);
|
|
150
179
|
const data = '0x';
|
|
151
180
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
160
|
-
SnackController.showSuccess('Transaction started');
|
|
161
|
-
EventsController.sendEvent({
|
|
162
|
-
type: 'track',
|
|
163
|
-
event: 'SEND_SUCCESS',
|
|
164
|
-
properties: {
|
|
165
|
-
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
|
|
166
|
-
token: this.state.token?.symbol || '',
|
|
167
|
-
amount: params.sendTokenAmount,
|
|
168
|
-
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
this.resetSend();
|
|
172
|
-
} catch (error) {
|
|
173
|
-
state.loading = false;
|
|
174
|
-
EventsController.sendEvent({
|
|
175
|
-
type: 'track',
|
|
176
|
-
event: 'SEND_ERROR',
|
|
177
|
-
properties: {
|
|
178
|
-
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount',
|
|
179
|
-
token: this.state.token?.symbol || '',
|
|
180
|
-
amount: params.sendTokenAmount,
|
|
181
|
-
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
SnackController.showError('Something went wrong');
|
|
185
|
-
}
|
|
181
|
+
await ConnectionsController.sendTransaction({
|
|
182
|
+
to,
|
|
183
|
+
address,
|
|
184
|
+
data,
|
|
185
|
+
value,
|
|
186
|
+
network
|
|
187
|
+
});
|
|
186
188
|
},
|
|
187
189
|
|
|
188
190
|
async sendERC20Token(params: ContractWriteParams) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
goBack: false
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const amount = ConnectionController.parseUnits(
|
|
191
|
+
const network = ConnectionsController.state.activeNetwork;
|
|
192
|
+
const amount = ConnectionsController.parseUnits(
|
|
195
193
|
params.sendTokenAmount.toString(),
|
|
196
194
|
Number(params.decimals)
|
|
197
195
|
);
|
|
198
196
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
method: 'transfer',
|
|
215
|
-
abi: ContractUtil.getERC20Abi(tokenAddress)
|
|
216
|
-
});
|
|
217
|
-
SnackController.showSuccess('Transaction started');
|
|
218
|
-
this.resetSend();
|
|
197
|
+
if (
|
|
198
|
+
ConnectionsController.state.activeAddress &&
|
|
199
|
+
params.sendTokenAmount &&
|
|
200
|
+
params.receiverAddress &&
|
|
201
|
+
params.tokenAddress
|
|
202
|
+
) {
|
|
203
|
+
const tokenAddress = CoreHelperUtil.getPlainAddress(
|
|
204
|
+
params.tokenAddress as `${string}:${string}:${string}`
|
|
205
|
+
) as `0x${string}`;
|
|
206
|
+
|
|
207
|
+
const fromAddress = CoreHelperUtil.getPlainAddress(
|
|
208
|
+
ConnectionsController.state.activeAddress
|
|
209
|
+
) as `0x${string}`;
|
|
210
|
+
if (!fromAddress) {
|
|
211
|
+
throw new Error('Invalid address');
|
|
219
212
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
213
|
+
|
|
214
|
+
await ConnectionsController.writeContract({
|
|
215
|
+
fromAddress,
|
|
216
|
+
tokenAddress,
|
|
217
|
+
receiverAddress: params.receiverAddress as `0x${string}`,
|
|
218
|
+
tokenAmount: amount,
|
|
219
|
+
method: 'transfer',
|
|
220
|
+
abi: ContractUtil.getERC20Abi(tokenAddress),
|
|
221
|
+
network
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
async sendSolanaToken() {
|
|
227
|
+
if (!this.state.sendTokenAmount || !this.state.receiverAddress) {
|
|
228
|
+
throw new Error('An amount and receiver address are required');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const plainAddress = CoreHelperUtil.getPlainAddress(ConnectionsController.state.activeAddress);
|
|
232
|
+
if (!plainAddress) {
|
|
233
|
+
throw new Error('Invalid address');
|
|
223
234
|
}
|
|
235
|
+
|
|
236
|
+
let tokenMint: string | undefined;
|
|
237
|
+
|
|
238
|
+
if (
|
|
239
|
+
SendController.state.token &&
|
|
240
|
+
SendController.state.token.address !== CoreConstantsUtil.NATIVE_TOKEN_ADDRESS.solana
|
|
241
|
+
) {
|
|
242
|
+
if (CoreHelperUtil.isCaipAddress(SendController.state.token.address)) {
|
|
243
|
+
tokenMint = CoreHelperUtil.getPlainAddress(SendController.state.token.address);
|
|
244
|
+
} else {
|
|
245
|
+
tokenMint = SendController.state.token.address;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
await ConnectionsController.sendTransaction({
|
|
250
|
+
tokenMint,
|
|
251
|
+
fromAddress: plainAddress,
|
|
252
|
+
toAddress: this.state.receiverAddress,
|
|
253
|
+
amount: this.state.sendTokenAmount,
|
|
254
|
+
network: ConnectionsController.state.activeNetwork
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
async fetchNetworkPrice() {
|
|
259
|
+
await SwapController.getNetworkTokenPrice();
|
|
224
260
|
},
|
|
225
261
|
|
|
226
|
-
|
|
262
|
+
resetState() {
|
|
227
263
|
state.token = undefined;
|
|
228
264
|
state.sendTokenAmount = undefined;
|
|
229
265
|
state.receiverAddress = undefined;
|
|
@@ -22,26 +22,52 @@ const state = proxy<SnackControllerState>({
|
|
|
22
22
|
long: false
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
// -- Private Variables --------------------------------- //
|
|
26
|
+
let hideTimeout: NodeJS.Timeout | null = null;
|
|
27
|
+
|
|
28
|
+
// -- Private Functions --------------------------------- //
|
|
29
|
+
const clearHideTimeout = () => {
|
|
30
|
+
if (hideTimeout) {
|
|
31
|
+
clearTimeout(hideTimeout);
|
|
32
|
+
hideTimeout = null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const scheduleAutoHide = (long: boolean) => {
|
|
37
|
+
clearHideTimeout();
|
|
38
|
+
|
|
39
|
+
const duration = long ? 15000 : 2200;
|
|
40
|
+
hideTimeout = setTimeout(() => {
|
|
41
|
+
SnackController.hide();
|
|
42
|
+
}, duration);
|
|
43
|
+
};
|
|
44
|
+
|
|
25
45
|
// -- Controller ---------------------------------------- //
|
|
26
46
|
export const SnackController = {
|
|
27
47
|
state,
|
|
28
48
|
|
|
29
|
-
showSuccess(message: SnackControllerState['message']) {
|
|
49
|
+
showSuccess(message: SnackControllerState['message'], long = false) {
|
|
30
50
|
state.message = message;
|
|
31
51
|
state.variant = 'success';
|
|
32
52
|
state.open = true;
|
|
53
|
+
state.long = long;
|
|
54
|
+
scheduleAutoHide(long);
|
|
33
55
|
},
|
|
34
56
|
|
|
35
|
-
showError(message: SnackControllerState['message']) {
|
|
57
|
+
showError(message: SnackControllerState['message'], long = false) {
|
|
36
58
|
state.message = message;
|
|
37
59
|
state.variant = 'error';
|
|
38
60
|
state.open = true;
|
|
61
|
+
state.long = long;
|
|
62
|
+
scheduleAutoHide(long);
|
|
39
63
|
},
|
|
40
64
|
|
|
41
|
-
showLoading(message: SnackControllerState['message']) {
|
|
65
|
+
showLoading(message: SnackControllerState['message'], long = false) {
|
|
42
66
|
state.message = message;
|
|
43
67
|
state.variant = 'loading';
|
|
44
68
|
state.open = true;
|
|
69
|
+
state.long = long;
|
|
70
|
+
scheduleAutoHide(long);
|
|
45
71
|
},
|
|
46
72
|
|
|
47
73
|
showInternalError(error: Message) {
|
|
@@ -52,6 +78,7 @@ export const SnackController = {
|
|
|
52
78
|
state.variant = 'error';
|
|
53
79
|
state.open = true;
|
|
54
80
|
state.long = true;
|
|
81
|
+
scheduleAutoHide(true);
|
|
55
82
|
}
|
|
56
83
|
|
|
57
84
|
if (error.longMessage) {
|
|
@@ -61,9 +88,8 @@ export const SnackController = {
|
|
|
61
88
|
},
|
|
62
89
|
|
|
63
90
|
hide() {
|
|
91
|
+
clearHideTimeout();
|
|
64
92
|
state.open = false;
|
|
65
93
|
state.long = false;
|
|
66
|
-
state.message = '';
|
|
67
|
-
state.variant = 'success';
|
|
68
94
|
}
|
|
69
95
|
};
|