@reown/appkit-core-react-native 0.0.0-feat-onramp-20250722205908 → 0.0.0-feat-coinbase-20250723185200
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/AccountController.js +20 -17
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +28 -16
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +204 -74
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +8 -11
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +387 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +4 -4
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +4 -4
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +6 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +22 -69
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +17 -3
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +101 -101
- 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 +151 -150
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +9 -1
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +25 -21
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/index.js +3 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +3 -15
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +538 -9
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +12 -6
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +9 -28
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +90 -95
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +15 -21
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/AccountController.js +20 -17
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +27 -16
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +203 -73
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +8 -11
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +382 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +2 -2
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +1 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +6 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +23 -70
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +17 -3
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +98 -98
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +29 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +151 -150
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +9 -1
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +23 -19
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/index.js +1 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +3 -15
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +538 -9
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +12 -6
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +9 -28
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +92 -95
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +15 -21
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +4 -4
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts +3 -2
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -15
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +5 -16
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +53 -0
- package/lib/typescript/controllers/ConnectionsController.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/NetworkController.d.ts +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +1 -3
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +8 -2
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +4 -16
- 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 +12 -11
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +1 -1
- 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/index.d.ts +1 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +2 -3
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +422 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +5 -4
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +18 -14
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +42 -195
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/controllers/AccountController.ts +23 -27
- package/src/controllers/ApiController.ts +29 -10
- package/src/controllers/BlockchainApiController.ts +179 -65
- package/src/controllers/ConnectionController.ts +14 -29
- package/src/controllers/ConnectionsController.ts +509 -0
- package/src/controllers/EnsController.ts +2 -2
- package/src/controllers/EventsController.ts +1 -1
- package/src/controllers/ModalController.ts +8 -8
- package/src/controllers/NetworkController.ts +1 -1
- package/src/controllers/OnRampController.ts +35 -99
- package/src/controllers/OptionsController.ts +27 -13
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +5 -54
- package/src/controllers/SendController.ts +124 -113
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +174 -181
- package/src/controllers/ThemeController.ts +11 -2
- package/src/controllers/TransactionsController.ts +26 -20
- package/src/index.ts +3 -6
- package/src/utils/AssetUtil.ts +4 -20
- package/src/utils/ConstantsUtil.ts +544 -9
- package/src/utils/CoreHelperUtil.ts +35 -8
- package/src/utils/FetchUtil.ts +10 -31
- package/src/utils/StorageUtil.ts +167 -105
- package/src/utils/SwapApiUtil.ts +27 -38
- package/src/utils/TypeUtil.ts +43 -198
- package/lib/commonjs/controllers/ConnectorController.js +0 -49
- package/lib/commonjs/controllers/ConnectorController.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/ConnectionUtil.js +0 -33
- package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
- package/lib/commonjs/utils/NetworkUtil.js +0 -46
- package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
- package/lib/module/controllers/ConnectorController.js +0 -44
- package/lib/module/controllers/ConnectorController.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/ConnectionUtil.js +0 -27
- package/lib/module/utils/ConnectionUtil.js.map +0 -1
- package/lib/module/utils/NetworkUtil.js +0 -40
- package/lib/module/utils/NetworkUtil.js.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/WebviewController.d.ts +0 -21
- package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
- package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
- package/lib/typescript/utils/ConnectionUtil.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/src/controllers/ConnectorController.ts +0 -63
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/ConnectionUtil.ts +0 -27
- package/src/utils/NetworkUtil.ts +0 -33
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { proxy } from 'valtio';
|
|
2
2
|
import { subscribeKey as subKey } from 'valtio/utils';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AccountType, CaipAddress } from '@reown/appkit-common-react-native';
|
|
4
4
|
|
|
5
5
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
6
|
-
import type {
|
|
7
|
-
import { NetworkController } from './NetworkController';
|
|
8
|
-
import { BlockchainApiController } from './BlockchainApiController';
|
|
9
|
-
import { SnackController } from './SnackController';
|
|
6
|
+
import type { ConnectedWalletInfo, BlockchainApiBalance } from '../utils/TypeUtil';
|
|
7
|
+
// import { NetworkController } from './NetworkController';
|
|
8
|
+
// import { BlockchainApiController } from './BlockchainApiController';
|
|
9
|
+
// import { SnackController } from './SnackController';
|
|
10
10
|
|
|
11
11
|
// -- Types --------------------------------------------- //
|
|
12
12
|
export interface AccountControllerState {
|
|
@@ -15,12 +15,12 @@ export interface AccountControllerState {
|
|
|
15
15
|
address?: string;
|
|
16
16
|
balance?: string;
|
|
17
17
|
balanceSymbol?: string;
|
|
18
|
-
tokenBalance?:
|
|
18
|
+
tokenBalance?: BlockchainApiBalance[];
|
|
19
19
|
profileName?: string;
|
|
20
20
|
profileImage?: string;
|
|
21
21
|
addressExplorerUrl?: string;
|
|
22
22
|
connectedWalletInfo?: ConnectedWalletInfo;
|
|
23
|
-
preferredAccountType?:
|
|
23
|
+
preferredAccountType?: AccountType;
|
|
24
24
|
smartAccountDeployed?: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -89,26 +89,22 @@ export const AccountController = {
|
|
|
89
89
|
},
|
|
90
90
|
|
|
91
91
|
async fetchTokenBalance() {
|
|
92
|
-
const chainId = NetworkController.state.caipNetwork?.id;
|
|
93
|
-
const address = AccountController.state.address;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
SnackController.showError('Failed to fetch token balance');
|
|
111
|
-
}
|
|
92
|
+
// const chainId = NetworkController.state.caipNetwork?.id;
|
|
93
|
+
// const address = AccountController.state.address;
|
|
94
|
+
// try {
|
|
95
|
+
// if (address && chainId) {
|
|
96
|
+
// const response = await BlockchainApiController.getBalance(address, chainId);
|
|
97
|
+
// if (!response) {
|
|
98
|
+
// throw new Error('Failed to fetch token balance');
|
|
99
|
+
// }
|
|
100
|
+
// const filteredBalances = response.balances.filter(
|
|
101
|
+
// balance => balance.quantity.decimals !== '0'
|
|
102
|
+
// );
|
|
103
|
+
// this.setTokenBalance(filteredBalances);
|
|
104
|
+
// }
|
|
105
|
+
// } catch (error) {
|
|
106
|
+
// SnackController.showError('Failed to fetch token balance');
|
|
107
|
+
// }
|
|
112
108
|
},
|
|
113
109
|
|
|
114
110
|
resetAccount() {
|
|
@@ -12,12 +12,13 @@ import type {
|
|
|
12
12
|
WcWallet
|
|
13
13
|
} from '../utils/TypeUtil';
|
|
14
14
|
import { AssetController } from './AssetController';
|
|
15
|
-
import { NetworkController } from './NetworkController';
|
|
16
15
|
import { OptionsController } from './OptionsController';
|
|
17
|
-
import { ConnectorController } from './ConnectorController';
|
|
16
|
+
// import { ConnectorController } from './ConnectorController';
|
|
18
17
|
import { ConnectionController } from './ConnectionController';
|
|
19
18
|
import { ApiUtil } from '../utils/ApiUtil';
|
|
20
19
|
import { SnackController } from './SnackController';
|
|
20
|
+
import { ConnectionsController } from './ConnectionsController';
|
|
21
|
+
import { PresetsUtil } from '@reown/appkit-common-react-native';
|
|
21
22
|
|
|
22
23
|
// -- Helpers ------------------------------------------- //
|
|
23
24
|
const baseUrl = CoreHelperUtil.getApiUrl();
|
|
@@ -92,16 +93,22 @@ export const ApiController = {
|
|
|
92
93
|
}
|
|
93
94
|
},
|
|
94
95
|
|
|
95
|
-
async _fetchNetworkImage(
|
|
96
|
+
async _fetchNetworkImage(networkId: string) {
|
|
97
|
+
const imageId = PresetsUtil.NetworkImageIds[networkId];
|
|
98
|
+
if (!imageId) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
const headers = ApiController._getApiHeaders();
|
|
97
103
|
const url = await api.fetchImage(`/public/getAssetImage/${imageId}`, headers);
|
|
98
104
|
if (url) {
|
|
99
|
-
AssetController.setNetworkImage(
|
|
105
|
+
AssetController.setNetworkImage(networkId, url);
|
|
100
106
|
}
|
|
101
107
|
},
|
|
102
108
|
|
|
103
109
|
async fetchConnectorImages() {
|
|
104
|
-
|
|
110
|
+
//TODO: check this with coinbase
|
|
111
|
+
const connectors = [{ imageId: PresetsUtil.ConnectorImageIds['WALLET_CONNECT'] }];
|
|
105
112
|
const ids = connectors.map(({ imageId }) => imageId).filter(Boolean);
|
|
106
113
|
await CoreHelperUtil.allSettled(
|
|
107
114
|
(ids as string[]).map(id => ApiController._fetchConnectorImage(id))
|
|
@@ -109,11 +116,10 @@ export const ApiController = {
|
|
|
109
116
|
},
|
|
110
117
|
|
|
111
118
|
async fetchNetworkImages() {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
if (ids) {
|
|
119
|
+
const networks = ConnectionsController.state.networks;
|
|
120
|
+
if (networks) {
|
|
115
121
|
await CoreHelperUtil.allSettled(
|
|
116
|
-
|
|
122
|
+
networks.map(network => ApiController._fetchNetworkImage(network.id as string))
|
|
117
123
|
);
|
|
118
124
|
}
|
|
119
125
|
},
|
|
@@ -201,6 +207,18 @@ export const ApiController = {
|
|
|
201
207
|
}
|
|
202
208
|
},
|
|
203
209
|
|
|
210
|
+
async fetchCustomWalletImages() {
|
|
211
|
+
const { customWallets } = OptionsController.state;
|
|
212
|
+
if (!customWallets?.length) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const images = customWallets.map(w => w.image_id).filter(Boolean);
|
|
217
|
+
await CoreHelperUtil.allSettled(
|
|
218
|
+
(images as string[]).map(id => ApiController._fetchWalletImage(id))
|
|
219
|
+
);
|
|
220
|
+
},
|
|
221
|
+
|
|
204
222
|
async fetchRecommendedWallets() {
|
|
205
223
|
const { installed } = ApiController.state;
|
|
206
224
|
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
|
|
@@ -339,7 +357,8 @@ export const ApiController = {
|
|
|
339
357
|
ApiController.fetchFeaturedWallets(),
|
|
340
358
|
ApiController.fetchRecommendedWallets(),
|
|
341
359
|
ApiController.fetchNetworkImages(),
|
|
342
|
-
ApiController.fetchConnectorImages()
|
|
360
|
+
ApiController.fetchConnectorImages(),
|
|
361
|
+
ApiController.fetchCustomWalletImages()
|
|
343
362
|
];
|
|
344
363
|
if (OptionsController.state.enableAnalytics === undefined) {
|
|
345
364
|
promises.push(ApiController.fetchAnalyticsConfig());
|
|
@@ -32,12 +32,14 @@ import type {
|
|
|
32
32
|
OnRampQuote,
|
|
33
33
|
BlockchainApiOnRampWidgetRequest,
|
|
34
34
|
BlockchainApiOnRampQuotesRequest,
|
|
35
|
-
OnRampFiatLimit
|
|
36
|
-
OnRampCountryDefaults
|
|
35
|
+
OnRampFiatLimit
|
|
37
36
|
} from '../utils/TypeUtil';
|
|
38
37
|
import { OptionsController } from './OptionsController';
|
|
39
38
|
import { ConstantsUtil } from '../utils/ConstantsUtil';
|
|
40
39
|
import { ApiUtil } from '../utils/ApiUtil';
|
|
40
|
+
import type { CaipAddress, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
41
|
+
|
|
42
|
+
import { SnackController } from './SnackController';
|
|
41
43
|
|
|
42
44
|
// -- Helpers ------------------------------------------- //
|
|
43
45
|
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();
|
|
@@ -54,25 +56,59 @@ const getHeaders = () => {
|
|
|
54
56
|
};
|
|
55
57
|
};
|
|
56
58
|
|
|
57
|
-
export const EXCLUDED_ONRAMP_PROVIDERS = ['BINANCECONNECT', 'COINBASEPAY'];
|
|
58
|
-
|
|
59
59
|
// -- Types --------------------------------------------- //
|
|
60
|
+
type WithCaipNetworkId = { caipNetworkId: CaipNetworkId };
|
|
61
|
+
|
|
60
62
|
export interface BlockchainApiControllerState {
|
|
61
63
|
clientId: string | null;
|
|
62
64
|
api: FetchUtil;
|
|
65
|
+
supportedChains: { http: CaipNetworkId[]; ws: CaipNetworkId[] };
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
// -- State --------------------------------------------- //
|
|
66
69
|
const state = proxy<BlockchainApiControllerState>({
|
|
67
70
|
clientId: null,
|
|
68
|
-
api: new FetchUtil({ baseUrl })
|
|
71
|
+
api: new FetchUtil({ baseUrl }),
|
|
72
|
+
supportedChains: { http: [], ws: [] }
|
|
69
73
|
});
|
|
70
74
|
|
|
71
75
|
// -- Controller ---------------------------------------- //
|
|
72
76
|
export const BlockchainApiController = {
|
|
73
77
|
state,
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
async isNetworkSupported(networkId?: CaipNetworkId) {
|
|
80
|
+
if (!networkId) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
if (!state.supportedChains.http.length) {
|
|
85
|
+
await BlockchainApiController.getSupportedNetworks();
|
|
86
|
+
}
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return state.supportedChains.http.includes(networkId);
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async getSupportedNetworks() {
|
|
95
|
+
const supportedChains = await state.api.get<BlockchainApiControllerState['supportedChains']>({
|
|
96
|
+
path: 'v1/supported-chains'
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
state.supportedChains = supportedChains!;
|
|
100
|
+
|
|
101
|
+
return supportedChains;
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
async fetchIdentity(params: BlockchainApiIdentityRequest & WithCaipNetworkId) {
|
|
105
|
+
const { address, caipNetworkId } = params;
|
|
106
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(caipNetworkId);
|
|
107
|
+
|
|
108
|
+
if (!isSupported) {
|
|
109
|
+
return { avatar: '', name: '' };
|
|
110
|
+
}
|
|
111
|
+
|
|
76
112
|
return state.api.get<BlockchainApiIdentityResponse>({
|
|
77
113
|
path: `/v1/identity/${address}`,
|
|
78
114
|
params: {
|
|
@@ -82,29 +118,39 @@ export const BlockchainApiController = {
|
|
|
82
118
|
});
|
|
83
119
|
},
|
|
84
120
|
|
|
85
|
-
fetchTransactions({
|
|
86
|
-
account,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
121
|
+
async fetchTransactions(params: BlockchainApiTransactionsRequest) {
|
|
122
|
+
const { account, projectId, cursor, onramp, signal, cache, chainId } = params;
|
|
123
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
124
|
+
|
|
125
|
+
if (!isSupported) {
|
|
126
|
+
return { data: [], next: undefined };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const response = await state.api.get<BlockchainApiTransactionsResponse>({
|
|
94
130
|
path: `/v1/account/${account}/history`,
|
|
95
131
|
headers: getHeaders(),
|
|
96
132
|
params: {
|
|
97
133
|
projectId,
|
|
98
134
|
cursor,
|
|
99
|
-
onramp
|
|
135
|
+
onramp,
|
|
136
|
+
chainId
|
|
100
137
|
},
|
|
101
138
|
signal,
|
|
102
139
|
cache
|
|
103
140
|
});
|
|
141
|
+
|
|
142
|
+
return response;
|
|
104
143
|
},
|
|
105
144
|
|
|
106
|
-
fetchTokenPrice(
|
|
107
|
-
|
|
145
|
+
async fetchTokenPrice(params: BlockchainApiTokenPriceRequest & WithCaipNetworkId) {
|
|
146
|
+
const { projectId, addresses, caipNetworkId } = params;
|
|
147
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(caipNetworkId);
|
|
148
|
+
|
|
149
|
+
if (!isSupported) {
|
|
150
|
+
return { fungibles: [] };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const response = await state.api.post<BlockchainApiTokenPriceResponse>({
|
|
108
154
|
path: '/v1/fungible/price',
|
|
109
155
|
body: {
|
|
110
156
|
projectId,
|
|
@@ -113,9 +159,20 @@ export const BlockchainApiController = {
|
|
|
113
159
|
},
|
|
114
160
|
headers: getHeaders()
|
|
115
161
|
});
|
|
162
|
+
|
|
163
|
+
return response;
|
|
116
164
|
},
|
|
117
165
|
|
|
118
|
-
fetchSwapAllowance(
|
|
166
|
+
async fetchSwapAllowance(params: BlockchainApiSwapAllowanceRequest) {
|
|
167
|
+
const { projectId, tokenAddress, userAddress } = params;
|
|
168
|
+
const [namespace, chain] = userAddress.split(':');
|
|
169
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
170
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
171
|
+
|
|
172
|
+
if (!isSupported) {
|
|
173
|
+
return { allowance: '0' };
|
|
174
|
+
}
|
|
175
|
+
|
|
119
176
|
return state.api.get<BlockchainApiSwapAllowanceResponse>({
|
|
120
177
|
path: `/v1/convert/allowance`,
|
|
121
178
|
params: {
|
|
@@ -127,7 +184,14 @@ export const BlockchainApiController = {
|
|
|
127
184
|
});
|
|
128
185
|
},
|
|
129
186
|
|
|
130
|
-
fetchGasPrice(
|
|
187
|
+
async fetchGasPrice(params: BlockchainApiGasPriceRequest) {
|
|
188
|
+
const { projectId, chainId } = params;
|
|
189
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
190
|
+
|
|
191
|
+
if (!isSupported) {
|
|
192
|
+
throw new Error('Network not supported for Gas Price');
|
|
193
|
+
}
|
|
194
|
+
|
|
131
195
|
return state.api.get<BlockchainApiGasPriceResponse>({
|
|
132
196
|
path: `/v1/convert/gas-price`,
|
|
133
197
|
headers: getHeaders(),
|
|
@@ -138,14 +202,16 @@ export const BlockchainApiController = {
|
|
|
138
202
|
});
|
|
139
203
|
},
|
|
140
204
|
|
|
141
|
-
fetchSwapQuote({
|
|
142
|
-
projectId,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
205
|
+
async fetchSwapQuote(params: BlockchainApiSwapQuoteRequest) {
|
|
206
|
+
const { projectId, amount, userAddress, from, to, gasPrice } = params;
|
|
207
|
+
const [namespace, chain] = userAddress.split(':');
|
|
208
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
209
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
210
|
+
|
|
211
|
+
if (!isSupported) {
|
|
212
|
+
return { quotes: [] };
|
|
213
|
+
}
|
|
214
|
+
|
|
149
215
|
return state.api.get<BlockchainApiSwapQuoteResponse>({
|
|
150
216
|
path: `/v1/convert/quotes`,
|
|
151
217
|
headers: getHeaders(),
|
|
@@ -160,7 +226,14 @@ export const BlockchainApiController = {
|
|
|
160
226
|
});
|
|
161
227
|
},
|
|
162
228
|
|
|
163
|
-
fetchSwapTokens(
|
|
229
|
+
async fetchSwapTokens(params: BlockchainApiSwapTokensRequest) {
|
|
230
|
+
const { projectId, chainId } = params;
|
|
231
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
232
|
+
|
|
233
|
+
if (!isSupported) {
|
|
234
|
+
return { tokens: [] };
|
|
235
|
+
}
|
|
236
|
+
|
|
164
237
|
return state.api.get<BlockchainApiSwapTokensResponse>({
|
|
165
238
|
path: `/v1/convert/tokens`,
|
|
166
239
|
headers: getHeaders(),
|
|
@@ -171,13 +244,16 @@ export const BlockchainApiController = {
|
|
|
171
244
|
});
|
|
172
245
|
},
|
|
173
246
|
|
|
174
|
-
generateSwapCalldata({
|
|
175
|
-
amount,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
247
|
+
async generateSwapCalldata(params: BlockchainApiGenerateSwapCalldataRequest) {
|
|
248
|
+
const { amount, from, projectId, to, userAddress } = params;
|
|
249
|
+
const [namespace, chain] = userAddress.split(':');
|
|
250
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
251
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
252
|
+
|
|
253
|
+
if (!isSupported) {
|
|
254
|
+
throw new Error('Network not supported for Swaps');
|
|
255
|
+
}
|
|
256
|
+
|
|
181
257
|
return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
|
|
182
258
|
path: '/v1/convert/build-transaction',
|
|
183
259
|
headers: getHeaders(),
|
|
@@ -194,12 +270,16 @@ export const BlockchainApiController = {
|
|
|
194
270
|
});
|
|
195
271
|
},
|
|
196
272
|
|
|
197
|
-
generateApproveCalldata({
|
|
198
|
-
from,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
273
|
+
async generateApproveCalldata(params: BlockchainApiGenerateApproveCalldataRequest) {
|
|
274
|
+
const { from, projectId, to, userAddress } = params;
|
|
275
|
+
const [namespace, chain] = userAddress.split(':');
|
|
276
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
277
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
278
|
+
|
|
279
|
+
if (!isSupported) {
|
|
280
|
+
throw new Error('Network not supported for Swaps');
|
|
281
|
+
}
|
|
282
|
+
|
|
203
283
|
return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
|
|
204
284
|
path: `/v1/convert/build-approve`,
|
|
205
285
|
headers: getHeaders(),
|
|
@@ -212,15 +292,29 @@ export const BlockchainApiController = {
|
|
|
212
292
|
});
|
|
213
293
|
},
|
|
214
294
|
|
|
215
|
-
async getBalance(address
|
|
295
|
+
async getBalance(address?: CaipAddress, forceUpdate?: CaipAddress[]) {
|
|
296
|
+
const [namespace, chain, plainAddress] = address?.split(':') ?? [];
|
|
297
|
+
|
|
298
|
+
if (!namespace || !chain || !plainAddress) {
|
|
299
|
+
throw new Error('Invalid address');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(`${namespace}:${chain}`);
|
|
303
|
+
|
|
304
|
+
if (!isSupported) {
|
|
305
|
+
SnackController.showError('Token Balance Unavailable');
|
|
306
|
+
|
|
307
|
+
return { balances: [] };
|
|
308
|
+
}
|
|
309
|
+
|
|
216
310
|
return state.api.get<BlockchainApiBalanceResponse>({
|
|
217
|
-
path: `/v1/account/${
|
|
311
|
+
path: `/v1/account/${plainAddress}/balance`,
|
|
218
312
|
headers: getHeaders(),
|
|
219
313
|
params: {
|
|
220
314
|
currency: 'usd',
|
|
221
315
|
projectId: OptionsController.state.projectId,
|
|
222
|
-
chainId
|
|
223
|
-
forceUpdate
|
|
316
|
+
chainId: `${namespace}:${chain}`,
|
|
317
|
+
forceUpdate: forceUpdate?.join(',')
|
|
224
318
|
}
|
|
225
319
|
});
|
|
226
320
|
},
|
|
@@ -236,6 +330,17 @@ export const BlockchainApiController = {
|
|
|
236
330
|
});
|
|
237
331
|
},
|
|
238
332
|
|
|
333
|
+
async fetchOnRampCountries() {
|
|
334
|
+
return await state.api.get<OnRampCountry[]>({
|
|
335
|
+
path: '/v1/onramp/providers/properties',
|
|
336
|
+
headers: getHeaders(),
|
|
337
|
+
params: {
|
|
338
|
+
projectId: OptionsController.state.projectId,
|
|
339
|
+
type: 'countries'
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
|
|
239
344
|
async fetchOnRampServiceProviders() {
|
|
240
345
|
return await state.api.get<OnRampServiceProvider[]>({
|
|
241
346
|
path: '/v1/onramp/providers',
|
|
@@ -246,39 +351,48 @@ export const BlockchainApiController = {
|
|
|
246
351
|
});
|
|
247
352
|
},
|
|
248
353
|
|
|
249
|
-
async fetchOnRampCountries() {
|
|
250
|
-
return await this.fetchProperties<OnRampCountry[]>('countries');
|
|
251
|
-
},
|
|
252
|
-
|
|
253
354
|
async fetchOnRampPaymentMethods(params: { countries?: string }) {
|
|
254
|
-
return await
|
|
355
|
+
return await state.api.get<OnRampPaymentMethod[]>({
|
|
356
|
+
path: '/v1/onramp/providers/properties',
|
|
357
|
+
headers: getHeaders(),
|
|
358
|
+
params: {
|
|
359
|
+
projectId: OptionsController.state.projectId,
|
|
360
|
+
type: 'payment-methods',
|
|
361
|
+
...params
|
|
362
|
+
}
|
|
363
|
+
});
|
|
255
364
|
},
|
|
256
365
|
|
|
257
366
|
async fetchOnRampCryptoCurrencies(params: { countries?: string }) {
|
|
258
|
-
return await
|
|
367
|
+
return await state.api.get<OnRampCryptoCurrency[]>({
|
|
368
|
+
path: '/v1/onramp/providers/properties',
|
|
369
|
+
headers: getHeaders(),
|
|
370
|
+
params: {
|
|
371
|
+
projectId: OptionsController.state.projectId,
|
|
372
|
+
type: 'crypto-currencies',
|
|
373
|
+
...params
|
|
374
|
+
}
|
|
375
|
+
});
|
|
259
376
|
},
|
|
260
377
|
|
|
261
378
|
async fetchOnRampFiatCurrencies() {
|
|
262
|
-
return await
|
|
379
|
+
return await state.api.get<OnRampFiatCurrency[]>({
|
|
380
|
+
path: '/v1/onramp/providers/properties',
|
|
381
|
+
headers: getHeaders(),
|
|
382
|
+
params: {
|
|
383
|
+
projectId: OptionsController.state.projectId,
|
|
384
|
+
type: 'fiat-currencies'
|
|
385
|
+
}
|
|
386
|
+
});
|
|
263
387
|
},
|
|
264
388
|
|
|
265
389
|
async fetchOnRampFiatLimits() {
|
|
266
|
-
return await
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
async fetchOnRampCountriesDefaults() {
|
|
270
|
-
return await this.fetchProperties<OnRampCountryDefaults[]>('countries-defaults');
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
async fetchProperties<T>(type: string, params?: Record<string, string>) {
|
|
274
|
-
return await state.api.get<T>({
|
|
390
|
+
return await state.api.get<OnRampFiatLimit[]>({
|
|
275
391
|
path: '/v1/onramp/providers/properties',
|
|
276
392
|
headers: getHeaders(),
|
|
277
393
|
params: {
|
|
278
394
|
projectId: OptionsController.state.projectId,
|
|
279
|
-
type
|
|
280
|
-
excludeProviders: EXCLUDED_ONRAMP_PROVIDERS.join(','),
|
|
281
|
-
...params
|
|
395
|
+
type: 'fiat-purchases-limits'
|
|
282
396
|
}
|
|
283
397
|
});
|
|
284
398
|
},
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import { proxy, ref } from 'valtio';
|
|
2
2
|
import { subscribeKey as subKey } from 'valtio/utils';
|
|
3
|
-
import type { SocialProvider } from '@reown/appkit-common-react-native';
|
|
3
|
+
import type { SocialProvider, WalletDeepLink } from '@reown/appkit-common-react-native';
|
|
4
4
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
5
5
|
import { StorageUtil } from '../utils/StorageUtil';
|
|
6
6
|
import type {
|
|
7
|
-
Connector,
|
|
8
7
|
EstimateGasTransactionArgs,
|
|
9
8
|
SendTransactionArgs,
|
|
10
9
|
WcWallet,
|
|
11
10
|
WriteContractArgs
|
|
12
11
|
} from '../utils/TypeUtil';
|
|
13
|
-
import { ConnectorController } from './ConnectorController';
|
|
14
12
|
|
|
15
13
|
// -- Types --------------------------------------------- //
|
|
16
|
-
export interface ConnectExternalOptions {
|
|
17
|
-
id: Connector['id'];
|
|
18
|
-
type: Connector['type'];
|
|
19
|
-
provider?: Connector['provider'];
|
|
20
|
-
info?: Connector['info'];
|
|
21
|
-
}
|
|
22
14
|
|
|
23
15
|
export interface ConnectionControllerClient {
|
|
24
16
|
connectWalletConnect: (
|
|
25
17
|
onUri: (uri: string) => void,
|
|
26
18
|
walletUniversalLink?: string
|
|
27
19
|
) => Promise<void>;
|
|
28
|
-
connectExternal?: (options: ConnectExternalOptions) => Promise<void>;
|
|
29
20
|
signMessage: (message: string) => Promise<string>;
|
|
30
21
|
sendTransaction: (args: SendTransactionArgs) => Promise<`0x${string}` | null>;
|
|
31
22
|
parseUnits: (value: string, decimals: number) => bigint;
|
|
@@ -42,16 +33,12 @@ export interface ConnectionControllerState {
|
|
|
42
33
|
wcUri?: string;
|
|
43
34
|
wcPromise?: Promise<void>;
|
|
44
35
|
wcPairingExpiry?: number;
|
|
45
|
-
wcLinking?:
|
|
46
|
-
href: string;
|
|
47
|
-
name: string;
|
|
48
|
-
};
|
|
36
|
+
wcLinking?: WalletDeepLink;
|
|
49
37
|
wcError?: boolean;
|
|
50
38
|
pressedWallet?: WcWallet;
|
|
51
39
|
recentWallets?: WcWallet[];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
connectedSocialProvider?: SocialProvider;
|
|
40
|
+
connectedWalletImageUrl?: string; //TODO: remove this
|
|
41
|
+
connectedSocialProvider?: SocialProvider; // TODO: remove this
|
|
55
42
|
}
|
|
56
43
|
|
|
57
44
|
type StateKey = keyof ConnectionControllerState;
|
|
@@ -91,11 +78,6 @@ export const ConnectionController = {
|
|
|
91
78
|
}, walletUniversalLink);
|
|
92
79
|
},
|
|
93
80
|
|
|
94
|
-
async connectExternal(options: ConnectExternalOptions) {
|
|
95
|
-
await this._getClient().connectExternal?.(options);
|
|
96
|
-
ConnectorController.setConnectedConnector(options.type);
|
|
97
|
-
},
|
|
98
|
-
|
|
99
81
|
async signMessage(message: string) {
|
|
100
82
|
return this._getClient().signMessage(message);
|
|
101
83
|
},
|
|
@@ -120,12 +102,17 @@ export const ConnectionController = {
|
|
|
120
102
|
state.pressedWallet = undefined;
|
|
121
103
|
},
|
|
122
104
|
|
|
123
|
-
|
|
124
|
-
state.
|
|
105
|
+
setWcPromise(wcPromise: ConnectionControllerState['wcPromise']) {
|
|
106
|
+
state.wcPromise = wcPromise;
|
|
125
107
|
},
|
|
126
108
|
|
|
127
|
-
|
|
128
|
-
state.
|
|
109
|
+
setWcUri(wcUri: ConnectionControllerState['wcUri']) {
|
|
110
|
+
state.wcUri = wcUri;
|
|
111
|
+
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
setRecentWallets(wallets: ConnectionControllerState['recentWallets']) {
|
|
115
|
+
state.recentWallets = wallets;
|
|
129
116
|
},
|
|
130
117
|
|
|
131
118
|
async setConnectedWalletImageUrl(url: ConnectionControllerState['connectedWalletImageUrl']) {
|
|
@@ -185,14 +172,12 @@ export const ConnectionController = {
|
|
|
185
172
|
resetWcConnection() {
|
|
186
173
|
this.clearUri();
|
|
187
174
|
state.pressedWallet = undefined;
|
|
188
|
-
state.selectedSocialProvider = undefined;
|
|
189
175
|
ConnectionController.setConnectedWalletImageUrl(undefined);
|
|
190
|
-
ConnectorController.setConnectedConnector(undefined);
|
|
176
|
+
// ConnectorController.setConnectedConnector(undefined);
|
|
191
177
|
StorageUtil.removeWalletConnectDeepLink();
|
|
192
178
|
},
|
|
193
179
|
|
|
194
180
|
async disconnect() {
|
|
195
|
-
await this._getClient().disconnect();
|
|
196
181
|
this.resetWcConnection();
|
|
197
182
|
// remove transactions
|
|
198
183
|
// RouterController.reset('Connect');
|