@reown/appkit-core-react-native 0.0.0-feat-onramp-20250718200617 → 0.0.0-feat-coinbase-20250722173213
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 +166 -67
- 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 -70
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +11 -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 +51 -42
- 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 +166 -67
- 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 +22 -70
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +11 -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 +51 -42
- 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 +28 -12
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +3 -11
- 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 +7 -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 +14 -7
- 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 -191
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/controllers/AccountController.ts +23 -27
- package/src/controllers/ApiController.ts +29 -10
- package/src/controllers/BlockchainApiController.ts +140 -55
- package/src/controllers/ConnectionController.ts +12 -24
- 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 +34 -99
- package/src/controllers/OptionsController.ts +19 -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 +34 -9
- package/src/utils/FetchUtil.ts +10 -31
- package/src/utils/StorageUtil.ts +60 -48
- package/src/utils/SwapApiUtil.ts +27 -38
- package/src/utils/TypeUtil.ts +43 -193
- 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
|
@@ -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();
|
|
@@ -55,22 +57,58 @@ const getHeaders = () => {
|
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
// -- Types --------------------------------------------- //
|
|
60
|
+
type WithCaipNetworkId = { caipNetworkId: CaipNetworkId };
|
|
61
|
+
|
|
58
62
|
export interface BlockchainApiControllerState {
|
|
59
63
|
clientId: string | null;
|
|
60
64
|
api: FetchUtil;
|
|
65
|
+
supportedChains: { http: CaipNetworkId[]; ws: CaipNetworkId[] };
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// -- State --------------------------------------------- //
|
|
64
69
|
const state = proxy<BlockchainApiControllerState>({
|
|
65
70
|
clientId: null,
|
|
66
|
-
api: new FetchUtil({ baseUrl })
|
|
71
|
+
api: new FetchUtil({ baseUrl }),
|
|
72
|
+
supportedChains: { http: [], ws: [] }
|
|
67
73
|
});
|
|
68
74
|
|
|
69
75
|
// -- Controller ---------------------------------------- //
|
|
70
76
|
export const BlockchainApiController = {
|
|
71
77
|
state,
|
|
72
78
|
|
|
73
|
-
|
|
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
|
+
|
|
74
112
|
return state.api.get<BlockchainApiIdentityResponse>({
|
|
75
113
|
path: `/v1/identity/${address}`,
|
|
76
114
|
params: {
|
|
@@ -80,29 +118,39 @@ export const BlockchainApiController = {
|
|
|
80
118
|
});
|
|
81
119
|
},
|
|
82
120
|
|
|
83
|
-
fetchTransactions({
|
|
84
|
-
account,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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>({
|
|
92
130
|
path: `/v1/account/${account}/history`,
|
|
93
131
|
headers: getHeaders(),
|
|
94
132
|
params: {
|
|
95
133
|
projectId,
|
|
96
134
|
cursor,
|
|
97
|
-
onramp
|
|
135
|
+
onramp,
|
|
136
|
+
chainId
|
|
98
137
|
},
|
|
99
138
|
signal,
|
|
100
139
|
cache
|
|
101
140
|
});
|
|
141
|
+
|
|
142
|
+
return response;
|
|
102
143
|
},
|
|
103
144
|
|
|
104
|
-
fetchTokenPrice(
|
|
105
|
-
|
|
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>({
|
|
106
154
|
path: '/v1/fungible/price',
|
|
107
155
|
body: {
|
|
108
156
|
projectId,
|
|
@@ -111,9 +159,20 @@ export const BlockchainApiController = {
|
|
|
111
159
|
},
|
|
112
160
|
headers: getHeaders()
|
|
113
161
|
});
|
|
162
|
+
|
|
163
|
+
return response;
|
|
114
164
|
},
|
|
115
165
|
|
|
116
|
-
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
|
+
|
|
117
176
|
return state.api.get<BlockchainApiSwapAllowanceResponse>({
|
|
118
177
|
path: `/v1/convert/allowance`,
|
|
119
178
|
params: {
|
|
@@ -125,7 +184,14 @@ export const BlockchainApiController = {
|
|
|
125
184
|
});
|
|
126
185
|
},
|
|
127
186
|
|
|
128
|
-
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
|
+
|
|
129
195
|
return state.api.get<BlockchainApiGasPriceResponse>({
|
|
130
196
|
path: `/v1/convert/gas-price`,
|
|
131
197
|
headers: getHeaders(),
|
|
@@ -136,14 +202,16 @@ export const BlockchainApiController = {
|
|
|
136
202
|
});
|
|
137
203
|
},
|
|
138
204
|
|
|
139
|
-
fetchSwapQuote({
|
|
140
|
-
projectId,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
+
|
|
147
215
|
return state.api.get<BlockchainApiSwapQuoteResponse>({
|
|
148
216
|
path: `/v1/convert/quotes`,
|
|
149
217
|
headers: getHeaders(),
|
|
@@ -158,7 +226,14 @@ export const BlockchainApiController = {
|
|
|
158
226
|
});
|
|
159
227
|
},
|
|
160
228
|
|
|
161
|
-
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
|
+
|
|
162
237
|
return state.api.get<BlockchainApiSwapTokensResponse>({
|
|
163
238
|
path: `/v1/convert/tokens`,
|
|
164
239
|
headers: getHeaders(),
|
|
@@ -169,13 +244,16 @@ export const BlockchainApiController = {
|
|
|
169
244
|
});
|
|
170
245
|
},
|
|
171
246
|
|
|
172
|
-
generateSwapCalldata({
|
|
173
|
-
amount,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
|
|
179
257
|
return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
|
|
180
258
|
path: '/v1/convert/build-transaction',
|
|
181
259
|
headers: getHeaders(),
|
|
@@ -192,12 +270,16 @@ export const BlockchainApiController = {
|
|
|
192
270
|
});
|
|
193
271
|
},
|
|
194
272
|
|
|
195
|
-
generateApproveCalldata({
|
|
196
|
-
from,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
+
|
|
201
283
|
return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
|
|
202
284
|
path: `/v1/convert/build-approve`,
|
|
203
285
|
headers: getHeaders(),
|
|
@@ -210,15 +292,29 @@ export const BlockchainApiController = {
|
|
|
210
292
|
});
|
|
211
293
|
},
|
|
212
294
|
|
|
213
|
-
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
|
+
|
|
214
310
|
return state.api.get<BlockchainApiBalanceResponse>({
|
|
215
|
-
path: `/v1/account/${
|
|
311
|
+
path: `/v1/account/${plainAddress}/balance`,
|
|
216
312
|
headers: getHeaders(),
|
|
217
313
|
params: {
|
|
218
314
|
currency: 'usd',
|
|
219
315
|
projectId: OptionsController.state.projectId,
|
|
220
|
-
chainId
|
|
221
|
-
forceUpdate
|
|
316
|
+
chainId: `${namespace}:${chain}`,
|
|
317
|
+
forceUpdate: forceUpdate?.join(',')
|
|
222
318
|
}
|
|
223
319
|
});
|
|
224
320
|
},
|
|
@@ -301,17 +397,6 @@ export const BlockchainApiController = {
|
|
|
301
397
|
});
|
|
302
398
|
},
|
|
303
399
|
|
|
304
|
-
async fetchOnRampCountriesDefaults() {
|
|
305
|
-
return await state.api.get<OnRampCountryDefaults[]>({
|
|
306
|
-
path: '/v1/onramp/providers/properties',
|
|
307
|
-
headers: getHeaders(),
|
|
308
|
-
params: {
|
|
309
|
-
projectId: OptionsController.state.projectId,
|
|
310
|
-
type: 'countries-defaults'
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
},
|
|
314
|
-
|
|
315
400
|
async getOnRampQuotes(body: BlockchainApiOnRampQuotesRequest, signal?: AbortSignal) {
|
|
316
401
|
return await state.api.post<OnRampQuote[]>({
|
|
317
402
|
path: '/v1/onramp/multi/quotes',
|
|
@@ -4,28 +4,19 @@ 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,
|
|
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;
|
|
@@ -49,9 +40,8 @@ export interface ConnectionControllerState {
|
|
|
49
40
|
wcError?: boolean;
|
|
50
41
|
pressedWallet?: WcWallet;
|
|
51
42
|
recentWallets?: WcWallet[];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
connectedSocialProvider?: SocialProvider;
|
|
43
|
+
connectedWalletImageUrl?: string; //TODO: remove this
|
|
44
|
+
connectedSocialProvider?: SocialProvider; // TODO: remove this
|
|
55
45
|
}
|
|
56
46
|
|
|
57
47
|
type StateKey = keyof ConnectionControllerState;
|
|
@@ -91,11 +81,6 @@ export const ConnectionController = {
|
|
|
91
81
|
}, walletUniversalLink);
|
|
92
82
|
},
|
|
93
83
|
|
|
94
|
-
async connectExternal(options: ConnectExternalOptions) {
|
|
95
|
-
await this._getClient().connectExternal?.(options);
|
|
96
|
-
ConnectorController.setConnectedConnector(options.type);
|
|
97
|
-
},
|
|
98
|
-
|
|
99
84
|
async signMessage(message: string) {
|
|
100
85
|
return this._getClient().signMessage(message);
|
|
101
86
|
},
|
|
@@ -120,12 +105,17 @@ export const ConnectionController = {
|
|
|
120
105
|
state.pressedWallet = undefined;
|
|
121
106
|
},
|
|
122
107
|
|
|
123
|
-
|
|
124
|
-
state.
|
|
108
|
+
setWcPromise(wcPromise: ConnectionControllerState['wcPromise']) {
|
|
109
|
+
state.wcPromise = wcPromise;
|
|
125
110
|
},
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
state.
|
|
112
|
+
setWcUri(wcUri: ConnectionControllerState['wcUri']) {
|
|
113
|
+
state.wcUri = wcUri;
|
|
114
|
+
state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
setRecentWallets(wallets: ConnectionControllerState['recentWallets']) {
|
|
118
|
+
state.recentWallets = wallets;
|
|
129
119
|
},
|
|
130
120
|
|
|
131
121
|
async setConnectedWalletImageUrl(url: ConnectionControllerState['connectedWalletImageUrl']) {
|
|
@@ -185,14 +175,12 @@ export const ConnectionController = {
|
|
|
185
175
|
resetWcConnection() {
|
|
186
176
|
this.clearUri();
|
|
187
177
|
state.pressedWallet = undefined;
|
|
188
|
-
state.selectedSocialProvider = undefined;
|
|
189
178
|
ConnectionController.setConnectedWalletImageUrl(undefined);
|
|
190
|
-
ConnectorController.setConnectedConnector(undefined);
|
|
179
|
+
// ConnectorController.setConnectedConnector(undefined);
|
|
191
180
|
StorageUtil.removeWalletConnectDeepLink();
|
|
192
181
|
},
|
|
193
182
|
|
|
194
183
|
async disconnect() {
|
|
195
|
-
await this._getClient().disconnect();
|
|
196
184
|
this.resetWcConnection();
|
|
197
185
|
// remove transactions
|
|
198
186
|
// RouterController.reset('Connect');
|