pleroma/app/soapbox/features/crypto_donate/components/site_wallet.tsx

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-25 12:42:04 -07:00
import { trimStart } from 'lodash';
import React from 'react';
2022-03-25 15:47:19 -07:00
import { Stack } from 'soapbox/components/ui';
2022-03-25 12:42:04 -07:00
import { useSoapboxConfig } from 'soapbox/hooks';
import CryptoAddress from './crypto_address';
import type { Map as ImmutableMap, List as ImmutableList } from 'immutable';
type Address = ImmutableMap<string, any>;
// 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 {
2022-03-25 13:16:05 -07:00
limit?: number,
2022-03-25 12:42:04 -07:00
}
const SiteWallet: React.FC<ISiteWallet> = ({ limit }): JSX.Element => {
2022-03-25 13:16:05 -07:00
const addresses: ImmutableList<Address> =
2022-03-28 12:58:50 -07:00
useSoapboxConfig().cryptoAddresses.map(normalizeAddress);
2022-03-25 13:16:05 -07:00
const coinList = typeof limit === 'number' ? addresses.take(limit) : addresses;
2022-03-25 12:42:04 -07:00
return (
2022-03-25 15:47:19 -07:00
<Stack space={4}>
2022-03-25 12:42:04 -07:00
{coinList.map(coin => (
<CryptoAddress
key={coin.get('ticker')}
2022-03-25 14:55:48 -07:00
address={coin.get('address')}
ticker={coin.get('ticker')}
note={coin.get('note')}
2022-03-25 12:42:04 -07:00
/>
))}
2022-03-25 15:47:19 -07:00
</Stack>
2022-03-25 12:42:04 -07:00
);
};
export default SiteWallet;