@reown/appkit-core-react-native 0.0.0-accounts-canary.1-20251023174733
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/ApiController.js +410 -0
- package/lib/commonjs/controllers/ApiController.js.map +1 -0
- package/lib/commonjs/controllers/AssetController.js +30 -0
- package/lib/commonjs/controllers/AssetController.js.map +1 -0
- package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
- package/lib/commonjs/controllers/ConnectionsController.js +425 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +37 -0
- package/lib/commonjs/controllers/EnsController.js.map +1 -0
- package/lib/commonjs/controllers/EventsController.js +122 -0
- package/lib/commonjs/controllers/EventsController.js.map +1 -0
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +68 -0
- package/lib/commonjs/controllers/ModalController.js.map +1 -0
- package/lib/commonjs/controllers/OnRampController.js +502 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +96 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -0
- package/lib/commonjs/controllers/PublicStateController.js +33 -0
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
- package/lib/commonjs/controllers/RouterController.js +63 -0
- package/lib/commonjs/controllers/RouterController.js.map +1 -0
- package/lib/commonjs/controllers/SendController.js +192 -0
- package/lib/commonjs/controllers/SendController.js.map +1 -0
- package/lib/commonjs/controllers/SnackController.js +83 -0
- package/lib/commonjs/controllers/SnackController.js.map +1 -0
- package/lib/commonjs/controllers/SwapController.js +674 -0
- package/lib/commonjs/controllers/SwapController.js.map +1 -0
- package/lib/commonjs/controllers/ThemeController.js +45 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -0
- package/lib/commonjs/controllers/TransactionsController.js +118 -0
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
- package/lib/commonjs/controllers/WcController.js +73 -0
- package/lib/commonjs/controllers/WcController.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/index.js +28 -0
- package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
- package/lib/commonjs/index.js +202 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +43 -0
- package/lib/commonjs/utils/ApiUtil.js.map +1 -0
- package/lib/commonjs/utils/AssetUtil.js +27 -0
- package/lib/commonjs/utils/AssetUtil.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +226 -0
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
- package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
- package/lib/commonjs/utils/EventUtil.js +25 -0
- package/lib/commonjs/utils/EventUtil.js.map +1 -0
- package/lib/commonjs/utils/FetchUtil.js +158 -0
- package/lib/commonjs/utils/FetchUtil.js.map +1 -0
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +319 -0
- package/lib/commonjs/utils/StorageUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapApiUtil.js +75 -0
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +407 -0
- package/lib/module/controllers/ApiController.js.map +1 -0
- package/lib/module/controllers/AssetController.js +27 -0
- package/lib/module/controllers/AssetController.js.map +1 -0
- package/lib/module/controllers/BlockchainApiController.js +381 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -0
- package/lib/module/controllers/ConnectionsController.js +422 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +34 -0
- package/lib/module/controllers/EnsController.js.map +1 -0
- package/lib/module/controllers/EventsController.js +118 -0
- package/lib/module/controllers/EventsController.js.map +1 -0
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +65 -0
- package/lib/module/controllers/ModalController.js.map +1 -0
- package/lib/module/controllers/OnRampController.js +499 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +93 -0
- package/lib/module/controllers/OptionsController.js.map +1 -0
- package/lib/module/controllers/PublicStateController.js +30 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -0
- package/lib/module/controllers/RouterController.js +60 -0
- package/lib/module/controllers/RouterController.js.map +1 -0
- package/lib/module/controllers/SendController.js +189 -0
- package/lib/module/controllers/SendController.js.map +1 -0
- package/lib/module/controllers/SnackController.js +80 -0
- package/lib/module/controllers/SnackController.js.map +1 -0
- package/lib/module/controllers/SwapController.js +671 -0
- package/lib/module/controllers/SwapController.js.map +1 -0
- package/lib/module/controllers/ThemeController.js +42 -0
- package/lib/module/controllers/ThemeController.js.map +1 -0
- package/lib/module/controllers/TransactionsController.js +115 -0
- package/lib/module/controllers/TransactionsController.js.map +1 -0
- package/lib/module/controllers/WcController.js +70 -0
- package/lib/module/controllers/WcController.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/module/features/reown-authentication/index.js +5 -0
- package/lib/module/features/reown-authentication/index.js.map +1 -0
- package/lib/module/index.js +38 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/ApiUtil.js +39 -0
- package/lib/module/utils/ApiUtil.js.map +1 -0
- package/lib/module/utils/AssetUtil.js +23 -0
- package/lib/module/utils/AssetUtil.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +222 -0
- package/lib/module/utils/ConstantsUtil.js.map +1 -0
- package/lib/module/utils/CoreHelperUtil.js +294 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -0
- package/lib/module/utils/EventUtil.js +21 -0
- package/lib/module/utils/EventUtil.js.map +1 -0
- package/lib/module/utils/FetchUtil.js +154 -0
- package/lib/module/utils/FetchUtil.js.map +1 -0
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +315 -0
- package/lib/module/utils/StorageUtil.js.map +1 -0
- package/lib/module/utils/SwapApiUtil.js +71 -0
- package/lib/module/utils/SwapApiUtil.js.map +1 -0
- package/lib/module/utils/SwapCalculationUtil.js +94 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +40 -0
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/AssetController.d.ts +12 -0
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EnsController.d.ts +10 -0
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EventsController.d.ts +25 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
- package/lib/typescript/controllers/LogController.d.ts +65 -0
- package/lib/typescript/controllers/LogController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +17 -0
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
- package/lib/typescript/controllers/OnRampController.d.ts +55 -0
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
- package/lib/typescript/controllers/OptionsController.d.ts +46 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
- package/lib/typescript/controllers/RouterController.d.ts +21 -0
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
- package/lib/typescript/controllers/SendController.d.ts +39 -0
- package/lib/typescript/controllers/SendController.d.ts.map +1 -0
- package/lib/typescript/controllers/SnackController.d.ts +20 -0
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
- package/lib/typescript/controllers/SwapController.d.ts +116 -0
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
- package/lib/typescript/controllers/ThemeController.d.ts +14 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
- package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/WcController.d.ts +27 -0
- package/lib/typescript/controllers/WcController.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
- package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +29 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/ApiUtil.d.ts +7 -0
- package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/AssetUtil.d.ts +6 -0
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
- package/lib/typescript/utils/EventUtil.d.ts +5 -0
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
- package/lib/typescript/utils/FetchUtil.d.ts +29 -0
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
- package/lib/typescript/utils/LogUtils.d.ts +15 -0
- package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +36 -0
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +57 -0
- package/readme.md +9 -0
- package/src/controllers/ApiController.ts +454 -0
- package/src/controllers/AssetController.ts +32 -0
- package/src/controllers/BlockchainApiController.ts +418 -0
- package/src/controllers/ConnectionsController.ts +575 -0
- package/src/controllers/EnsController.ts +41 -0
- package/src/controllers/EventsController.ts +146 -0
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +68 -0
- package/src/controllers/OnRampController.ts +698 -0
- package/src/controllers/OptionsController.ts +143 -0
- package/src/controllers/PublicStateController.ts +37 -0
- package/src/controllers/RouterController.ts +112 -0
- package/src/controllers/SendController.ts +270 -0
- package/src/controllers/SnackController.ts +95 -0
- package/src/controllers/SwapController.ts +863 -0
- package/src/controllers/ThemeController.ts +47 -0
- package/src/controllers/TransactionsController.ts +150 -0
- package/src/controllers/WcController.ts +93 -0
- package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
- package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
- package/src/features/reown-authentication/index.ts +2 -0
- package/src/index.ts +70 -0
- package/src/utils/ApiUtil.ts +50 -0
- package/src/utils/AssetUtil.ts +27 -0
- package/src/utils/ConstantsUtil.ts +303 -0
- package/src/utils/CoreHelperUtil.ts +377 -0
- package/src/utils/EventUtil.ts +22 -0
- package/src/utils/FetchUtil.ts +164 -0
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +405 -0
- package/src/utils/SwapApiUtil.ts +101 -0
- package/src/utils/SwapCalculationUtil.ts +145 -0
- package/src/utils/WalletUtil.ts +14 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { proxy } from 'valtio';
|
|
2
|
+
|
|
3
|
+
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
4
|
+
import { FetchUtil } from '../utils/FetchUtil';
|
|
5
|
+
import type {
|
|
6
|
+
BlockchainApiBalanceResponse,
|
|
7
|
+
BlockchainApiGasPriceRequest,
|
|
8
|
+
BlockchainApiGasPriceResponse,
|
|
9
|
+
BlockchainApiGenerateApproveCalldataRequest,
|
|
10
|
+
BlockchainApiGenerateApproveCalldataResponse,
|
|
11
|
+
BlockchainApiGenerateSwapCalldataRequest,
|
|
12
|
+
BlockchainApiGenerateSwapCalldataResponse,
|
|
13
|
+
BlockchainApiIdentityRequest,
|
|
14
|
+
BlockchainApiIdentityResponse,
|
|
15
|
+
BlockchainApiLookupEnsName,
|
|
16
|
+
BlockchainApiSwapAllowanceRequest,
|
|
17
|
+
BlockchainApiSwapAllowanceResponse,
|
|
18
|
+
BlockchainApiSwapQuoteRequest,
|
|
19
|
+
BlockchainApiSwapQuoteResponse,
|
|
20
|
+
BlockchainApiSwapTokensRequest,
|
|
21
|
+
BlockchainApiSwapTokensResponse,
|
|
22
|
+
BlockchainApiOnRampWidgetResponse,
|
|
23
|
+
BlockchainApiTokenPriceRequest,
|
|
24
|
+
BlockchainApiTokenPriceResponse,
|
|
25
|
+
BlockchainApiTransactionsRequest,
|
|
26
|
+
BlockchainApiTransactionsResponse,
|
|
27
|
+
OnRampCountry,
|
|
28
|
+
OnRampServiceProvider,
|
|
29
|
+
OnRampPaymentMethod,
|
|
30
|
+
OnRampCryptoCurrency,
|
|
31
|
+
OnRampFiatCurrency,
|
|
32
|
+
OnRampQuote,
|
|
33
|
+
BlockchainApiOnRampWidgetRequest,
|
|
34
|
+
BlockchainApiOnRampQuotesRequest,
|
|
35
|
+
OnRampFiatLimit,
|
|
36
|
+
OnRampCountryDefaults,
|
|
37
|
+
CaipAddress,
|
|
38
|
+
CaipNetworkId
|
|
39
|
+
} from '@reown/appkit-common-react-native';
|
|
40
|
+
import { OptionsController } from './OptionsController';
|
|
41
|
+
import { ConstantsUtil } from '../utils/ConstantsUtil';
|
|
42
|
+
import { ApiUtil } from '../utils/ApiUtil';
|
|
43
|
+
|
|
44
|
+
import { SnackController } from './SnackController';
|
|
45
|
+
import { LogController } from './LogController';
|
|
46
|
+
|
|
47
|
+
// -- Helpers ------------------------------------------- //
|
|
48
|
+
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();
|
|
49
|
+
|
|
50
|
+
const getParams = () => {
|
|
51
|
+
const { projectId, sdkType, sdkVersion } = OptionsController.state;
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
projectId,
|
|
55
|
+
st: sdkType,
|
|
56
|
+
sv: sdkVersion
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getHeaders = () => {
|
|
61
|
+
return {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
63
|
+
'User-Agent': ApiUtil.getUserAgent(),
|
|
64
|
+
'origin': ApiUtil.getOrigin()
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const EXCLUDED_ONRAMP_PROVIDERS = ['BINANCECONNECT', 'COINBASEPAY'];
|
|
69
|
+
|
|
70
|
+
// -- Types --------------------------------------------- //
|
|
71
|
+
type WithCaipNetworkId = { caipNetworkId: CaipNetworkId };
|
|
72
|
+
|
|
73
|
+
export interface BlockchainApiControllerState {
|
|
74
|
+
clientId: string | null;
|
|
75
|
+
api: FetchUtil;
|
|
76
|
+
supportedChains: { http: CaipNetworkId[]; ws: CaipNetworkId[] };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// -- State --------------------------------------------- //
|
|
80
|
+
const state = proxy<BlockchainApiControllerState>({
|
|
81
|
+
clientId: null,
|
|
82
|
+
api: new FetchUtil({ baseUrl }),
|
|
83
|
+
supportedChains: { http: [], ws: [] }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// -- Controller ---------------------------------------- //
|
|
87
|
+
export const BlockchainApiController = {
|
|
88
|
+
state,
|
|
89
|
+
|
|
90
|
+
async isNetworkSupported(networkId?: CaipNetworkId) {
|
|
91
|
+
if (!networkId) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
if (!state.supportedChains.http.length) {
|
|
96
|
+
await BlockchainApiController.getSupportedNetworks();
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
LogController.sendError(e, 'BlockchainApiController.ts', 'isNetworkSupported');
|
|
100
|
+
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return state.supportedChains.http.includes(networkId);
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
async getSupportedNetworks() {
|
|
108
|
+
const supportedChains = await state.api.get<BlockchainApiControllerState['supportedChains']>({
|
|
109
|
+
path: 'v1/supported-chains',
|
|
110
|
+
params: getParams()
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
state.supportedChains = supportedChains!;
|
|
114
|
+
|
|
115
|
+
return supportedChains;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
async fetchIdentity(params: BlockchainApiIdentityRequest) {
|
|
119
|
+
const { address } = params;
|
|
120
|
+
|
|
121
|
+
return state.api.get<BlockchainApiIdentityResponse>({
|
|
122
|
+
path: `/v1/identity/${address}`,
|
|
123
|
+
headers: getHeaders(),
|
|
124
|
+
params: getParams()
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
async fetchTransactions(params: BlockchainApiTransactionsRequest) {
|
|
129
|
+
const { account, cursor, signal, cache, chainId } = params;
|
|
130
|
+
const isSupported = ConstantsUtil.ACTIVITY_SUPPORTED_CHAINS.includes(chainId);
|
|
131
|
+
|
|
132
|
+
if (!isSupported) {
|
|
133
|
+
return { data: [], next: undefined };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const response = await state.api.get<BlockchainApiTransactionsResponse>({
|
|
137
|
+
path: `/v1/account/${account}/history`,
|
|
138
|
+
headers: getHeaders(),
|
|
139
|
+
params: {
|
|
140
|
+
...getParams(),
|
|
141
|
+
cursor,
|
|
142
|
+
chainId
|
|
143
|
+
},
|
|
144
|
+
signal,
|
|
145
|
+
cache
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return response;
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
async fetchTokenPrice(params: BlockchainApiTokenPriceRequest & WithCaipNetworkId) {
|
|
152
|
+
const { projectId, addresses, caipNetworkId } = params;
|
|
153
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(caipNetworkId);
|
|
154
|
+
|
|
155
|
+
if (!isSupported) {
|
|
156
|
+
return { fungibles: [] };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const response = await state.api.post<BlockchainApiTokenPriceResponse>({
|
|
160
|
+
path: '/v1/fungible/price',
|
|
161
|
+
headers: getHeaders(),
|
|
162
|
+
params: getParams(),
|
|
163
|
+
body: {
|
|
164
|
+
projectId,
|
|
165
|
+
currency: 'usd',
|
|
166
|
+
addresses
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return response;
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
async fetchSwapAllowance(params: BlockchainApiSwapAllowanceRequest) {
|
|
174
|
+
const { tokenAddress, userAddress } = params;
|
|
175
|
+
const [namespace, chain] = userAddress.split(':');
|
|
176
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
177
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
178
|
+
|
|
179
|
+
if (!isSupported) {
|
|
180
|
+
return { allowance: '0' };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return state.api.get<BlockchainApiSwapAllowanceResponse>({
|
|
184
|
+
path: `/v1/convert/allowance`,
|
|
185
|
+
params: {
|
|
186
|
+
...getParams(),
|
|
187
|
+
tokenAddress,
|
|
188
|
+
userAddress
|
|
189
|
+
},
|
|
190
|
+
headers: getHeaders()
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
async fetchGasPrice(params: BlockchainApiGasPriceRequest) {
|
|
195
|
+
const { chainId } = params;
|
|
196
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
197
|
+
|
|
198
|
+
if (!isSupported) {
|
|
199
|
+
throw new Error('Network not supported for Gas Price');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return state.api.get<BlockchainApiGasPriceResponse>({
|
|
203
|
+
path: `/v1/convert/gas-price`,
|
|
204
|
+
headers: getHeaders(),
|
|
205
|
+
params: {
|
|
206
|
+
...getParams(),
|
|
207
|
+
chainId
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
async fetchSwapQuote(params: BlockchainApiSwapQuoteRequest) {
|
|
213
|
+
const { amount, userAddress, from, to, gasPrice } = params;
|
|
214
|
+
const [namespace, chain] = userAddress.split(':');
|
|
215
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
216
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
217
|
+
|
|
218
|
+
if (!isSupported) {
|
|
219
|
+
return { quotes: [] };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return state.api.get<BlockchainApiSwapQuoteResponse>({
|
|
223
|
+
path: `/v1/convert/quotes`,
|
|
224
|
+
headers: getHeaders(),
|
|
225
|
+
params: {
|
|
226
|
+
...getParams(),
|
|
227
|
+
amount,
|
|
228
|
+
userAddress,
|
|
229
|
+
from,
|
|
230
|
+
to,
|
|
231
|
+
gasPrice
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
async fetchSwapTokens(params: BlockchainApiSwapTokensRequest) {
|
|
237
|
+
const { chainId } = params;
|
|
238
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(chainId);
|
|
239
|
+
|
|
240
|
+
if (!isSupported) {
|
|
241
|
+
return { tokens: [] };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return state.api.get<BlockchainApiSwapTokensResponse>({
|
|
245
|
+
path: `/v1/convert/tokens`,
|
|
246
|
+
headers: getHeaders(),
|
|
247
|
+
params: {
|
|
248
|
+
...getParams(),
|
|
249
|
+
chainId
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
async generateSwapCalldata(params: BlockchainApiGenerateSwapCalldataRequest) {
|
|
255
|
+
const { amount, from, projectId, to, userAddress } = params;
|
|
256
|
+
const [namespace, chain] = userAddress.split(':');
|
|
257
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
258
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
259
|
+
|
|
260
|
+
if (!isSupported) {
|
|
261
|
+
throw new Error('Network not supported for Swaps');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return state.api.post<BlockchainApiGenerateSwapCalldataResponse>({
|
|
265
|
+
path: '/v1/convert/build-transaction',
|
|
266
|
+
headers: getHeaders(),
|
|
267
|
+
params: getParams(),
|
|
268
|
+
body: {
|
|
269
|
+
amount,
|
|
270
|
+
eip155: {
|
|
271
|
+
slippage: ConstantsUtil.CONVERT_SLIPPAGE_TOLERANCE
|
|
272
|
+
},
|
|
273
|
+
from,
|
|
274
|
+
projectId,
|
|
275
|
+
to,
|
|
276
|
+
userAddress
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
async generateApproveCalldata(params: BlockchainApiGenerateApproveCalldataRequest) {
|
|
282
|
+
const { from, to, userAddress } = params;
|
|
283
|
+
const [namespace, chain] = userAddress.split(':');
|
|
284
|
+
const networkId: CaipNetworkId = `${namespace}:${chain}`;
|
|
285
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(networkId);
|
|
286
|
+
|
|
287
|
+
if (!isSupported) {
|
|
288
|
+
throw new Error('Network not supported for Swaps');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return state.api.get<BlockchainApiGenerateApproveCalldataResponse>({
|
|
292
|
+
path: `/v1/convert/build-approve`,
|
|
293
|
+
headers: getHeaders(),
|
|
294
|
+
params: {
|
|
295
|
+
...getParams(),
|
|
296
|
+
userAddress,
|
|
297
|
+
from,
|
|
298
|
+
to
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
async getBalance(address?: CaipAddress, forceUpdate?: CaipAddress[]) {
|
|
304
|
+
const [namespace, chain, plainAddress] = address?.split(':') ?? [];
|
|
305
|
+
|
|
306
|
+
if (!namespace || !chain || !plainAddress) {
|
|
307
|
+
throw new Error('Invalid address');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const isSupported = await BlockchainApiController.isNetworkSupported(`${namespace}:${chain}`);
|
|
311
|
+
|
|
312
|
+
if (!isSupported) {
|
|
313
|
+
SnackController.showError('Token Balance Unavailable');
|
|
314
|
+
|
|
315
|
+
return { balances: [] };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return state.api.get<BlockchainApiBalanceResponse>({
|
|
319
|
+
path: `/v1/account/${plainAddress}/balance`,
|
|
320
|
+
headers: getHeaders(),
|
|
321
|
+
params: {
|
|
322
|
+
...getParams(),
|
|
323
|
+
currency: 'usd',
|
|
324
|
+
chainId: `${namespace}:${chain}`,
|
|
325
|
+
forceUpdate: forceUpdate?.join(',')
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
async lookupEnsName(name: string) {
|
|
331
|
+
return state.api.get<BlockchainApiLookupEnsName>({
|
|
332
|
+
path: `/v1/profile/account/${name}`,
|
|
333
|
+
headers: getHeaders(),
|
|
334
|
+
params: {
|
|
335
|
+
...getParams(),
|
|
336
|
+
apiVersion: '2'
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
async fetchOnRampServiceProviders() {
|
|
342
|
+
return await state.api.get<OnRampServiceProvider[]>({
|
|
343
|
+
path: '/v1/onramp/providers',
|
|
344
|
+
headers: getHeaders(),
|
|
345
|
+
params: getParams()
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
async fetchOnRampCountries() {
|
|
350
|
+
return await this.fetchProperties<OnRampCountry[]>('countries');
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
async fetchOnRampPaymentMethods(params: { countries?: string }) {
|
|
354
|
+
return await this.fetchProperties<OnRampPaymentMethod[]>('payment-methods', params);
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
async fetchOnRampCryptoCurrencies(params: { countries?: string }) {
|
|
358
|
+
return await this.fetchProperties<OnRampCryptoCurrency[]>('crypto-currencies', params);
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
async fetchOnRampFiatCurrencies() {
|
|
362
|
+
return await this.fetchProperties<OnRampFiatCurrency[]>('fiat-currencies');
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
async fetchOnRampFiatLimits() {
|
|
366
|
+
return await this.fetchProperties<OnRampFiatLimit[]>('fiat-purchases-limits');
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
async fetchOnRampCountriesDefaults() {
|
|
370
|
+
return await this.fetchProperties<OnRampCountryDefaults[]>('countries-defaults');
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
async fetchProperties<T>(type: string, params?: Record<string, string>) {
|
|
374
|
+
return await state.api.get<T>({
|
|
375
|
+
path: '/v1/onramp/providers/properties',
|
|
376
|
+
headers: getHeaders(),
|
|
377
|
+
params: {
|
|
378
|
+
...getParams(),
|
|
379
|
+
type,
|
|
380
|
+
excludeProviders: EXCLUDED_ONRAMP_PROVIDERS.join(','),
|
|
381
|
+
...params
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
async getOnRampQuotes(body: BlockchainApiOnRampQuotesRequest, signal?: AbortSignal) {
|
|
387
|
+
return await state.api.post<OnRampQuote[]>({
|
|
388
|
+
path: '/v1/onramp/multi/quotes',
|
|
389
|
+
headers: getHeaders(),
|
|
390
|
+
params: getParams(),
|
|
391
|
+
body: {
|
|
392
|
+
projectId: OptionsController.state.projectId,
|
|
393
|
+
...body
|
|
394
|
+
},
|
|
395
|
+
signal
|
|
396
|
+
});
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
async getOnRampWidget(body: BlockchainApiOnRampWidgetRequest, signal?: AbortSignal) {
|
|
400
|
+
return await state.api.post<BlockchainApiOnRampWidgetResponse>({
|
|
401
|
+
path: '/v1/onramp/widget',
|
|
402
|
+
headers: getHeaders(),
|
|
403
|
+
params: getParams(),
|
|
404
|
+
body: {
|
|
405
|
+
projectId: OptionsController.state.projectId,
|
|
406
|
+
sessionData: {
|
|
407
|
+
...body
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
signal
|
|
411
|
+
});
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
setClientId(clientId: string | null) {
|
|
415
|
+
state.clientId = clientId;
|
|
416
|
+
state.api = new FetchUtil({ baseUrl, clientId });
|
|
417
|
+
}
|
|
418
|
+
};
|