@reown/appkit-core-react-native 0.0.0-accounts-canary.1-20251023174733
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 +410 -0
- package/lib/commonjs/controllers/ApiController.js.map +1 -0
- package/lib/commonjs/controllers/AssetController.js +30 -0
- package/lib/commonjs/controllers/AssetController.js.map +1 -0
- package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
- package/lib/commonjs/controllers/ConnectionsController.js +425 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +37 -0
- package/lib/commonjs/controllers/EnsController.js.map +1 -0
- package/lib/commonjs/controllers/EventsController.js +122 -0
- package/lib/commonjs/controllers/EventsController.js.map +1 -0
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +68 -0
- package/lib/commonjs/controllers/ModalController.js.map +1 -0
- package/lib/commonjs/controllers/OnRampController.js +502 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +96 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -0
- package/lib/commonjs/controllers/PublicStateController.js +33 -0
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
- package/lib/commonjs/controllers/RouterController.js +63 -0
- package/lib/commonjs/controllers/RouterController.js.map +1 -0
- package/lib/commonjs/controllers/SendController.js +192 -0
- package/lib/commonjs/controllers/SendController.js.map +1 -0
- package/lib/commonjs/controllers/SnackController.js +83 -0
- package/lib/commonjs/controllers/SnackController.js.map +1 -0
- package/lib/commonjs/controllers/SwapController.js +674 -0
- package/lib/commonjs/controllers/SwapController.js.map +1 -0
- package/lib/commonjs/controllers/ThemeController.js +45 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -0
- package/lib/commonjs/controllers/TransactionsController.js +118 -0
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
- 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 +202 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +43 -0
- package/lib/commonjs/utils/ApiUtil.js.map +1 -0
- package/lib/commonjs/utils/AssetUtil.js +27 -0
- package/lib/commonjs/utils/AssetUtil.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +226 -0
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
- package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
- package/lib/commonjs/utils/EventUtil.js +25 -0
- package/lib/commonjs/utils/EventUtil.js.map +1 -0
- package/lib/commonjs/utils/FetchUtil.js +158 -0
- package/lib/commonjs/utils/FetchUtil.js.map +1 -0
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +319 -0
- package/lib/commonjs/utils/StorageUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapApiUtil.js +75 -0
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +407 -0
- package/lib/module/controllers/ApiController.js.map +1 -0
- package/lib/module/controllers/AssetController.js +27 -0
- package/lib/module/controllers/AssetController.js.map +1 -0
- package/lib/module/controllers/BlockchainApiController.js +381 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -0
- package/lib/module/controllers/ConnectionsController.js +422 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +34 -0
- package/lib/module/controllers/EnsController.js.map +1 -0
- package/lib/module/controllers/EventsController.js +118 -0
- package/lib/module/controllers/EventsController.js.map +1 -0
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +65 -0
- package/lib/module/controllers/ModalController.js.map +1 -0
- package/lib/module/controllers/OnRampController.js +499 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +93 -0
- package/lib/module/controllers/OptionsController.js.map +1 -0
- package/lib/module/controllers/PublicStateController.js +30 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -0
- package/lib/module/controllers/RouterController.js +60 -0
- package/lib/module/controllers/RouterController.js.map +1 -0
- package/lib/module/controllers/SendController.js +189 -0
- package/lib/module/controllers/SendController.js.map +1 -0
- package/lib/module/controllers/SnackController.js +80 -0
- package/lib/module/controllers/SnackController.js.map +1 -0
- package/lib/module/controllers/SwapController.js +671 -0
- package/lib/module/controllers/SwapController.js.map +1 -0
- package/lib/module/controllers/ThemeController.js +42 -0
- package/lib/module/controllers/ThemeController.js.map +1 -0
- package/lib/module/controllers/TransactionsController.js +115 -0
- package/lib/module/controllers/TransactionsController.js.map +1 -0
- 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 +38 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/ApiUtil.js +39 -0
- package/lib/module/utils/ApiUtil.js.map +1 -0
- package/lib/module/utils/AssetUtil.js +23 -0
- package/lib/module/utils/AssetUtil.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +222 -0
- package/lib/module/utils/ConstantsUtil.js.map +1 -0
- package/lib/module/utils/CoreHelperUtil.js +294 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -0
- package/lib/module/utils/EventUtil.js +21 -0
- package/lib/module/utils/EventUtil.js.map +1 -0
- package/lib/module/utils/FetchUtil.js +154 -0
- package/lib/module/utils/FetchUtil.js.map +1 -0
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +315 -0
- package/lib/module/utils/StorageUtil.js.map +1 -0
- package/lib/module/utils/SwapApiUtil.js +71 -0
- package/lib/module/utils/SwapApiUtil.js.map +1 -0
- package/lib/module/utils/SwapCalculationUtil.js +94 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +40 -0
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/AssetController.d.ts +12 -0
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EnsController.d.ts +10 -0
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EventsController.d.ts +25 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
- 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 +17 -0
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
- package/lib/typescript/controllers/OnRampController.d.ts +55 -0
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
- package/lib/typescript/controllers/OptionsController.d.ts +46 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
- package/lib/typescript/controllers/RouterController.d.ts +21 -0
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
- package/lib/typescript/controllers/SendController.d.ts +39 -0
- package/lib/typescript/controllers/SendController.d.ts.map +1 -0
- package/lib/typescript/controllers/SnackController.d.ts +20 -0
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
- package/lib/typescript/controllers/SwapController.d.ts +116 -0
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
- package/lib/typescript/controllers/ThemeController.d.ts +14 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
- package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
- 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 +29 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/ApiUtil.d.ts +7 -0
- package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/AssetUtil.d.ts +6 -0
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
- package/lib/typescript/utils/EventUtil.d.ts +5 -0
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
- package/lib/typescript/utils/FetchUtil.d.ts +29 -0
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
- 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 +36 -0
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +57 -0
- package/readme.md +9 -0
- package/src/controllers/ApiController.ts +454 -0
- package/src/controllers/AssetController.ts +32 -0
- package/src/controllers/BlockchainApiController.ts +418 -0
- package/src/controllers/ConnectionsController.ts +575 -0
- package/src/controllers/EnsController.ts +41 -0
- package/src/controllers/EventsController.ts +146 -0
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +68 -0
- package/src/controllers/OnRampController.ts +698 -0
- package/src/controllers/OptionsController.ts +143 -0
- package/src/controllers/PublicStateController.ts +37 -0
- package/src/controllers/RouterController.ts +112 -0
- package/src/controllers/SendController.ts +270 -0
- package/src/controllers/SnackController.ts +95 -0
- package/src/controllers/SwapController.ts +863 -0
- package/src/controllers/ThemeController.ts +47 -0
- package/src/controllers/TransactionsController.ts +150 -0
- 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 +70 -0
- package/src/utils/ApiUtil.ts +50 -0
- package/src/utils/AssetUtil.ts +27 -0
- package/src/utils/ConstantsUtil.ts +303 -0
- package/src/utils/CoreHelperUtil.ts +377 -0
- package/src/utils/EventUtil.ts +22 -0
- package/src/utils/FetchUtil.ts +164 -0
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +405 -0
- package/src/utils/SwapApiUtil.ts +101 -0
- package/src/utils/SwapCalculationUtil.ts +145 -0
- package/src/utils/WalletUtil.ts +14 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Appearance } from 'react-native';
|
|
2
|
+
import { proxy, subscribe as sub } from 'valtio';
|
|
3
|
+
import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-native';
|
|
4
|
+
|
|
5
|
+
// -- Types --------------------------------------------- //
|
|
6
|
+
export interface ThemeControllerState {
|
|
7
|
+
themeMode?: ThemeMode;
|
|
8
|
+
defaultThemeMode?: ThemeMode;
|
|
9
|
+
themeVariables?: ThemeVariables;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// -- State --------------------------------------------- //
|
|
13
|
+
const state = proxy<ThemeControllerState>({
|
|
14
|
+
themeMode: undefined,
|
|
15
|
+
defaultThemeMode: undefined,
|
|
16
|
+
themeVariables: {}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// -- Controller ---------------------------------------- //
|
|
20
|
+
export const ThemeController = {
|
|
21
|
+
state,
|
|
22
|
+
|
|
23
|
+
subscribe(callback: (newState: ThemeControllerState) => void) {
|
|
24
|
+
return sub(state, () => callback(state));
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
setThemeMode(themeMode: ThemeControllerState['themeMode']) {
|
|
28
|
+
if (!themeMode) {
|
|
29
|
+
state.themeMode = Appearance.getColorScheme() as ThemeMode;
|
|
30
|
+
} else {
|
|
31
|
+
state.themeMode = themeMode;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
setDefaultThemeMode(themeMode: ThemeControllerState['defaultThemeMode']) {
|
|
36
|
+
state.defaultThemeMode = themeMode;
|
|
37
|
+
this.setThemeMode(themeMode);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
setThemeVariables(themeVariables: ThemeControllerState['themeVariables']) {
|
|
41
|
+
if (!themeVariables) {
|
|
42
|
+
state.themeVariables = {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
state.themeVariables = { ...state.themeVariables, ...themeVariables };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { CaipAddress, Transaction } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { proxy, subscribe as sub } from 'valtio';
|
|
3
|
+
import { OptionsController } from './OptionsController';
|
|
4
|
+
import { EventsController } from './EventsController';
|
|
5
|
+
import { SnackController } from './SnackController';
|
|
6
|
+
import { BlockchainApiController } from './BlockchainApiController';
|
|
7
|
+
import { ConnectionsController } from './ConnectionsController';
|
|
8
|
+
import { LogController } from './LogController';
|
|
9
|
+
|
|
10
|
+
// -- Types --------------------------------------------- //
|
|
11
|
+
type TransactionByMonthMap = Record<string, Transaction[]>;
|
|
12
|
+
type TransactionByYearMap = Record<string, TransactionByMonthMap>;
|
|
13
|
+
|
|
14
|
+
export interface TransactionsControllerState {
|
|
15
|
+
transactions: Transaction[];
|
|
16
|
+
loading: boolean;
|
|
17
|
+
empty: boolean;
|
|
18
|
+
next: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// -- State --------------------------------------------- //
|
|
22
|
+
const state = proxy<TransactionsControllerState>({
|
|
23
|
+
transactions: [],
|
|
24
|
+
loading: false,
|
|
25
|
+
empty: false,
|
|
26
|
+
next: undefined
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// -- Controller ---------------------------------------- //
|
|
30
|
+
export const TransactionsController = {
|
|
31
|
+
state,
|
|
32
|
+
|
|
33
|
+
subscribe(callback: (newState: TransactionsControllerState) => void) {
|
|
34
|
+
return sub(state, () => callback(state));
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
async fetchTransactions(accountAddress: CaipAddress, reset?: boolean) {
|
|
38
|
+
try {
|
|
39
|
+
const { projectId } = OptionsController.state;
|
|
40
|
+
|
|
41
|
+
if (!projectId || !accountAddress) {
|
|
42
|
+
throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
state.loading = true;
|
|
46
|
+
|
|
47
|
+
if (reset) {
|
|
48
|
+
state.next = undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const [namespace, chain, address] = accountAddress?.split(':') ?? [];
|
|
52
|
+
|
|
53
|
+
if (!namespace || !chain || !address) {
|
|
54
|
+
throw new Error('Invalid address');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const response = await BlockchainApiController.fetchTransactions({
|
|
58
|
+
account: address,
|
|
59
|
+
chainId: `${namespace}:${chain}`,
|
|
60
|
+
projectId,
|
|
61
|
+
cursor: state.next
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const nonSpamTransactions = this.filterSpamTransactions(response?.data ?? []);
|
|
65
|
+
let filteredTransactions = [...state.transactions, ...nonSpamTransactions];
|
|
66
|
+
|
|
67
|
+
if (reset) {
|
|
68
|
+
filteredTransactions = nonSpamTransactions;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
state.loading = false;
|
|
72
|
+
|
|
73
|
+
state.transactions = filteredTransactions;
|
|
74
|
+
|
|
75
|
+
state.empty = nonSpamTransactions.length === 0;
|
|
76
|
+
state.next = response?.next ? response.next : undefined;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
LogController.sendError(error, 'TransactionsController.ts', 'fetchTransactions');
|
|
79
|
+
EventsController.sendEvent({
|
|
80
|
+
type: 'track',
|
|
81
|
+
event: 'ERROR_FETCH_TRANSACTIONS',
|
|
82
|
+
properties: {
|
|
83
|
+
address: accountAddress ?? '',
|
|
84
|
+
projectId: OptionsController.state.projectId,
|
|
85
|
+
cursor: state.next,
|
|
86
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
SnackController.showError('Failed to fetch transactions');
|
|
90
|
+
state.loading = false;
|
|
91
|
+
state.empty = true;
|
|
92
|
+
state.next = undefined;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
getTransactionsByYearAndMonth(transactions: Transaction[]) {
|
|
97
|
+
const grouped: TransactionByYearMap = {};
|
|
98
|
+
let filteredTransactions = this.filterByConnectedChain(transactions);
|
|
99
|
+
|
|
100
|
+
filteredTransactions.forEach(transaction => {
|
|
101
|
+
const year = new Date(transaction.metadata.minedAt).getFullYear();
|
|
102
|
+
const month = new Date(transaction.metadata.minedAt).getMonth();
|
|
103
|
+
|
|
104
|
+
const yearTransactions = grouped[year] ?? {};
|
|
105
|
+
const monthTransactions = yearTransactions[month] ?? [];
|
|
106
|
+
|
|
107
|
+
// If there's a transaction with the same id, remove the old one
|
|
108
|
+
const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id);
|
|
109
|
+
|
|
110
|
+
grouped[year] = {
|
|
111
|
+
...yearTransactions,
|
|
112
|
+
[month]: [...newMonthTransactions, transaction].sort(
|
|
113
|
+
(a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime()
|
|
114
|
+
)
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return grouped;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
filterSpamTransactions(transactions: Transaction[]) {
|
|
122
|
+
return transactions.filter(transaction => {
|
|
123
|
+
const isAllSpam = transaction.transfers.every(
|
|
124
|
+
transfer => transfer.nft_info?.flags.is_spam === true
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return !isAllSpam;
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
filterByConnectedChain(transactions: Transaction[]) {
|
|
132
|
+
const chainId = ConnectionsController.state.activeCaipNetworkId;
|
|
133
|
+
const filteredTransactions = transactions.filter(
|
|
134
|
+
transaction => transaction.metadata.chain === chainId
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return filteredTransactions;
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
clearCursor() {
|
|
141
|
+
state.next = undefined;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
resetState() {
|
|
145
|
+
state.transactions = [];
|
|
146
|
+
state.loading = false;
|
|
147
|
+
state.empty = false;
|
|
148
|
+
state.next = undefined;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { proxy } from 'valtio';
|
|
2
|
+
import { subscribeKey as subKey } from 'valtio/utils';
|
|
3
|
+
import type { WalletDeepLink, WcWallet } from '@reown/appkit-common-react-native';
|
|
4
|
+
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
5
|
+
import { StorageUtil } from '../utils/StorageUtil';
|
|
6
|
+
|
|
7
|
+
// -- Types --------------------------------------------- //
|
|
8
|
+
export interface WcControllerState {
|
|
9
|
+
wcUri?: string;
|
|
10
|
+
wcPromise?: Promise<void>;
|
|
11
|
+
wcPairingExpiry?: number;
|
|
12
|
+
wcLinking?: WalletDeepLink;
|
|
13
|
+
wcError?: boolean;
|
|
14
|
+
pressedWallet?: WcWallet;
|
|
15
|
+
recentWallets?: WcWallet[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type StateKey = keyof WcControllerState;
|
|
19
|
+
|
|
20
|
+
// -- State --------------------------------------------- //
|
|
21
|
+
const state = proxy<WcControllerState>({
|
|
22
|
+
wcError: false
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// -- Controller ---------------------------------------- //
|
|
26
|
+
export const WcController = {
|
|
27
|
+
state,
|
|
28
|
+
|
|
29
|
+
subscribeKey<K extends StateKey>(key: K, callback: (value: WcControllerState[K]) => void) {
|
|
30
|
+
return subKey(state, key, callback);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
setWcLinking(wcLinking: WcControllerState['wcLinking']) {
|
|
34
|
+
state.wcLinking = wcLinking;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
removeWcLinking() {
|
|
38
|
+
state.wcLinking = undefined;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
setWcError(wcError: WcControllerState['wcError']) {
|
|
42
|
+
state.wcError = wcError;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
setPressedWallet(wallet: WcControllerState['pressedWallet']) {
|
|
46
|
+
state.pressedWallet = wallet;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
removePressedWallet() {
|
|
50
|
+
state.pressedWallet = undefined;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
setWcPromise(wcPromise: WcControllerState['wcPromise']) {
|
|
54
|
+
state.wcPromise = wcPromise;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
setWcUri(wcUri: WcControllerState['wcUri']) {
|
|
58
|
+
state.wcUri = wcUri;
|
|
59
|
+
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
setRecentWallets(wallets: WcControllerState['recentWallets']) {
|
|
63
|
+
state.recentWallets = wallets;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
async addRecentWallet(wallet: WcWallet) {
|
|
67
|
+
const recentWallets = await StorageUtil.addRecentWallet(wallet);
|
|
68
|
+
if (recentWallets) {
|
|
69
|
+
WcController.setRecentWallets(recentWallets);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
setConnectedWallet: async (wcLinking: WalletDeepLink, pressedWallet?: WcWallet) => {
|
|
74
|
+
StorageUtil.setWalletConnectDeepLink(wcLinking);
|
|
75
|
+
|
|
76
|
+
if (pressedWallet) {
|
|
77
|
+
WcController.addRecentWallet(pressedWallet);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
clearUri() {
|
|
82
|
+
state.wcUri = undefined;
|
|
83
|
+
state.wcPairingExpiry = undefined;
|
|
84
|
+
state.wcPromise = undefined;
|
|
85
|
+
state.wcLinking = undefined;
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
resetState() {
|
|
89
|
+
this.clearUri();
|
|
90
|
+
state.pressedWallet = undefined;
|
|
91
|
+
StorageUtil.removeWalletConnectDeepLink();
|
|
92
|
+
}
|
|
93
|
+
};
|