Skip to content

Commit

Permalink
[web/hotfix] Use deprecated safePromiseAllV1
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo committed Oct 12, 2022
1 parent ae55c46 commit b556a9a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/bento-common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export { Base64 } from './Base64';
export { safePromiseAll, safeAsyncFlatMap } from './safer-promises';
export {
safePromiseAll,
safePromiseAllV1,
safeAsyncFlatMap,
} from './safer-promises';
export { shortenAddress } from './shortenAddress';
8 changes: 8 additions & 0 deletions packages/bento-common/utils/safer-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ export const safePromiseAll = async <T extends any>(promises: Promise<T>[]) =>
[] as T[],
);

/**
* @deprecated Might not work intended for 2D arrays
*/
export const safePromiseAllV1 = async <T extends any>(promises: Promise<T>[]) =>
(await Promise.allSettled(promises)).flatMap((res) =>
res.status === 'fulfilled' ? res.value : [],
);

export const safeAsyncFlatMap = async <T extends any, U extends any>(
array: T[],
callback: (value: T, index: number, array: T[]) => Promise<[] | U | U[]>,
Expand Down
14 changes: 7 additions & 7 deletions packages/bento-core/chains/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, safePromiseAll } from '@bento/common';
import { Config, safePromiseAllV1 } from '@bento/common';
import { JsonRpcProvider } from '@ethersproject/providers';
import * as web3 from '@solana/web3.js';
import axios, { Axios } from 'axios';
Expand Down Expand Up @@ -95,7 +95,7 @@ export class EthereumChain implements Chain {
price,
};
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down Expand Up @@ -170,7 +170,7 @@ export class BNBChain implements Chain {
price,
};
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down Expand Up @@ -245,7 +245,7 @@ export class PolygonChain implements Chain {
price,
};
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down Expand Up @@ -320,7 +320,7 @@ export class AvalancheChain implements Chain {
price,
};
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down Expand Up @@ -430,7 +430,7 @@ export class KlaytnChain implements Chain {
};
return balanceInfo;
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down Expand Up @@ -507,7 +507,7 @@ export class SolanaChain implements Chain {
price,
};
}) as Promise<TokenBalance>[];
return safePromiseAll(promises).then((items) => items.flat());
return safePromiseAllV1(promises);
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/bento-core/pricings/CoinMarketCap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, randomOf, safePromiseAll } from '@bento/common';
import { Config, randomOf, safePromiseAllV1 } from '@bento/common';
import axios from 'axios';
import queryString from 'query-string';

Expand Down Expand Up @@ -48,7 +48,7 @@ export const priceFromCoinMarketCap = withCache(

export const pricesFromCoinMarketCap = async (coinMarketCapIds: number[]) =>
(
await safePromiseAll(
await safePromiseAllV1(
coinMarketCapIds.map(async (coinMarketCapId) => {
const price = await priceFromCoinMarketCap(coinMarketCapId).catch(
() => 0,
Expand Down
4 changes: 2 additions & 2 deletions packages/bento-web/pages/api/defis/klaytn/[walletAddress].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { safeAsyncFlatMap, safePromiseAll } from '@bento/common';
import { safeAsyncFlatMap, safePromiseAllV1 } from '@bento/common';
import { getTokenBalancesFromCovalent } from '@bento/core';
import { getAddress, isAddress } from '@ethersproject/address';
import CompressedJSON from 'compressed-json';
Expand Down Expand Up @@ -224,7 +224,7 @@ const getDeFiStakingsByWalletAddress = async (
const promisesForDelegations = KlayStation.getDelegations(walletAddress);

const stakings = (
await Promise.all([
await safePromiseAllV1([
promisesForStakings.catch(handleError),
promisesForDelegations.catch(handleError),
])
Expand Down

1 comment on commit b556a9a

@vercel
Copy link

@vercel vercel bot commented on b556a9a Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.