@reown/appkit-core-react-native 0.0.0-feat-coinbase-20250722202925 → 0.0.0-feat-onramp-20250722205908
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 +17 -20
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +16 -28
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +74 -204
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +11 -8
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectorController.js +49 -0
- package/lib/commonjs/controllers/ConnectorController.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 +7 -6
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +69 -22
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +3 -11
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +22 -1
- 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 +5 -29
- package/lib/commonjs/controllers/SnackController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +150 -151
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +1 -9
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +21 -25
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/controllers/WebviewController.js +52 -0
- package/lib/commonjs/controllers/WebviewController.js.map +1 -0
- package/lib/commonjs/index.js +24 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +15 -3
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConnectionUtil.js +33 -0
- package/lib/commonjs/utils/ConnectionUtil.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +9 -538
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +6 -12
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +28 -9
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/NetworkUtil.js +46 -0
- package/lib/commonjs/utils/NetworkUtil.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +42 -51
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +21 -15
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/AccountController.js +17 -20
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +16 -27
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +73 -203
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +11 -8
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/ConnectorController.js +44 -0
- package/lib/module/controllers/ConnectorController.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 +7 -6
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +70 -23
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +3 -11
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +22 -1
- 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 +5 -29
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +150 -151
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +1 -9
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +19 -23
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/controllers/WebviewController.js +47 -0
- package/lib/module/controllers/WebviewController.js.map +1 -0
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +15 -3
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConnectionUtil.js +27 -0
- package/lib/module/utils/ConnectionUtil.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +9 -538
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +6 -12
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +28 -9
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/NetworkUtil.js +40 -0
- package/lib/module/utils/NetworkUtil.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +42 -51
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +21 -15
- 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 +2 -3
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +15 -29
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +11 -3
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +18 -0
- package/lib/typescript/controllers/ConnectorController.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 +3 -1
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +2 -7
- 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 +16 -4
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts +7 -5
- 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 -12
- 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/controllers/WebviewController.d.ts +21 -0
- package/lib/typescript/controllers/WebviewController.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +3 -2
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConnectionUtil.d.ts +4 -0
- package/lib/typescript/utils/ConnectionUtil.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +3 -422
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +4 -5
- 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/NetworkUtil.d.ts +8 -0
- package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +7 -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 +191 -42
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/controllers/AccountController.ts +27 -23
- package/src/controllers/ApiController.ts +10 -29
- package/src/controllers/BlockchainApiController.ts +65 -179
- package/src/controllers/ConnectionController.ts +24 -12
- package/src/controllers/ConnectorController.ts +63 -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 +99 -35
- package/src/controllers/OptionsController.ts +13 -19
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +54 -5
- package/src/controllers/SendController.ts +113 -124
- package/src/controllers/SnackController.ts +5 -31
- package/src/controllers/SwapController.ts +181 -174
- package/src/controllers/ThemeController.ts +2 -11
- package/src/controllers/TransactionsController.ts +20 -26
- package/src/controllers/WebviewController.ts +63 -0
- package/src/index.ts +6 -3
- package/src/utils/AssetUtil.ts +20 -4
- package/src/utils/ConnectionUtil.ts +27 -0
- package/src/utils/ConstantsUtil.ts +9 -544
- package/src/utils/CoreHelperUtil.ts +9 -34
- package/src/utils/FetchUtil.ts +31 -10
- package/src/utils/NetworkUtil.ts +33 -0
- package/src/utils/StorageUtil.ts +48 -60
- package/src/utils/SwapApiUtil.ts +38 -27
- package/src/utils/TypeUtil.ts +193 -43
- package/lib/commonjs/controllers/ConnectionsController.js +0 -387
- package/lib/commonjs/controllers/ConnectionsController.js.map +0 -1
- package/lib/module/controllers/ConnectionsController.js +0 -382
- package/lib/module/controllers/ConnectionsController.js.map +0 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +0 -53
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +0 -1
- package/src/controllers/ConnectionsController.ts +0 -509
|
@@ -32,14 +32,12 @@ import type {
|
|
|
32
32
|
OnRampQuote,
|
|
33
33
|
BlockchainApiOnRampWidgetRequest,
|
|
34
34
|
BlockchainApiOnRampQuotesRequest,
|
|
35
|
-
OnRampFiatLimit
|
|
35
|
+
OnRampFiatLimit,
|
|
36
|
+
OnRampCountryDefaults
|
|
36
37
|
} from '../utils/TypeUtil';
|
|
37
38
|
import { OptionsController } from './OptionsController';
|
|
38
39
|
import { ConstantsUtil } from '../utils/ConstantsUtil';
|
|
39
40
|
import { ApiUtil } from '../utils/ApiUtil';
|
|
40
|
-
import type { CaipAddress, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
41
|
-
|
|
42
|
-
import { SnackController } from './SnackController';
|
|
43
41
|
|
|
44
42
|
// -- Helpers ------------------------------------------- //
|
|
45
43
|
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();
|
|
@@ -56,59 +54,25 @@ const getHeaders = () => {
|
|
|
56
54
|
};
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
type WithCaipNetworkId = { caipNetworkId: CaipNetworkId };
|
|
57
|
+
export const EXCLUDED_ONRAMP_PROVIDERS = ['BINANCECONNECT', 'COINBASEPAY'];
|
|
61
58
|
|
|
59
|
+
// -- Types --------------------------------------------- //
|
|
62
60
|
export interface BlockchainApiControllerState {
|
|
63
61
|
clientId: string | null;
|
|
64
62
|
api: FetchUtil;
|
|
65
|
-
supportedChains: { http: CaipNetworkId[]; ws: CaipNetworkId[] };
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
// -- State --------------------------------------------- //
|
|
69
66
|
const state = proxy<BlockchainApiControllerState>({
|
|
70
67
|
clientId: null,
|
|
71
|
-
api: new FetchUtil({ baseUrl })
|
|
72
|
-
supportedChains: { http: [], ws: [] }
|
|
68
|
+
api: new FetchUtil({ baseUrl })
|
|
73
69
|
});
|
|
74
70
|
|
|
75
71
|
// -- Controller ---------------------------------------- //
|
|
76
72
|
export const BlockchainApiController = {
|
|
77
73
|
state,
|
|
78
74
|
|
|
79
|
-
|
|
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
|
-
|
|
75
|
+
fetchIdentity({ address }: BlockchainApiIdentityRequest) {
|
|
112
76
|
return state.api.get<BlockchainApiIdentityResponse>({
|
|
113
77
|
path: `/v1/identity/${address}`,
|
|
114
78
|
params: {
|
|
@@ -118,39 +82,29 @@ export const BlockchainApiController = {
|
|
|
118
82
|
});
|
|
119
83
|
},
|
|
120
84
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
85
|
+
fetchTransactions({
|
|
86
|
+
account,
|
|
87
|
+
projectId,
|
|
88
|
+
cursor,
|
|
89
|
+
onramp,
|
|
90
|
+
signal,
|
|
91
|
+
cache
|
|
92
|
+
}: BlockchainApiTransactionsRequest) {
|
|
93
|
+
return state.api.get<BlockchainApiTransactionsResponse>({
|
|
130
94
|
path: `/v1/account/${account}/history`,
|
|
131
95
|
headers: getHeaders(),
|
|
132
96
|
params: {
|
|
133
97
|
projectId,
|
|
134
98
|
cursor,
|
|
135
|
-
onramp
|
|
136
|
-
chainId
|
|
99
|
+
onramp
|
|
137
100
|
},
|
|
138
101
|
signal,
|
|
139
102
|
cache
|
|
140
103
|
});
|
|
141
|
-
|
|
142
|
-
return response;
|
|
143
104
|
},
|
|
144
105
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const isSupported = await BlockchainApiController.isNetworkSupported(caipNetworkId);
|
|
148
|
-
|
|
149
|
-
if (!isSupported) {
|
|
150
|
-
return { fungibles: [] };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const response = await state.api.post<BlockchainApiTokenPriceResponse>({
|
|
106
|
+
fetchTokenPrice({ projectId, addresses }: BlockchainApiTokenPriceRequest) {
|
|
107
|
+
return state.api.post<BlockchainApiTokenPriceResponse>({
|
|
154
108
|
path: '/v1/fungible/price',
|
|
155
109
|
body: {
|
|
156
110
|
projectId,
|
|
@@ -159,20 +113,9 @@ export const BlockchainApiController = {
|
|
|
159
113
|
},
|
|
160
114
|
headers: getHeaders()
|
|
161
115
|
});
|
|
162
|
-
|
|
163
|
-
return response;
|
|
164
116
|
},
|
|
165
117
|
|
|
166
|
-
|
|
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
|
-
|
|
118
|
+
fetchSwapAllowance({ projectId, tokenAddress, userAddress }: BlockchainApiSwapAllowanceRequest) {
|
|
176
119
|
return state.api.get<BlockchainApiSwapAllowanceResponse>({
|
|
177
120
|
path: `/v1/convert/allowance`,
|
|
178
121
|
params: {
|
|
@@ -184,14 +127,7 @@ export const BlockchainApiController = {
|
|
|
184
127
|
});
|
|
185
128
|
},
|
|
186
129
|
|
|
187
|
-
|
|
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
|
-
|
|
130
|
+
fetchGasPrice({ projectId, chainId }: BlockchainApiGasPriceRequest) {
|
|
195
131
|
return state.api.get<BlockchainApiGasPriceResponse>({
|
|
196
132
|
path: `/v1/convert/gas-price`,
|
|
197
133
|
headers: getHeaders(),
|
|
@@ -202,16 +138,14 @@ export const BlockchainApiController = {
|
|
|
202
138
|
});
|
|
203
139
|
},
|
|
204
140
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
141
|
+
fetchSwapQuote({
|
|
142
|
+
projectId,
|
|
143
|
+
amount,
|
|
144
|
+
userAddress,
|
|
145
|
+
from,
|
|
146
|
+
to,
|
|
147
|
+
gasPrice
|
|
148
|
+
}: BlockchainApiSwapQuoteRequest) {
|
|
215
149
|
return state.api.get<BlockchainApiSwapQuoteResponse>({
|
|
216
150
|
path: `/v1/convert/quotes`,
|
|
217
151
|
headers: getHeaders(),
|
|
@@ -226,14 +160,7 @@ export const BlockchainApiController = {
|
|
|
226
160
|
});
|
|
227
161
|
},
|
|
228
162
|
|
|
229
|
-
|
|
230
|
-
const { projectId, chainId } = params;
|
|
231
|
-
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
232
|
-
|
|
233
|
-
if (!isSupported) {
|
|
234
|
-
return { tokens: [] };
|
|
235
|
-
}
|
|
236
|
-
|
|
163
|
+
fetchSwapTokens({ projectId, chainId }: BlockchainApiSwapTokensRequest) {
|
|
237
164
|
return state.api.get<BlockchainApiSwapTokensResponse>({
|
|
238
165
|
path: `/v1/convert/tokens`,
|
|
239
166
|
headers: getHeaders(),
|
|
@@ -244,16 +171,13 @@ export const BlockchainApiController = {
|
|
|
244
171
|
});
|
|
245
172
|
},
|
|
246
173
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
throw new Error('Network not supported for Swaps');
|
|
255
|
-
}
|
|
256
|
-
|
|
174
|
+
generateSwapCalldata({
|
|
175
|
+
amount,
|
|
176
|
+
from,
|
|
177
|
+
projectId,
|
|
178
|
+
to,
|
|
179
|
+
userAddress
|
|
180
|
+
}: BlockchainApiGenerateSwapCalldataRequest) {
|
|
257
181
|
return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
|
|
258
182
|
path: '/v1/convert/build-transaction',
|
|
259
183
|
headers: getHeaders(),
|
|
@@ -270,16 +194,12 @@ export const BlockchainApiController = {
|
|
|
270
194
|
});
|
|
271
195
|
},
|
|
272
196
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (!isSupported) {
|
|
280
|
-
throw new Error('Network not supported for Swaps');
|
|
281
|
-
}
|
|
282
|
-
|
|
197
|
+
generateApproveCalldata({
|
|
198
|
+
from,
|
|
199
|
+
projectId,
|
|
200
|
+
to,
|
|
201
|
+
userAddress
|
|
202
|
+
}: BlockchainApiGenerateApproveCalldataRequest) {
|
|
283
203
|
return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
|
|
284
204
|
path: `/v1/convert/build-approve`,
|
|
285
205
|
headers: getHeaders(),
|
|
@@ -292,29 +212,15 @@ export const BlockchainApiController = {
|
|
|
292
212
|
});
|
|
293
213
|
},
|
|
294
214
|
|
|
295
|
-
async getBalance(address?:
|
|
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
|
-
|
|
215
|
+
async getBalance(address: string, chainId?: string, forceUpdate?: string) {
|
|
310
216
|
return state.api.get<BlockchainApiBalanceResponse>({
|
|
311
|
-
path: `/v1/account/${
|
|
217
|
+
path: `/v1/account/${address}/balance`,
|
|
312
218
|
headers: getHeaders(),
|
|
313
219
|
params: {
|
|
314
220
|
currency: 'usd',
|
|
315
221
|
projectId: OptionsController.state.projectId,
|
|
316
|
-
chainId
|
|
317
|
-
forceUpdate
|
|
222
|
+
chainId,
|
|
223
|
+
forceUpdate
|
|
318
224
|
}
|
|
319
225
|
});
|
|
320
226
|
},
|
|
@@ -330,17 +236,6 @@ export const BlockchainApiController = {
|
|
|
330
236
|
});
|
|
331
237
|
},
|
|
332
238
|
|
|
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
|
-
|
|
344
239
|
async fetchOnRampServiceProviders() {
|
|
345
240
|
return await state.api.get<OnRampServiceProvider[]>({
|
|
346
241
|
path: '/v1/onramp/providers',
|
|
@@ -351,48 +246,39 @@ export const BlockchainApiController = {
|
|
|
351
246
|
});
|
|
352
247
|
},
|
|
353
248
|
|
|
249
|
+
async fetchOnRampCountries() {
|
|
250
|
+
return await this.fetchProperties<OnRampCountry[]>('countries');
|
|
251
|
+
},
|
|
252
|
+
|
|
354
253
|
async fetchOnRampPaymentMethods(params: { countries?: string }) {
|
|
355
|
-
return await
|
|
356
|
-
path: '/v1/onramp/providers/properties',
|
|
357
|
-
headers: getHeaders(),
|
|
358
|
-
params: {
|
|
359
|
-
projectId: OptionsController.state.projectId,
|
|
360
|
-
type: 'payment-methods',
|
|
361
|
-
...params
|
|
362
|
-
}
|
|
363
|
-
});
|
|
254
|
+
return await this.fetchProperties<OnRampPaymentMethod[]>('payment-methods', params);
|
|
364
255
|
},
|
|
365
256
|
|
|
366
257
|
async fetchOnRampCryptoCurrencies(params: { countries?: string }) {
|
|
367
|
-
return await
|
|
368
|
-
path: '/v1/onramp/providers/properties',
|
|
369
|
-
headers: getHeaders(),
|
|
370
|
-
params: {
|
|
371
|
-
projectId: OptionsController.state.projectId,
|
|
372
|
-
type: 'crypto-currencies',
|
|
373
|
-
...params
|
|
374
|
-
}
|
|
375
|
-
});
|
|
258
|
+
return await this.fetchProperties<OnRampCryptoCurrency[]>('crypto-currencies', params);
|
|
376
259
|
},
|
|
377
260
|
|
|
378
261
|
async fetchOnRampFiatCurrencies() {
|
|
379
|
-
return await
|
|
380
|
-
path: '/v1/onramp/providers/properties',
|
|
381
|
-
headers: getHeaders(),
|
|
382
|
-
params: {
|
|
383
|
-
projectId: OptionsController.state.projectId,
|
|
384
|
-
type: 'fiat-currencies'
|
|
385
|
-
}
|
|
386
|
-
});
|
|
262
|
+
return await this.fetchProperties<OnRampFiatCurrency[]>('fiat-currencies');
|
|
387
263
|
},
|
|
388
264
|
|
|
389
265
|
async fetchOnRampFiatLimits() {
|
|
390
|
-
return await
|
|
266
|
+
return await this.fetchProperties<OnRampFiatLimit[]>('fiat-purchases-limits');
|
|
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>({
|
|
391
275
|
path: '/v1/onramp/providers/properties',
|
|
392
276
|
headers: getHeaders(),
|
|
393
277
|
params: {
|
|
394
278
|
projectId: OptionsController.state.projectId,
|
|
395
|
-
type
|
|
279
|
+
type,
|
|
280
|
+
excludeProviders: EXCLUDED_ONRAMP_PROVIDERS.join(','),
|
|
281
|
+
...params
|
|
396
282
|
}
|
|
397
283
|
});
|
|
398
284
|
},
|
|
@@ -4,19 +4,28 @@ import type { SocialProvider } 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,
|
|
7
8
|
EstimateGasTransactionArgs,
|
|
8
9
|
SendTransactionArgs,
|
|
9
10
|
WcWallet,
|
|
10
11
|
WriteContractArgs
|
|
11
12
|
} from '../utils/TypeUtil';
|
|
13
|
+
import { ConnectorController } from './ConnectorController';
|
|
12
14
|
|
|
13
15
|
// -- Types --------------------------------------------- //
|
|
16
|
+
export interface ConnectExternalOptions {
|
|
17
|
+
id: Connector['id'];
|
|
18
|
+
type: Connector['type'];
|
|
19
|
+
provider?: Connector['provider'];
|
|
20
|
+
info?: Connector['info'];
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
export interface ConnectionControllerClient {
|
|
16
24
|
connectWalletConnect: (
|
|
17
25
|
onUri: (uri: string) => void,
|
|
18
26
|
walletUniversalLink?: string
|
|
19
27
|
) => Promise<void>;
|
|
28
|
+
connectExternal?: (options: ConnectExternalOptions) => Promise<void>;
|
|
20
29
|
signMessage: (message: string) => Promise<string>;
|
|
21
30
|
sendTransaction: (args: SendTransactionArgs) => Promise<`0x${string}` | null>;
|
|
22
31
|
parseUnits: (value: string, decimals: number) => bigint;
|
|
@@ -40,8 +49,9 @@ export interface ConnectionControllerState {
|
|
|
40
49
|
wcError?: boolean;
|
|
41
50
|
pressedWallet?: WcWallet;
|
|
42
51
|
recentWallets?: WcWallet[];
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
selectedSocialProvider?: SocialProvider;
|
|
53
|
+
connectedWalletImageUrl?: string;
|
|
54
|
+
connectedSocialProvider?: SocialProvider;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
type StateKey = keyof ConnectionControllerState;
|
|
@@ -81,6 +91,11 @@ export const ConnectionController = {
|
|
|
81
91
|
}, walletUniversalLink);
|
|
82
92
|
},
|
|
83
93
|
|
|
94
|
+
async connectExternal(options: ConnectExternalOptions) {
|
|
95
|
+
await this._getClient().connectExternal?.(options);
|
|
96
|
+
ConnectorController.setConnectedConnector(options.type);
|
|
97
|
+
},
|
|
98
|
+
|
|
84
99
|
async signMessage(message: string) {
|
|
85
100
|
return this._getClient().signMessage(message);
|
|
86
101
|
},
|
|
@@ -105,19 +120,14 @@ export const ConnectionController = {
|
|
|
105
120
|
state.pressedWallet = undefined;
|
|
106
121
|
},
|
|
107
122
|
|
|
108
|
-
setWcPromise(wcPromise: ConnectionControllerState['wcPromise']) {
|
|
109
|
-
state.wcPromise = wcPromise;
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
setWcUri(wcUri: ConnectionControllerState['wcUri']) {
|
|
113
|
-
state.wcUri = wcUri;
|
|
114
|
-
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
|
|
115
|
-
},
|
|
116
|
-
|
|
117
123
|
setRecentWallets(wallets: ConnectionControllerState['recentWallets']) {
|
|
118
124
|
state.recentWallets = wallets;
|
|
119
125
|
},
|
|
120
126
|
|
|
127
|
+
setSelectedSocialProvider(provider: ConnectionControllerState['selectedSocialProvider']) {
|
|
128
|
+
state.selectedSocialProvider = provider;
|
|
129
|
+
},
|
|
130
|
+
|
|
121
131
|
async setConnectedWalletImageUrl(url: ConnectionControllerState['connectedWalletImageUrl']) {
|
|
122
132
|
state.connectedWalletImageUrl = url;
|
|
123
133
|
|
|
@@ -175,12 +185,14 @@ export const ConnectionController = {
|
|
|
175
185
|
resetWcConnection() {
|
|
176
186
|
this.clearUri();
|
|
177
187
|
state.pressedWallet = undefined;
|
|
188
|
+
state.selectedSocialProvider = undefined;
|
|
178
189
|
ConnectionController.setConnectedWalletImageUrl(undefined);
|
|
179
|
-
|
|
190
|
+
ConnectorController.setConnectedConnector(undefined);
|
|
180
191
|
StorageUtil.removeWalletConnectDeepLink();
|
|
181
192
|
},
|
|
182
193
|
|
|
183
194
|
async disconnect() {
|
|
195
|
+
await this._getClient().disconnect();
|
|
184
196
|
this.resetWcConnection();
|
|
185
197
|
// remove transactions
|
|
186
198
|
// RouterController.reset('Connect');
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ConnectorType } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { subscribeKey as subKey } from 'valtio/utils';
|
|
3
|
+
import { proxy, ref } from 'valtio';
|
|
4
|
+
import type { Connector } from '../utils/TypeUtil';
|
|
5
|
+
import { StorageUtil } from '../utils/StorageUtil';
|
|
6
|
+
|
|
7
|
+
// -- Types --------------------------------------------- //
|
|
8
|
+
export interface ConnectorControllerState {
|
|
9
|
+
connectors: Connector[];
|
|
10
|
+
connectedConnector?: ConnectorType;
|
|
11
|
+
authLoading?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type StateKey = keyof ConnectorControllerState;
|
|
15
|
+
|
|
16
|
+
// -- State --------------------------------------------- //
|
|
17
|
+
const state = proxy<ConnectorControllerState>({
|
|
18
|
+
connectors: []
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// -- Controller ---------------------------------------- //
|
|
22
|
+
export const ConnectorController = {
|
|
23
|
+
state,
|
|
24
|
+
|
|
25
|
+
subscribeKey<K extends StateKey>(key: K, callback: (value: ConnectorControllerState[K]) => void) {
|
|
26
|
+
return subKey(state, key, callback);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
setConnectors(connectors: ConnectorControllerState['connectors']) {
|
|
30
|
+
state.connectors = connectors.map(c => ref(c));
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
addConnector(connector: Connector) {
|
|
34
|
+
state.connectors = [...state.connectors, ref(connector)];
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
getConnectors() {
|
|
38
|
+
return state.connectors;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
getAuthConnector() {
|
|
42
|
+
return state.connectors.find(c => c.type === 'AUTH');
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
setConnectedConnector(
|
|
46
|
+
connectorType: ConnectorControllerState['connectedConnector'],
|
|
47
|
+
saveStorage = true
|
|
48
|
+
) {
|
|
49
|
+
state.connectedConnector = connectorType;
|
|
50
|
+
|
|
51
|
+
if (saveStorage) {
|
|
52
|
+
if (connectorType) {
|
|
53
|
+
StorageUtil.setConnectedConnector(connectorType);
|
|
54
|
+
} else {
|
|
55
|
+
StorageUtil.removeConnectedConnector();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
setAuthLoading(loading: ConnectorControllerState['authLoading']) {
|
|
61
|
+
state.authLoading = loading;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { subscribeKey as subKey } from 'valtio/
|
|
2
|
-
import { proxy, subscribe as sub } from 'valtio
|
|
1
|
+
import { subscribeKey as subKey } from 'valtio/utils';
|
|
2
|
+
import { proxy, subscribe as sub } from 'valtio';
|
|
3
3
|
import { BlockchainApiController } from './BlockchainApiController';
|
|
4
4
|
import type { BlockchainApiEnsError } from '../utils/TypeUtil';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { proxy, subscribe as sub } from 'valtio
|
|
1
|
+
import { proxy, subscribe as sub } from 'valtio';
|
|
2
2
|
import { ApiController } from './ApiController';
|
|
3
3
|
import { OptionsController } from './OptionsController';
|
|
4
4
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { proxy } from 'valtio';
|
|
2
|
-
import
|
|
3
|
-
import { RouterController } from './RouterController';
|
|
2
|
+
import { AccountController } from './AccountController';
|
|
3
|
+
import { RouterController, type RouterControllerState } from './RouterController';
|
|
4
4
|
import { PublicStateController } from './PublicStateController';
|
|
5
5
|
import { EventsController } from './EventsController';
|
|
6
6
|
import { ApiController } from './ApiController';
|
|
7
|
-
import {
|
|
7
|
+
import { ConnectorController } from './ConnectorController';
|
|
8
8
|
|
|
9
9
|
// -- Types --------------------------------------------- //
|
|
10
10
|
export interface ModalControllerState {
|
|
@@ -30,11 +30,11 @@ export const ModalController = {
|
|
|
30
30
|
|
|
31
31
|
async open(options?: ModalControllerArguments['open']) {
|
|
32
32
|
await ApiController.state.prefetchPromise;
|
|
33
|
-
const
|
|
33
|
+
const connected = AccountController.state.isConnected;
|
|
34
34
|
if (options?.view) {
|
|
35
35
|
RouterController.reset(options.view);
|
|
36
|
-
} else if (isConnected) {
|
|
37
|
-
const isUniversalWallet =
|
|
36
|
+
} else if (AccountController.state.isConnected) {
|
|
37
|
+
const isUniversalWallet = ConnectorController.state.connectedConnector === 'AUTH';
|
|
38
38
|
RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
|
|
39
39
|
} else {
|
|
40
40
|
RouterController.reset('Connect');
|
|
@@ -44,12 +44,12 @@ export const ModalController = {
|
|
|
44
44
|
EventsController.sendEvent({
|
|
45
45
|
type: 'track',
|
|
46
46
|
event: 'MODAL_OPEN',
|
|
47
|
-
properties: { connected
|
|
47
|
+
properties: { connected }
|
|
48
48
|
});
|
|
49
49
|
},
|
|
50
50
|
|
|
51
51
|
close() {
|
|
52
|
-
const connected =
|
|
52
|
+
const connected = AccountController.state.isConnected;
|
|
53
53
|
state.open = false;
|
|
54
54
|
PublicStateController.set({ open: false });
|
|
55
55
|
EventsController.sendEvent({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxy, ref } from 'valtio';
|
|
2
|
-
import type { CaipNetwork, CaipNetworkId } from '
|
|
2
|
+
import type { CaipNetwork, CaipNetworkId } from '../utils/TypeUtil';
|
|
3
3
|
import { PublicStateController } from './PublicStateController';
|
|
4
4
|
import { NetworkUtil } from '@reown/appkit-common-react-native';
|
|
5
5
|
import { ConstantsUtil } from '../utils/ConstantsUtil';
|