@reown/appkit-core-react-native 1.2.6 → 1.3.1
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/BlockchainApiController.js +65 -1
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectorController.js +3 -3
- package/lib/commonjs/controllers/ConnectorController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/NetworkController.js +2 -2
- package/lib/commonjs/controllers/NetworkController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +475 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +3 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +3 -2
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +8 -5
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +69 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +28 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +20 -4
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +185 -1
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +29 -0
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +64 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectorController.js +3 -3
- package/lib/module/controllers/ConnectorController.js.map +1 -1
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/NetworkController.js +2 -2
- package/lib/module/controllers/NetworkController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +470 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +3 -0
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +3 -2
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +8 -5
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +68 -4
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +26 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +20 -4
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +186 -1
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +27 -1
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +16 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +1 -1
- 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 +3 -2
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- 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 +2 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +4 -3
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +55 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +3 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +4 -4
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +16 -2
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +172 -0
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/controllers/BlockchainApiController.ts +87 -1
- package/src/controllers/ConnectorController.ts +3 -3
- package/src/controllers/ModalController.ts +1 -2
- package/src/controllers/NetworkController.ts +4 -4
- package/src/controllers/OnRampController.ts +663 -0
- package/src/controllers/OptionsController.ts +5 -0
- package/src/controllers/RouterController.ts +16 -3
- package/src/index.ts +1 -0
- package/src/utils/AssetUtil.ts +9 -5
- package/src/utils/ConstantsUtil.ts +49 -4
- package/src/utils/CoreHelperUtil.ts +30 -0
- package/src/utils/FetchUtil.ts +21 -8
- package/src/utils/StorageUtil.ts +225 -3
- package/src/utils/TypeUtil.ts +201 -1
|
@@ -20,6 +20,7 @@ const getHeaders = () => {
|
|
|
20
20
|
'origin': ApiUtil.getOrigin()
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
export const EXCLUDED_ONRAMP_PROVIDERS = ['BINANCECONNECT', 'COINBASEPAY'];
|
|
23
24
|
|
|
24
25
|
// -- Types --------------------------------------------- //
|
|
25
26
|
|
|
@@ -202,6 +203,69 @@ export const BlockchainApiController = {
|
|
|
202
203
|
}
|
|
203
204
|
});
|
|
204
205
|
},
|
|
206
|
+
async fetchOnRampServiceProviders() {
|
|
207
|
+
return await state.api.get({
|
|
208
|
+
path: '/v1/onramp/providers',
|
|
209
|
+
headers: getHeaders(),
|
|
210
|
+
params: {
|
|
211
|
+
projectId: OptionsController.state.projectId
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
async fetchOnRampCountries() {
|
|
216
|
+
return await this.fetchProperties('countries');
|
|
217
|
+
},
|
|
218
|
+
async fetchOnRampPaymentMethods(params) {
|
|
219
|
+
return await this.fetchProperties('payment-methods', params);
|
|
220
|
+
},
|
|
221
|
+
async fetchOnRampCryptoCurrencies(params) {
|
|
222
|
+
return await this.fetchProperties('crypto-currencies', params);
|
|
223
|
+
},
|
|
224
|
+
async fetchOnRampFiatCurrencies() {
|
|
225
|
+
return await this.fetchProperties('fiat-currencies');
|
|
226
|
+
},
|
|
227
|
+
async fetchOnRampFiatLimits() {
|
|
228
|
+
return await this.fetchProperties('fiat-purchases-limits');
|
|
229
|
+
},
|
|
230
|
+
async fetchOnRampCountriesDefaults() {
|
|
231
|
+
return await this.fetchProperties('countries-defaults');
|
|
232
|
+
},
|
|
233
|
+
async fetchProperties(type, params) {
|
|
234
|
+
return await state.api.get({
|
|
235
|
+
path: '/v1/onramp/providers/properties',
|
|
236
|
+
headers: getHeaders(),
|
|
237
|
+
params: {
|
|
238
|
+
projectId: OptionsController.state.projectId,
|
|
239
|
+
type,
|
|
240
|
+
excludeProviders: EXCLUDED_ONRAMP_PROVIDERS.join(','),
|
|
241
|
+
...params
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
async getOnRampQuotes(body, signal) {
|
|
246
|
+
return await state.api.post({
|
|
247
|
+
path: '/v1/onramp/multi/quotes',
|
|
248
|
+
headers: getHeaders(),
|
|
249
|
+
body: {
|
|
250
|
+
projectId: OptionsController.state.projectId,
|
|
251
|
+
...body
|
|
252
|
+
},
|
|
253
|
+
signal
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
async getOnRampWidget(body, signal) {
|
|
257
|
+
return await state.api.post({
|
|
258
|
+
path: '/v1/onramp/widget',
|
|
259
|
+
headers: getHeaders(),
|
|
260
|
+
body: {
|
|
261
|
+
projectId: OptionsController.state.projectId,
|
|
262
|
+
sessionData: {
|
|
263
|
+
...body
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
signal
|
|
267
|
+
});
|
|
268
|
+
},
|
|
205
269
|
setClientId(clientId) {
|
|
206
270
|
state.clientId = clientId;
|
|
207
271
|
state.api = new FetchUtil({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["proxy","CoreHelperUtil","FetchUtil","OptionsController","ConstantsUtil","ApiUtil","baseUrl","getBlockchainApiUrl","getHeaders","sdkType","sdkVersion","state","getUserAgent","getOrigin","clientId","api","BlockchainApiController","fetchIdentity","address","get","path","params","projectId","headers","fetchTransactions","account","cursor","onramp","signal","cache","fetchTokenPrice","addresses","post","body","currency","fetchSwapAllowance","tokenAddress","userAddress","fetchGasPrice","chainId","fetchSwapQuote","amount","from","to","gasPrice","fetchSwapTokens","generateSwapCalldata","eip155","slippage","CONVERT_SLIPPAGE_TOLERANCE","generateApproveCalldata","getBalance","forceUpdate","lookupEnsName","name","apiVersion","setClientId"],"sourceRoot":"../../../src","sources":["controllers/BlockchainApiController.ts"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAE9B,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,SAAS,QAAQ,oBAAoB;
|
|
1
|
+
{"version":3,"names":["proxy","CoreHelperUtil","FetchUtil","OptionsController","ConstantsUtil","ApiUtil","baseUrl","getBlockchainApiUrl","getHeaders","sdkType","sdkVersion","state","getUserAgent","getOrigin","EXCLUDED_ONRAMP_PROVIDERS","clientId","api","BlockchainApiController","fetchIdentity","address","get","path","params","projectId","headers","fetchTransactions","account","cursor","onramp","signal","cache","fetchTokenPrice","addresses","post","body","currency","fetchSwapAllowance","tokenAddress","userAddress","fetchGasPrice","chainId","fetchSwapQuote","amount","from","to","gasPrice","fetchSwapTokens","generateSwapCalldata","eip155","slippage","CONVERT_SLIPPAGE_TOLERANCE","generateApproveCalldata","getBalance","forceUpdate","lookupEnsName","name","apiVersion","fetchOnRampServiceProviders","fetchOnRampCountries","fetchProperties","fetchOnRampPaymentMethods","fetchOnRampCryptoCurrencies","fetchOnRampFiatCurrencies","fetchOnRampFiatLimits","fetchOnRampCountriesDefaults","type","excludeProviders","join","getOnRampQuotes","getOnRampWidget","sessionData","setClientId"],"sourceRoot":"../../../src","sources":["controllers/BlockchainApiController.ts"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAE9B,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,SAAS,QAAQ,oBAAoB;AAkC9C,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,OAAO,QAAQ,kBAAkB;;AAE1C;AACA,MAAMC,OAAO,GAAGL,cAAc,CAACM,mBAAmB,CAAC,CAAC;AAEpD,MAAMC,UAAU,GAAGA,CAAA,KAAM;EACvB,MAAM;IAAEC,OAAO;IAAEC;EAAW,CAAC,GAAGP,iBAAiB,CAACQ,KAAK;EAEvD,OAAO;IACL,cAAc,EAAE,kBAAkB;IAClC,YAAY,EAAEF,OAAO;IACrB,eAAe,EAAEC,UAAU;IAC3B,YAAY,EAAEL,OAAO,CAACO,YAAY,CAAC,CAAC;IACpC,QAAQ,EAAEP,OAAO,CAACQ,SAAS,CAAC;EAC9B,CAAC;AACH,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC;;AAE1E;;AAMA;AACA,MAAMH,KAAK,GAAGX,KAAK,CAA+B;EAChDe,QAAQ,EAAE,IAAI;EACdC,GAAG,EAAE,IAAId,SAAS,CAAC;IAAEI;EAAQ,CAAC;AAChC,CAAC,CAAC;;AAEF;AACA,OAAO,MAAMW,uBAAuB,GAAG;EACrCN,KAAK;EAELO,aAAaA,CAAC;IAAEC;EAAsC,CAAC,EAAE;IAC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,SAAS;QAC5C,GAAGW;MACL,CAAC;MACDL;IACF,CAAC,CAAC;EACJ,CAAC;EAED,MAAMwC,eAAeA,CAACnC,IAAsC,EAAEL,MAAoB,EAAE;IAClF,OAAO,MAAMlB,KAAK,CAACK,GAAG,CAACiB,IAAI,CAAoC;MAC7DZ,IAAI,EAAE,mBAAmB;MACzBG,OAAO,EAAEhB,UAAU,CAAC,CAAC;MACrB0B,IAAI,EAAE;QACJX,SAAS,EAAEpB,iBAAiB,CAACQ,KAAK,CAACY,SAAS;QAC5C+C,WAAW,EAAE;UACX,GAAGpC;QACL;MACF,CAAC;MACDL;IACF,CAAC,CAAC;EACJ,CAAC;EAED0C,WAAWA,CAACxD,QAAuB,EAAE;IACnCJ,KAAK,CAACI,QAAQ,GAAGA,QAAQ;IACzBJ,KAAK,CAACK,GAAG,GAAG,IAAId,SAAS,CAAC;MAAEI,OAAO;MAAES;IAAS,CAAC,CAAC;EAClD;AACF,CAAC"}
|
|
@@ -27,13 +27,13 @@ export const ConnectorController = {
|
|
|
27
27
|
getAuthConnector() {
|
|
28
28
|
return state.connectors.find(c => c.type === 'AUTH');
|
|
29
29
|
},
|
|
30
|
-
setConnectedConnector(connectorType, saveStorage = true) {
|
|
30
|
+
async setConnectedConnector(connectorType, saveStorage = true) {
|
|
31
31
|
state.connectedConnector = connectorType;
|
|
32
32
|
if (saveStorage) {
|
|
33
33
|
if (connectorType) {
|
|
34
|
-
StorageUtil.setConnectedConnector(connectorType);
|
|
34
|
+
await StorageUtil.setConnectedConnector(connectorType);
|
|
35
35
|
} else {
|
|
36
|
-
StorageUtil.removeConnectedConnector();
|
|
36
|
+
await StorageUtil.removeConnectedConnector();
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["subscribeKey","subKey","proxy","ref","StorageUtil","state","connectors","ConnectorController","key","callback","setConnectors","map","c","addConnector","connector","getConnectors","getAuthConnector","find","type","setConnectedConnector","connectorType","saveStorage","connectedConnector","removeConnectedConnector","setAuthLoading","loading","authLoading"],"sourceRoot":"../../../src","sources":["controllers/ConnectorController.ts"],"mappings":"AACA,SAASA,YAAY,IAAIC,MAAM,QAAQ,cAAc;AACrD,SAASC,KAAK,EAAEC,GAAG,QAAQ,QAAQ;AAEnC,SAASC,WAAW,QAAQ,sBAAsB;;AAElD;;AASA;AACA,MAAMC,KAAK,GAAGH,KAAK,CAA2B;EAC5CI,UAAU,EAAE;AACd,CAAC,CAAC;;AAEF;AACA,OAAO,MAAMC,mBAAmB,GAAG;EACjCF,KAAK;EAELL,YAAYA,CAAqBQ,GAAM,EAAEC,QAAsD,EAAE;IAC/F,OAAOR,MAAM,CAACI,KAAK,EAAEG,GAAG,EAAEC,QAAQ,CAAC;EACrC,CAAC;EAEDC,aAAaA,CAACJ,UAAkD,EAAE;IAChED,KAAK,CAACC,UAAU,GAAGA,UAAU,CAACK,GAAG,CAACC,CAAC,IAAIT,GAAG,CAACS,CAAC,CAAC,CAAC;EAChD,CAAC;EAEDC,YAAYA,CAACC,SAAoB,EAAE;IACjCT,KAAK,CAACC,UAAU,GAAG,CAAC,GAAGD,KAAK,CAACC,UAAU,EAAEH,GAAG,CAACW,SAAS,CAAC,CAAC;EAC1D,CAAC;EAEDC,aAAaA,CAAA,EAAG;IACd,OAAOV,KAAK,CAACC,UAAU;EACzB,CAAC;EAEDU,gBAAgBA,CAAA,EAAG;IACjB,OAAOX,KAAK,CAACC,UAAU,CAACW,IAAI,CAACL,CAAC,IAAIA,CAAC,CAACM,IAAI,KAAK,MAAM,CAAC;EACtD,CAAC;
|
|
1
|
+
{"version":3,"names":["subscribeKey","subKey","proxy","ref","StorageUtil","state","connectors","ConnectorController","key","callback","setConnectors","map","c","addConnector","connector","getConnectors","getAuthConnector","find","type","setConnectedConnector","connectorType","saveStorage","connectedConnector","removeConnectedConnector","setAuthLoading","loading","authLoading"],"sourceRoot":"../../../src","sources":["controllers/ConnectorController.ts"],"mappings":"AACA,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KAAK,CAACqB,WAAW,GAAGD,OAAO;EAC7B;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["proxy","AccountController","RouterController","PublicStateController","EventsController","ApiController","ConnectorController","state","open","loading","ModalController","options","prefetchPromise","connected","isConnected","view","reset","isUniversalWallet","connectedConnector","set","sendEvent","type","event","properties","close","setLoading"],"sourceRoot":"../../../src","sources":["controllers/ModalController.ts"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAC9B,SAASC,iBAAiB,QAAQ,qBAAqB;
|
|
1
|
+
{"version":3,"names":["proxy","AccountController","RouterController","PublicStateController","EventsController","ApiController","ConnectorController","state","open","loading","ModalController","options","prefetchPromise","connected","isConnected","view","reset","isUniversalWallet","connectedConnector","set","sendEvent","type","event","properties","close","setLoading"],"sourceRoot":"../../../src","sources":["controllers/ModalController.ts"],"mappings":"AAAA,SAASA,KAAK,QAAQ,QAAQ;AAC9B,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAAoC,oBAAoB;AACjF,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,mBAAmB,QAAQ,uBAAuB;;AAE3D;;AAYA;AACA,MAAMC,KAAK,GAAGP,KAAK,CAAuB;EACxCQ,IAAI,EAAE,KAAK;EACXC,OAAO,EAAE;AACX,CAAC,CAAC;;AAEF;AACA,OAAO,MAAMC,eAAe,GAAG;EAC7BH,KAAK;EAEL,MAAMC,IAAIA,CAACG,OAA0C,EAAE;IACrD,MAAMN,aAAa,CAACE,KAAK,CAACK,eAAe;IACzC,MAAMC,SAAS,GAAGZ,iBAAiB,CAACM,KAAK,CAACO,WAAW;IACrD,IAAIH,OAAO,EAAEI,IAAI,EAAE;MACjBb,gBAAgB,CAACc,KAAK,CAACL,OAAO,CAACI,IAAI,CAAC;IACtC,CAAC,MAAM,IAAId,iBAAiB,CAACM,KAAK,CAACO,WAAW,EAAE;MAC9C,MAAMG,iBAAiB,GAAGX,mBAAmB,CAACC,KAAK,CAACW,kBAAkB,KAAK,MAAM;MACjFhB,gBAAgB,CAACc,KAAK,CAACC,iBAAiB,GAAG,SAAS,GAAG,gBAAgB,CAAC;IAC1E,CAAC,MAAM;MACLf,gBAAgB,CAACc,KAAK,CAAC,SAAS,CAAC;IACnC;IACAT,KAAK,CAACC,IAAI,GAAG,IAAI;IACjBL,qBAAqB,CAACgB,GAAG,CAAC;MAAEX,IAAI,EAAE;IAAK,CAAC,CAAC;IACzCJ,gBAAgB,CAACgB,SAAS,CAAC;MACzBC,IAAI,EAAE,OAAO;MACbC,KAAK,EAAE,YAAY;MACnBC,UAAU,EAAE;QAAEV;MAAU;IAC1B,CAAC,CAAC;EACJ,CAAC;EAEDW,KAAKA,CAAA,EAAG;IACN,MAAMX,SAAS,GAAGZ,iBAAiB,CAACM,KAAK,CAACO,WAAW;IACrDP,KAAK,CAACC,IAAI,GAAG,KAAK;IAClBL,qBAAqB,CAACgB,GAAG,CAAC;MAAEX,IAAI,EAAE;IAAM,CAAC,CAAC;IAC1CJ,gBAAgB,CAACgB,SAAS,CAAC;MACzBC,IAAI,EAAE,OAAO;MACbC,KAAK,EAAE,aAAa;MACpBC,UAAU,EAAE;QAAEV;MAAU;IAC1B,CAAC,CAAC;EACJ,CAAC;EAEDY,UAAUA,CAAChB,OAAwC,EAAE;IACnDF,KAAK,CAACE,OAAO,GAAGA,OAAO;EACzB;AACF,CAAC"}
|
|
@@ -50,8 +50,8 @@ export const NetworkController = {
|
|
|
50
50
|
}
|
|
51
51
|
return Boolean(state.smartAccountEnabledNetworks?.includes(Number(networkId)));
|
|
52
52
|
},
|
|
53
|
-
async getApprovedCaipNetworksData() {
|
|
54
|
-
const data = await this._getClient().getApprovedCaipNetworksData();
|
|
53
|
+
async getApprovedCaipNetworksData(connectorType) {
|
|
54
|
+
const data = await this._getClient().getApprovedCaipNetworksData(connectorType);
|
|
55
55
|
state.supportsAllNetworks = data.supportsAllNetworks;
|
|
56
56
|
state.approvedCaipNetworkIds = data.approvedCaipNetworkIds;
|
|
57
57
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["proxy","ref","PublicStateController","NetworkUtil","ConstantsUtil","state","supportsAllNetworks","isDefaultCaipNetwork","smartAccountEnabledNetworks","NetworkController","_getClient","_client","Error","setClient","client","setCaipNetwork","caipNetwork","set","selectedNetworkId","id","setDefaultCaipNetwork","setRequestedCaipNetworks","requestedNetworks","requestedCaipNetworks","setSmartAccountEnabledNetworks","checkIfSmartAccountEnabled","networkId","caipNetworkIdToNumber","Boolean","includes","Number","getApprovedCaipNetworksData","data","approvedCaipNetworkIds","getApprovedCaipNetworks","map","find","network","filter","getSmartAccountEnabledNetworks","getActiveNetworkTokenAddress","chainId","address","NATIVE_TOKEN_ADDRESS","switchActiveNetwork","switchCaipNetwork","resetNetwork","undefined"],"sourceRoot":"../../../src","sources":["controllers/NetworkController.ts"],"mappings":"AAAA,SAASA,KAAK,EAAEC,GAAG,QAAQ,QAAQ;AAEnC,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,WAAW,
|
|
1
|
+
{"version":3,"names":["proxy","ref","PublicStateController","NetworkUtil","ConstantsUtil","state","supportsAllNetworks","isDefaultCaipNetwork","smartAccountEnabledNetworks","NetworkController","_getClient","_client","Error","setClient","client","setCaipNetwork","caipNetwork","set","selectedNetworkId","id","setDefaultCaipNetwork","setRequestedCaipNetworks","requestedNetworks","requestedCaipNetworks","setSmartAccountEnabledNetworks","checkIfSmartAccountEnabled","networkId","caipNetworkIdToNumber","Boolean","includes","Number","getApprovedCaipNetworksData","connectorType","data","approvedCaipNetworkIds","getApprovedCaipNetworks","map","find","network","filter","getSmartAccountEnabledNetworks","getActiveNetworkTokenAddress","chainId","address","NATIVE_TOKEN_ADDRESS","switchActiveNetwork","switchCaipNetwork","resetNetwork","undefined"],"sourceRoot":"../../../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AQ,IAAGC,OAAQ,EAAC;EAChC,CAAC;EAED,MAAME,mBAAmBA,CAACP,OAA8C,EAAE;IACxE,MAAM,IAAI,CAAC5B,UAAU,CAAC,CAAC,CAACoC,iBAAiB,CAACR,OAAO,CAAC;IAClDjC,KAAK,CAACW,WAAW,GAAGsB,OAAO;IAC3BpC,qBAAqB,CAACe,GAAG,CAAC;MAAEC,iBAAiB,EAAEoB,OAAO,EAAEnB;IAAG,CAAC,CAAC;EAC/D,CAAC;EAED4B,YAAYA,CAAA,EAAG;IACb,IAAI,CAAC1C,KAAK,CAACE,oBAAoB,EAAE;MAC/BF,KAAK,CAACW,WAAW,GAAGgC,SAAS;IAC/B;IACA3C,KAAK,CAAC6B,sBAAsB,GAAGc,SAAS;IACxC3C,KAAK,CAACC,mBAAmB,GAAG,IAAI;IAChCD,KAAK,CAACG,2BAA2B,GAAG,EAAE;EACxC;AACF,CAAC"}
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import { subscribeKey as subKey } from 'valtio/vanilla/utils';
|
|
2
|
+
import { proxy, subscribe as sub } from 'valtio/vanilla';
|
|
3
|
+
import { BlockchainOnRampError } from '../utils/TypeUtil';
|
|
4
|
+
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
5
|
+
import { NetworkController } from './NetworkController';
|
|
6
|
+
import { AccountController } from './AccountController';
|
|
7
|
+
import { OptionsController } from './OptionsController';
|
|
8
|
+
import { ConstantsUtil, OnRampErrorType } from '../utils/ConstantsUtil';
|
|
9
|
+
import { StorageUtil } from '../utils/StorageUtil';
|
|
10
|
+
import { SnackController } from './SnackController';
|
|
11
|
+
import { EventsController } from './EventsController';
|
|
12
|
+
import { BlockchainApiController, EXCLUDED_ONRAMP_PROVIDERS } from './BlockchainApiController';
|
|
13
|
+
|
|
14
|
+
// -- Helpers ------------------------------------------- //
|
|
15
|
+
|
|
16
|
+
let quotesAbortController = null;
|
|
17
|
+
|
|
18
|
+
// -- Utils --------------------------------------------- //
|
|
19
|
+
|
|
20
|
+
const mapErrorMessage = errorCode => {
|
|
21
|
+
const errorMap = {
|
|
22
|
+
[OnRampErrorType.AMOUNT_TOO_LOW]: {
|
|
23
|
+
type: OnRampErrorType.AMOUNT_TOO_LOW,
|
|
24
|
+
message: 'The amount is too low'
|
|
25
|
+
},
|
|
26
|
+
[OnRampErrorType.AMOUNT_TOO_HIGH]: {
|
|
27
|
+
type: OnRampErrorType.AMOUNT_TOO_HIGH,
|
|
28
|
+
message: 'The amount is too high'
|
|
29
|
+
},
|
|
30
|
+
[OnRampErrorType.INVALID_AMOUNT]: {
|
|
31
|
+
type: OnRampErrorType.INVALID_AMOUNT,
|
|
32
|
+
message: 'Enter a valid amount'
|
|
33
|
+
},
|
|
34
|
+
[OnRampErrorType.INCOMPATIBLE_REQUEST]: {
|
|
35
|
+
type: OnRampErrorType.INCOMPATIBLE_REQUEST,
|
|
36
|
+
message: 'Enter a valid amount'
|
|
37
|
+
},
|
|
38
|
+
[OnRampErrorType.BAD_REQUEST]: {
|
|
39
|
+
type: OnRampErrorType.BAD_REQUEST,
|
|
40
|
+
message: 'Enter a valid amount'
|
|
41
|
+
},
|
|
42
|
+
[OnRampErrorType.NO_VALID_QUOTES]: {
|
|
43
|
+
type: OnRampErrorType.NO_VALID_QUOTES,
|
|
44
|
+
message: 'No quotes available'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return errorMap[errorCode] || {
|
|
48
|
+
type: OnRampErrorType.UNKNOWN,
|
|
49
|
+
message: 'Something went wrong. Please try again'
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// -- Types --------------------------------------------- //
|
|
54
|
+
|
|
55
|
+
const defaultState = {
|
|
56
|
+
quotesLoading: false,
|
|
57
|
+
countries: [],
|
|
58
|
+
paymentMethods: [],
|
|
59
|
+
serviceProviders: [],
|
|
60
|
+
paymentAmount: undefined
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// -- State --------------------------------------------- //
|
|
64
|
+
const state = proxy(defaultState);
|
|
65
|
+
|
|
66
|
+
// -- Controller ---------------------------------------- //
|
|
67
|
+
export const OnRampController = {
|
|
68
|
+
state,
|
|
69
|
+
subscribe(callback) {
|
|
70
|
+
return sub(state, () => callback(state));
|
|
71
|
+
},
|
|
72
|
+
subscribeKey(key, callback) {
|
|
73
|
+
return subKey(state, key, callback);
|
|
74
|
+
},
|
|
75
|
+
async setSelectedCountry(country, updateCurrency = true) {
|
|
76
|
+
try {
|
|
77
|
+
state.selectedCountry = country;
|
|
78
|
+
state.loading = true;
|
|
79
|
+
if (updateCurrency) {
|
|
80
|
+
const currencyCode = state.countriesDefaults?.find(d => d.countryCode === country.countryCode)?.defaultCurrencyCode || 'USD';
|
|
81
|
+
const currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
|
|
82
|
+
if (currency) {
|
|
83
|
+
this.setPaymentCurrency(currency);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await Promise.all([this.fetchPaymentMethods(), this.fetchCryptoCurrencies()]);
|
|
87
|
+
this.clearQuotes();
|
|
88
|
+
state.loading = false;
|
|
89
|
+
StorageUtil.setOnRampPreferredCountry(country);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
state.loading = false;
|
|
92
|
+
state.error = {
|
|
93
|
+
type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
|
|
94
|
+
message: 'Failed to load countries'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
setSelectedPaymentMethod(paymentMethod) {
|
|
99
|
+
state.selectedPaymentMethod = paymentMethod;
|
|
100
|
+
},
|
|
101
|
+
setPurchaseCurrency(currency) {
|
|
102
|
+
state.purchaseCurrency = currency;
|
|
103
|
+
EventsController.sendEvent({
|
|
104
|
+
type: 'track',
|
|
105
|
+
event: 'SELECT_BUY_ASSET',
|
|
106
|
+
properties: {
|
|
107
|
+
asset: currency.currencyCode
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
this.clearQuotes();
|
|
111
|
+
},
|
|
112
|
+
setPaymentCurrency(currency, updateAmount = true) {
|
|
113
|
+
state.paymentCurrency = currency;
|
|
114
|
+
StorageUtil.setOnRampPreferredFiatCurrency(currency);
|
|
115
|
+
if (updateAmount) {
|
|
116
|
+
state.paymentAmount = undefined;
|
|
117
|
+
}
|
|
118
|
+
this.clearQuotes();
|
|
119
|
+
this.clearError();
|
|
120
|
+
},
|
|
121
|
+
setPaymentAmount(amount) {
|
|
122
|
+
state.paymentAmount = amount ? Number(amount) : undefined;
|
|
123
|
+
},
|
|
124
|
+
setSelectedQuote(quote) {
|
|
125
|
+
state.selectedQuote = quote;
|
|
126
|
+
},
|
|
127
|
+
updateSelectedPurchaseCurrency() {
|
|
128
|
+
let selectedCurrency;
|
|
129
|
+
if (NetworkController.state.caipNetwork?.id) {
|
|
130
|
+
const defaultCurrency = ConstantsUtil.NETWORK_DEFAULT_CURRENCIES[NetworkController.state.caipNetwork?.id];
|
|
131
|
+
selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
|
|
132
|
+
}
|
|
133
|
+
state.purchaseCurrency = selectedCurrency ?? state.purchaseCurrencies?.[0] ?? undefined;
|
|
134
|
+
},
|
|
135
|
+
getServiceProviderImage(serviceProviderName) {
|
|
136
|
+
if (!serviceProviderName) return undefined;
|
|
137
|
+
const provider = state.serviceProviders.find(p => p.serviceProvider === serviceProviderName);
|
|
138
|
+
return provider?.logos?.lightShort;
|
|
139
|
+
},
|
|
140
|
+
getCurrencyLimit(currency) {
|
|
141
|
+
return state.paymentCurrenciesLimits?.find(l => l.currencyCode === currency.currencyCode);
|
|
142
|
+
},
|
|
143
|
+
async fetchCountries() {
|
|
144
|
+
try {
|
|
145
|
+
let countries = await StorageUtil.getOnRampCountries();
|
|
146
|
+
if (!countries.length) {
|
|
147
|
+
countries = (await BlockchainApiController.fetchOnRampCountries()) ?? [];
|
|
148
|
+
if (countries.length) {
|
|
149
|
+
StorageUtil.setOnRampCountries(countries);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
state.countries = countries;
|
|
153
|
+
const preferredCountry = await StorageUtil.getOnRampPreferredCountry();
|
|
154
|
+
if (preferredCountry) {
|
|
155
|
+
state.selectedCountry = preferredCountry;
|
|
156
|
+
} else {
|
|
157
|
+
const countryCode = CoreHelperUtil.getCountryFromTimezone();
|
|
158
|
+
state.selectedCountry = countries.find(c => c.countryCode === countryCode) || countries[0] || undefined;
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
state.error = {
|
|
162
|
+
type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
|
|
163
|
+
message: 'Failed to load countries'
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
async fetchCountriesDefaults() {
|
|
168
|
+
try {
|
|
169
|
+
let countriesDefaults = await StorageUtil.getOnRampCountriesDefaults();
|
|
170
|
+
if (!countriesDefaults.length) {
|
|
171
|
+
countriesDefaults = (await BlockchainApiController.fetchOnRampCountriesDefaults()) ?? [];
|
|
172
|
+
if (countriesDefaults.length) {
|
|
173
|
+
StorageUtil.setOnRampCountriesDefaults(countriesDefaults);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
state.countriesDefaults = countriesDefaults;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
state.error = {
|
|
179
|
+
type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
|
|
180
|
+
message: 'Failed to load countries defaults'
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
async fetchServiceProviders() {
|
|
185
|
+
try {
|
|
186
|
+
let serviceProviders = await StorageUtil.getOnRampServiceProviders();
|
|
187
|
+
if (!serviceProviders.length) {
|
|
188
|
+
serviceProviders = (await BlockchainApiController.fetchOnRampServiceProviders()) ?? [];
|
|
189
|
+
if (serviceProviders.length) {
|
|
190
|
+
StorageUtil.setOnRampServiceProviders(serviceProviders);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
state.serviceProviders = serviceProviders || [];
|
|
194
|
+
} catch (error) {
|
|
195
|
+
state.error = {
|
|
196
|
+
type: OnRampErrorType.FAILED_TO_LOAD_PROVIDERS,
|
|
197
|
+
message: 'Failed to load service providers'
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
async fetchPaymentMethods() {
|
|
202
|
+
try {
|
|
203
|
+
const paymentMethods = await BlockchainApiController.fetchOnRampPaymentMethods({
|
|
204
|
+
countries: state.selectedCountry?.countryCode
|
|
205
|
+
});
|
|
206
|
+
const defaultCountryPaymentMethods = state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)?.defaultPaymentMethods || [];
|
|
207
|
+
state.paymentMethods = paymentMethods?.sort((a, b) => {
|
|
208
|
+
const aIndex = defaultCountryPaymentMethods?.indexOf(a.paymentMethod);
|
|
209
|
+
const bIndex = defaultCountryPaymentMethods?.indexOf(b.paymentMethod);
|
|
210
|
+
if (aIndex === -1 && bIndex === -1) return 0;
|
|
211
|
+
if (aIndex === -1) return 1;
|
|
212
|
+
if (bIndex === -1) return -1;
|
|
213
|
+
return aIndex - bIndex;
|
|
214
|
+
}) || [];
|
|
215
|
+
state.selectedPaymentMethod = state.paymentMethods[0];
|
|
216
|
+
} catch (error) {
|
|
217
|
+
state.error = {
|
|
218
|
+
type: OnRampErrorType.FAILED_TO_LOAD_METHODS,
|
|
219
|
+
message: 'Failed to load payment methods'
|
|
220
|
+
};
|
|
221
|
+
state.paymentMethods = [];
|
|
222
|
+
state.selectedPaymentMethod = undefined;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
async fetchCryptoCurrencies() {
|
|
226
|
+
try {
|
|
227
|
+
const cryptoCurrencies = await BlockchainApiController.fetchOnRampCryptoCurrencies({
|
|
228
|
+
countries: state.selectedCountry?.countryCode
|
|
229
|
+
});
|
|
230
|
+
state.purchaseCurrencies = cryptoCurrencies || [];
|
|
231
|
+
let selectedCurrency;
|
|
232
|
+
if (NetworkController.state.caipNetwork?.id) {
|
|
233
|
+
const defaultCurrency = ConstantsUtil.NETWORK_DEFAULT_CURRENCIES[NetworkController.state.caipNetwork?.id] || 'ETH';
|
|
234
|
+
selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
|
|
235
|
+
}
|
|
236
|
+
state.purchaseCurrency = selectedCurrency || cryptoCurrencies?.[0] || undefined;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
state.error = {
|
|
239
|
+
type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
|
|
240
|
+
message: 'Failed to load crypto currencies'
|
|
241
|
+
};
|
|
242
|
+
state.purchaseCurrencies = [];
|
|
243
|
+
state.purchaseCurrency = undefined;
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
async fetchFiatCurrencies() {
|
|
247
|
+
try {
|
|
248
|
+
let fiatCurrencies = await StorageUtil.getOnRampFiatCurrencies();
|
|
249
|
+
let currencyCode = 'USD';
|
|
250
|
+
const countryCode = state.selectedCountry?.countryCode;
|
|
251
|
+
if (!fiatCurrencies.length) {
|
|
252
|
+
fiatCurrencies = (await BlockchainApiController.fetchOnRampFiatCurrencies()) ?? [];
|
|
253
|
+
if (fiatCurrencies.length) {
|
|
254
|
+
StorageUtil.setOnRampFiatCurrencies(fiatCurrencies);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
state.paymentCurrencies = fiatCurrencies || [];
|
|
258
|
+
if (countryCode) {
|
|
259
|
+
currencyCode = state.countriesDefaults?.find(d => d.countryCode === countryCode)?.defaultCurrencyCode || 'USD';
|
|
260
|
+
}
|
|
261
|
+
const preferredCurrency = await StorageUtil.getOnRampPreferredFiatCurrency();
|
|
262
|
+
const defaultCurrency = preferredCurrency || fiatCurrencies?.find(c => c.currencyCode === currencyCode) || fiatCurrencies?.[0] || undefined;
|
|
263
|
+
if (defaultCurrency) {
|
|
264
|
+
this.setPaymentCurrency(defaultCurrency);
|
|
265
|
+
}
|
|
266
|
+
} catch (error) {
|
|
267
|
+
state.error = {
|
|
268
|
+
type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
|
|
269
|
+
message: 'Failed to load fiat currencies'
|
|
270
|
+
};
|
|
271
|
+
state.paymentCurrencies = [];
|
|
272
|
+
state.paymentCurrency = undefined;
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
abortGetQuotes(clearState = true) {
|
|
276
|
+
if (quotesAbortController) {
|
|
277
|
+
quotesAbortController.abort();
|
|
278
|
+
quotesAbortController = null;
|
|
279
|
+
}
|
|
280
|
+
if (clearState) {
|
|
281
|
+
this.clearQuotes();
|
|
282
|
+
state.quotesLoading = false;
|
|
283
|
+
state.error = undefined;
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
async getQuotes() {
|
|
287
|
+
if (!this.canGenerateQuote()) {
|
|
288
|
+
this.clearQuotes();
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
this.abortGetQuotes(false);
|
|
292
|
+
quotesAbortController = new AbortController();
|
|
293
|
+
const currentSignal = quotesAbortController.signal;
|
|
294
|
+
try {
|
|
295
|
+
if (!state.selectedCountry?.countryCode || !state.purchaseCurrency?.currencyCode || !state.paymentCurrency?.currencyCode || !AccountController.state.address) {
|
|
296
|
+
throw new BlockchainOnRampError(OnRampErrorType.UNKNOWN, 'Invalid quote parameters');
|
|
297
|
+
}
|
|
298
|
+
state.quotesLoading = true;
|
|
299
|
+
state.selectedQuote = undefined;
|
|
300
|
+
state.selectedServiceProvider = undefined;
|
|
301
|
+
state.error = undefined;
|
|
302
|
+
const body = {
|
|
303
|
+
countryCode: state.selectedCountry.countryCode,
|
|
304
|
+
destinationCurrencyCode: state.purchaseCurrency.currencyCode,
|
|
305
|
+
sourceAmount: state.paymentAmount,
|
|
306
|
+
sourceCurrencyCode: state.paymentCurrency.currencyCode,
|
|
307
|
+
walletAddress: AccountController.state.address,
|
|
308
|
+
excludeProviders: EXCLUDED_ONRAMP_PROVIDERS
|
|
309
|
+
};
|
|
310
|
+
const response = await BlockchainApiController.getOnRampQuotes(body, currentSignal);
|
|
311
|
+
if (!response || !response.length) {
|
|
312
|
+
throw new BlockchainOnRampError(OnRampErrorType.NO_VALID_QUOTES, 'No valid quotes');
|
|
313
|
+
}
|
|
314
|
+
const quotes = response.sort((a, b) => b.customerScore - a.customerScore);
|
|
315
|
+
state.quotes = quotes;
|
|
316
|
+
|
|
317
|
+
//Replace payment method if it's not in the quotes
|
|
318
|
+
const isValidPaymentMethod = state.selectedPaymentMethod && quotes.some(quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod);
|
|
319
|
+
if (!isValidPaymentMethod) {
|
|
320
|
+
const countryMethods = state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)?.defaultPaymentMethods || [];
|
|
321
|
+
const availableQuoteMethods = new Set(quotes.map(q => q.paymentMethodType));
|
|
322
|
+
let newPaymentMethodType;
|
|
323
|
+
for (const dpm of countryMethods) {
|
|
324
|
+
if (availableQuoteMethods.has(dpm)) {
|
|
325
|
+
newPaymentMethodType = dpm;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (newPaymentMethodType) {
|
|
330
|
+
state.selectedPaymentMethod = state.paymentMethods.find(m => m.paymentMethod === newPaymentMethodType) || state.paymentMethods.find(method => method.paymentMethod === quotes[0]?.paymentMethodType);
|
|
331
|
+
} else {
|
|
332
|
+
state.selectedPaymentMethod = state.paymentMethods.find(method => method.paymentMethod === quotes[0]?.paymentMethodType);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
state.selectedQuote = quotes.find(quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod);
|
|
336
|
+
state.selectedServiceProvider = state.serviceProviders.find(sp => sp.serviceProvider === state.selectedQuote?.serviceProvider);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error.name === 'AbortError') {
|
|
339
|
+
// Do nothing, another request was made
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
EventsController.sendEvent({
|
|
343
|
+
type: 'track',
|
|
344
|
+
event: 'BUY_FAIL',
|
|
345
|
+
properties: {
|
|
346
|
+
message: error?.message ?? error?.code ?? 'Error getting quotes'
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
this.clearQuotes();
|
|
350
|
+
state.error = mapErrorMessage(error?.code || 'UNKNOWN_ERROR');
|
|
351
|
+
} finally {
|
|
352
|
+
if (!currentSignal.aborted) {
|
|
353
|
+
state.quotesLoading = false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
canGenerateQuote() {
|
|
358
|
+
return !!(state.selectedCountry?.countryCode && state.selectedPaymentMethod?.paymentMethod && state.purchaseCurrency?.currencyCode && state.paymentAmount && state.paymentAmount > 0 && state.paymentCurrency?.currencyCode && state.selectedCountry && !state.loading && AccountController.state.address);
|
|
359
|
+
},
|
|
360
|
+
async fetchFiatLimits() {
|
|
361
|
+
try {
|
|
362
|
+
let limits = await StorageUtil.getOnRampFiatLimits();
|
|
363
|
+
if (!limits.length) {
|
|
364
|
+
limits = (await BlockchainApiController.fetchOnRampFiatLimits()) ?? [];
|
|
365
|
+
if (limits.length) {
|
|
366
|
+
StorageUtil.setOnRampFiatLimits(limits);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
state.paymentCurrenciesLimits = limits;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
state.error = {
|
|
372
|
+
type: OnRampErrorType.FAILED_TO_LOAD_LIMITS,
|
|
373
|
+
message: 'Failed to load fiat limits'
|
|
374
|
+
};
|
|
375
|
+
state.paymentCurrenciesLimits = [];
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
async generateWidget({
|
|
379
|
+
quote
|
|
380
|
+
}) {
|
|
381
|
+
const metadata = OptionsController.state.metadata;
|
|
382
|
+
const eventProperties = {
|
|
383
|
+
asset: quote.destinationCurrencyCode,
|
|
384
|
+
network: state.purchaseCurrency?.chainName ?? '',
|
|
385
|
+
amount: quote.destinationAmount.toString(),
|
|
386
|
+
currency: quote.destinationCurrencyCode,
|
|
387
|
+
paymentMethod: quote.paymentMethodType,
|
|
388
|
+
provider: 'MELD',
|
|
389
|
+
serviceProvider: quote.serviceProvider
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
if (!quote) {
|
|
393
|
+
throw new Error('Invalid quote');
|
|
394
|
+
}
|
|
395
|
+
const body = {
|
|
396
|
+
countryCode: quote.countryCode,
|
|
397
|
+
destinationCurrencyCode: quote.destinationCurrencyCode,
|
|
398
|
+
paymentMethodType: quote.paymentMethodType,
|
|
399
|
+
serviceProvider: quote.serviceProvider,
|
|
400
|
+
sourceAmount: quote.sourceAmount,
|
|
401
|
+
sourceCurrencyCode: quote.sourceCurrencyCode,
|
|
402
|
+
walletAddress: AccountController.state.address,
|
|
403
|
+
redirectUrl: metadata?.redirect?.universal ?? metadata?.redirect?.native
|
|
404
|
+
};
|
|
405
|
+
const widget = await BlockchainApiController.getOnRampWidget(body);
|
|
406
|
+
if (!widget || !widget.widgetUrl) {
|
|
407
|
+
throw new Error('Invalid widget response');
|
|
408
|
+
}
|
|
409
|
+
EventsController.sendEvent({
|
|
410
|
+
type: 'track',
|
|
411
|
+
event: 'BUY_SUBMITTED',
|
|
412
|
+
properties: eventProperties
|
|
413
|
+
});
|
|
414
|
+
state.widgetUrl = widget.widgetUrl;
|
|
415
|
+
return widget;
|
|
416
|
+
} catch (e) {
|
|
417
|
+
EventsController.sendEvent({
|
|
418
|
+
type: 'track',
|
|
419
|
+
event: 'BUY_FAIL',
|
|
420
|
+
properties: {
|
|
421
|
+
...eventProperties,
|
|
422
|
+
message: e?.message ?? e?.code ?? 'Error generating widget url'
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
state.error = mapErrorMessage(e?.code || 'UNKNOWN_ERROR');
|
|
426
|
+
SnackController.showInternalError({
|
|
427
|
+
shortMessage: 'Error creating purchase URL',
|
|
428
|
+
longMessage: e?.message ?? e?.code
|
|
429
|
+
});
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
clearError() {
|
|
434
|
+
state.error = undefined;
|
|
435
|
+
},
|
|
436
|
+
clearQuotes() {
|
|
437
|
+
state.quotes = [];
|
|
438
|
+
state.selectedQuote = undefined;
|
|
439
|
+
state.selectedServiceProvider = undefined;
|
|
440
|
+
},
|
|
441
|
+
async loadOnRampData() {
|
|
442
|
+
state.initialLoading = true;
|
|
443
|
+
state.error = undefined;
|
|
444
|
+
try {
|
|
445
|
+
await this.fetchCountries();
|
|
446
|
+
await this.fetchServiceProviders();
|
|
447
|
+
await Promise.all([this.fetchCountriesDefaults(), this.fetchPaymentMethods(), this.fetchFiatLimits(), this.fetchCryptoCurrencies(), this.fetchFiatCurrencies()]);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (!state.error) {
|
|
450
|
+
state.error = {
|
|
451
|
+
type: OnRampErrorType.FAILED_TO_LOAD,
|
|
452
|
+
message: 'Failed to load onramp data'
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
} finally {
|
|
456
|
+
state.initialLoading = false;
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
resetState() {
|
|
460
|
+
state.error = undefined;
|
|
461
|
+
state.quotesLoading = false;
|
|
462
|
+
state.quotes = [];
|
|
463
|
+
state.selectedQuote = undefined;
|
|
464
|
+
state.selectedServiceProvider = undefined;
|
|
465
|
+
state.widgetUrl = undefined;
|
|
466
|
+
state.paymentAmount = undefined;
|
|
467
|
+
this.updateSelectedPurchaseCurrency();
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
//# sourceMappingURL=OnRampController.js.map
|