Skip to content

Commit

Permalink
update axios to prevent interfering different versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Aug 13, 2023
1 parent 262ee00 commit ed72a7b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 22 deletions.
3 changes: 2 additions & 1 deletion api/chainik.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import axios from 'axios';
import {cacheAdapterEnhancer, Cache} from 'axios-extensions';
import {CHAINIK_API_URL, NETWORK, MAINNET} from "~/assets/variables.js";
import addToCamelInterceptor from '~/assets/axios-to-camel.js';
import {getDefaultAdapter} from '~/assets/axios-default-adapter.js';

const instance = axios.create({
baseURL: CHAINIK_API_URL,
adapter: cacheAdapterEnhancer(axios.defaults.adapter, { enabledByDefault: false}),
adapter: cacheAdapterEnhancer(getDefaultAdapter(), { enabledByDefault: false}),
});
addToCamelInterceptor(instance);

Expand Down
5 changes: 3 additions & 2 deletions api/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {getCoinIconList as getChainikIconList} from '~/api/chainik.js';
import {BASE_COIN, EXPLORER_API_URL, TX_STATUS} from '~/assets/variables.js';
import addToCamelInterceptor from '~/assets/axios-to-camel.js';
import {addTimeInterceptor} from '~/assets/axios-time-offset.js';
import preventConcurrencyAdapter from '~/assets/axios-prevent-concurrency.js';
import preventConcurrencyAdapter from 'axios-prevent-concurrency';
import debounceAdapter from '~/assets/axios-debounce.js';
import {getDefaultAdapter} from '~/assets/axios-default-adapter.js';


const coinBlockMap = Object.fromEntries(coinBlockList.map((symbol) => [symbol, true]));
Expand Down Expand Up @@ -44,7 +45,7 @@ function restoreErrorAdapter(adapter) {
};
}

const adapter = (($ = axios.defaults.adapter) => {
const adapter = (($ = getDefaultAdapter()) => {
$ = save404Adapter($);
$ = cacheAdapterEnhancer($, { enabledByDefault: false});
$ = restoreErrorAdapter($);
Expand Down
3 changes: 2 additions & 1 deletion api/gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {ReplaceCoinSymbol, ReplaceCoinSymbolByPath, GetCoinId} from 'minter-js-s
import GetCoinInfo from 'minter-js-sdk/src/api/get-coin-info.js';
import GetCommissionPrice from 'minter-js-sdk/src/api/get-commission-price.js';
import {GATE_API_URL, CHAIN_ID} from '~/assets/variables.js';
import {getDefaultAdapter} from '~/assets/axios-default-adapter.js';
import debounceAdapter from '~/assets/axios-debounce.js';
import {getSwapEstimate as explorerGetSwapEstimate} from '~/api/explorer.js';

const adapter = (($ = axios.defaults.adapter) => {
const adapter = (($ = getDefaultAdapter()) => {
$ = cacheAdapterEnhancer($, { enabledByDefault: false});
$ = debounceAdapter($, {time: 500, leading: false});
return $;
Expand Down
3 changes: 2 additions & 1 deletion api/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {getCoinList} from '~/api/explorer.js';
import Big from '~/assets/big.js';
import {HUB_API_URL, HUB_TRANSFER_STATUS, HUB_CHAIN_ID, HUB_NETWORK_SLUG, NETWORK, MAINNET, BASE_COIN, HUB_CHAIN_BY_ID, HUB_CHAIN_DATA} from "~/assets/variables.js";
import addToCamelInterceptor from '~/assets/axios-to-camel.js';
import {getDefaultAdapter} from '~/assets/axios-default-adapter.js';
import {isHubTransferFinished} from '~/assets/utils.js';

const instance = axios.create({
baseURL: HUB_API_URL,
adapter: cacheAdapterEnhancer(axios.defaults.adapter, { enabledByDefault: false}),
adapter: cacheAdapterEnhancer(getDefaultAdapter(), { enabledByDefault: false}),
});
addToCamelInterceptor(instance);

Expand Down
12 changes: 12 additions & 0 deletions assets/axios-default-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from 'axios';
import adapters from 'axios/lib/adapters/adapters.js';

const getAdapter = adapters.getAdapter;

/**
*
* @return {import('axios').AxiosAdapter}
*/
export function getDefaultAdapter() {
return getAdapter(axios.defaults.adapter);
}
1 change: 1 addition & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export default {
'@walletconnect/',
'@ethersproject/',
'jsbi', // @uniswap/sdk
'axios-prevent-concurrency/src',
'v-autosize/src',
'v-file-input/src',
'vue-inline-svg/src/',
Expand Down
35 changes: 19 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
"@walletconnect/ethereum-provider": "^2.9.2",
"@walletconnect/modal": "^2.6.1",
"aes-js": "^3.1.2",
"axios": "^0.27.2",
"axios": "^1.4.0",
"axios-extensions": "^3.1.7",
"axios-prevent-concurrency": "^0.0.3",
"big.js": "^6.2.1",
"camelcase-keys": "^7.0.2",
"centrifuge": "^2.8.5",
Expand Down

0 comments on commit ed72a7b

Please sign in to comment.