Skip to content

Commit c5ac97f

Browse files
committed
use proxy
1 parent 1502d7c commit c5ac97f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

.storybook/stories/Introduction/demo.story.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,25 +395,34 @@ const ViewMarket = ({ marketData, item, isExpanded, onOpen, onClose }) => {
395395
);
396396
};
397397

398-
const queryCurrencies = ({ page, size, category }) => () => {
399-
let extra = '';
400-
if (category !== DEFAULT_CATEGORY) {
401-
extra = `category=${category}&`;
402-
}
398+
const onError = (error) => {
399+
console.log(error);
400+
console.log('local API may not be running');
401+
return [];
402+
};
403+
404+
export const queryCurrencies = ({ page, size, category }) => () => {
405+
const extra = category !== DEFAULT_CATEGORY ? `category=${category}&` : '';
403406

404407
return axios
405408
.get(
406-
`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&${extra}order=market_cap_desc&per_page=${size}&page=${page}&sparkline=true&price_change_percentage=1h%2C24h%2C7d%2C14d%2C30d%2C200d%2C1y`,
409+
`https://api.react-tables.com/?proxy=${btoa(
410+
`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&${extra}order=market_cap_desc&per_page=${size}&page=${page}&sparkline=true&price_change_percentage=1h%2C24h%2C7d%2C14d%2C30d%2C200d%2C1y`,
411+
)}`,
407412
)
408-
.then((result) => result.data);
413+
.then((result) => result.data)
414+
.catch(onError);
409415
};
410416

411-
const queryMarkets = (id) => () =>
417+
export const queryMarkets = (id) => () =>
412418
axios
413419
.get(
414-
`https://api.coingecko.com/api/v3/coins/${id}/tickers?per_page=5&page=1&include_exchange_logo=true`,
420+
`https://api.react-tables.com/?proxy=${btoa(
421+
`https://api.coingecko.com/api/v3/coins/${id}/tickers?per_page=5&page=1&include_exchange_logo=true`,
422+
)}`,
415423
)
416-
.then((res) => res.data);
424+
.then((res) => res.data)
425+
.catch(onError);
417426

418427
const Demo = () => {
419428
// dropdown
@@ -502,9 +511,9 @@ const Demo = () => {
502511

503512
React.useEffect(() => {
504513
pagination.fns.onSetPage(DEFAULT_PAGE);
505-
pagination.fns.onSetSize(50); // TODO
514+
pagination.fns.onSetSize(10); // TODO
506515
fetchCurrencies(
507-
{ page: DEFAULT_PAGE, size: 50, category: activeCategory },
516+
{ page: DEFAULT_PAGE, size: 10, category: activeCategory },
508517
{ overlayLoading: true },
509518
);
510519
}, [activeCategory]);

0 commit comments

Comments
 (0)