Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
useCurrenciesByMarketcapWithStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLaforge committed May 16, 2022
1 parent 5b012ce commit 9f5d182
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/currencies/sortByMarketcap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,36 @@ export const useCurrenciesByMarketcap = <C extends Currency>(
const tickers = useMarketcapTickers();
return tickers ? sortByMarketcap(currencies, tickers) : currencies;
};

type CurrenciesByMarketcapResult = {
loading: boolean;
error?: Error;
currencies?: any[];
};

export const useCurrenciesByMarketcapWithStatus = <C extends Currency>(
currencies: C[]
): CurrenciesByMarketcapResult => {
const [status, setStatus] = useState<CurrenciesByMarketcapResult>({
loading: false,
});

useEffect(() => {
function getCurrenciesByMarketcap() {
setStatus({ loading: true });
getMarketcapTickers()
.then((tickers) => {
setStatus({
loading: false,
currencies: sortByMarketcap(currencies, tickers),
});
})
.catch((error: Error) => {
setStatus({ loading: false, error, currencies });
});
}
getCurrenciesByMarketcap();
}, []);

return status;
};

1 comment on commit 9f5d182

@github-actions
Copy link

@github-actions github-actions bot commented on 9f5d182 May 16, 2022

Choose a reason for hiding this comment

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

Thanks for your contribution.
To be able to merge in develop branch, you need to:

  • pass the CI
  • have a dev review
  • have a QA review

Please sign in to comment.