From c8c2f40e38e789db1ac68b23f6cecc0832823f84 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 25 Mar 2022 14:42:04 -0500 Subject: [PATCH] SiteWallet: convert to tsx --- .../components/crypto_donate_panel.tsx | 22 +++--- .../crypto_donate/components/site_wallet.js | 67 ------------------- .../crypto_donate/components/site_wallet.tsx | 40 +++++++++++ 3 files changed, 51 insertions(+), 78 deletions(-) delete mode 100644 app/soapbox/features/crypto_donate/components/site_wallet.js create mode 100644 app/soapbox/features/crypto_donate/components/site_wallet.tsx diff --git a/app/soapbox/features/crypto_donate/components/crypto_donate_panel.tsx b/app/soapbox/features/crypto_donate/components/crypto_donate_panel.tsx index 6dd4fe946..52cbcaa74 100644 --- a/app/soapbox/features/crypto_donate/components/crypto_donate_panel.tsx +++ b/app/soapbox/features/crypto_donate/components/crypto_donate_panel.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { Link } from 'react-router-dom'; -import { Widget } from 'soapbox/components/ui'; +import { Text, Widget } from 'soapbox/components/ui'; import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks'; import SiteWallet from './site_wallet'; @@ -24,16 +24,16 @@ const CryptoDonatePanel: React.FC = ({ limit = 3 }): JSX.Ele return ( }> -
-
- -
- -
+ + + + + + {hasMore && { - return address.update('ticker', '', ticker => { - return trimStart(ticker, '$').toLowerCase(); - }); -}; - -const normalizeAddresses = addresses => addresses.map(normalizeAddress); - -const makeGetCoinList = () => { - return createSelector( - [(addresses, limit) => typeof limit === 'number' ? addresses.take(limit) : addresses], - addresses => normalizeAddresses(addresses), - ); -}; - -const makeMapStateToProps = () => { - const getCoinList = makeGetCoinList(); - - const mapStateToProps = (state, ownProps) => { - // Address example: - // {"ticker": "btc", "address": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n", "note": "This is our main address"} - const addresses = state.getIn(['soapbox', 'cryptoAddresses']); - const { limit } = ownProps; - - return { - coinList: getCoinList(addresses, limit), - }; - }; - - return mapStateToProps; -}; - -export default @connect(makeMapStateToProps) -class CoinList extends ImmutablePureComponent { - - static propTypes = { - coinList: ImmutablePropTypes.list, - limit: PropTypes.number, - } - - render() { - const { coinList } = this.props; - if (!coinList) return null; - - return ( -
- {coinList.map(coin => ( - - ))} -
- ); - } - -} diff --git a/app/soapbox/features/crypto_donate/components/site_wallet.tsx b/app/soapbox/features/crypto_donate/components/site_wallet.tsx new file mode 100644 index 000000000..dd11db5b2 --- /dev/null +++ b/app/soapbox/features/crypto_donate/components/site_wallet.tsx @@ -0,0 +1,40 @@ +import { trimStart } from 'lodash'; +import React from 'react'; + +import { useSoapboxConfig } from 'soapbox/hooks'; + +import CryptoAddress from './crypto_address'; + +import type { Map as ImmutableMap, List as ImmutableList } from 'immutable'; + +type Address = ImmutableMap; + +// Address example: +// {"ticker": "btc", "address": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n", "note": "This is our main address"} +const normalizeAddress = (address: Address): Address => { + return address.update('ticker', '', ticker => { + return trimStart(ticker, '$').toLowerCase(); + }); +}; + +interface ISiteWallet { + limit: number, +} + +const SiteWallet: React.FC = ({ limit }): JSX.Element => { + const addresses: ImmutableList
= useSoapboxConfig().get('cryptoAddresses'); + const coinList = addresses.map(normalizeAddress).take(limit); + + return ( +
+ {coinList.map(coin => ( + + ))} +
+ ); +}; + +export default SiteWallet;