This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wallet] Get history data depending on selected address using `Accoun…
…tAddressSelector` (#1838) - [x] Provide connected keystore / ledger addresses - [x] Extend `Address` to `WalletAddress` to provide more data (chain + type) - [x] Extract `WalletAddress` + `WalletType` to `shared/wallet/types` - [x] Request history data depending on selected address
- Loading branch information
Showing
77 changed files
with
451 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 5 additions & 22 deletions
27
src/renderer/components/AccountAddressSelector/AccountAddressSelector.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 59 additions & 41 deletions
100
src/renderer/components/AccountAddressSelector/AccountAddressSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,93 @@ | ||
import React, { useMemo } from 'react' | ||
|
||
import { Address } from '@xchainjs/xchain-client' | ||
import { Chain } from '@xchainjs/xchain-util' | ||
import { Dropdown } from 'antd' | ||
import * as A from 'fp-ts/lib/Array' | ||
import * as FP from 'fp-ts/lib/function' | ||
import * as O from 'fp-ts/lib/Option' | ||
import { useIntl } from 'react-intl' | ||
|
||
import { Network } from '../../../shared/api/types' | ||
import { isLedgerWallet } from '../../../shared/utils/guard' | ||
import { WalletAddress, WalletAddresses } from '../../../shared/wallet/types' | ||
import { truncateAddress } from '../../helpers/addressHelper' | ||
import { getChainAsset } from '../../helpers/chainHelper' | ||
import { eqString } from '../../helpers/fp/eq' | ||
import { WalletType } from '../../services/wallet/types' | ||
import { eqWalletAddress } from '../../helpers/fp/eq' | ||
import { walletTypeToI18n } from '../../services/wallet/util' | ||
import { AssetIcon } from '../uielements/assets/assetIcon/AssetIcon' | ||
import { Size as IconSize } from '../uielements/assets/assetIcon/AssetIcon.types' | ||
import { WalletTypeLabel } from '../uielements/common/Common.styles' | ||
import * as Styled from './AccountAddressSelector.styles' | ||
|
||
export type WalletAddress = { | ||
walletAddress: Address | ||
walletType: WalletType | ||
chain: Chain | ||
} | ||
|
||
type Props = { | ||
selectedAddress: WalletAddress | ||
addresses: WalletAddress[] | ||
selectedAddress: O.Option<WalletAddress> | ||
addresses: WalletAddresses | ||
size?: IconSize | ||
network: Network | ||
onChangeAddress?: (address: Address) => void | ||
onChangeAddress?: (address: WalletAddress) => void | ||
} | ||
|
||
export const AccountAddressSelector: React.FC<Props> = (props) => { | ||
const { selectedAddress, addresses, size = 'small', network, onChangeAddress = FP.constVoid } = props | ||
const { | ||
selectedAddress: oSelectedAddress, | ||
addresses, | ||
size = 'small', | ||
network, | ||
onChangeAddress = FP.constVoid | ||
} = props | ||
|
||
const intl = useIntl() | ||
const truncatedAddress = useMemo( | ||
() => truncateAddress(selectedAddress.walletAddress, selectedAddress.chain, network), | ||
[network, selectedAddress.chain, selectedAddress.walletAddress] | ||
) | ||
|
||
const menu = useMemo( | ||
() => ( | ||
const menu = useMemo(() => { | ||
const highlight = (address: WalletAddress) => | ||
FP.pipe( | ||
oSelectedAddress, | ||
O.fold( | ||
() => false, | ||
(selectedAddress) => eqWalletAddress.equals(address, selectedAddress) | ||
) | ||
) | ||
|
||
return ( | ||
<Styled.Menu> | ||
{addresses.map(({ walletAddress, walletType, chain }) => ( | ||
<Styled.MenuItem key={walletAddress} onClick={() => onChangeAddress(walletAddress)}> | ||
<Styled.MenuItemWrapper highlighted={eqString.equals(selectedAddress.walletAddress, walletAddress)}> | ||
<Styled.AssetIcon asset={getChainAsset(chain)} size={size} network={network} /> | ||
<Styled.WalletAddress>{walletAddress}</Styled.WalletAddress> | ||
{isLedgerWallet(walletType) && ( | ||
<Styled.WalletTypeLabel>{walletTypeToI18n(walletType, intl)}</Styled.WalletTypeLabel> | ||
)} | ||
</Styled.MenuItemWrapper> | ||
</Styled.MenuItem> | ||
))} | ||
{FP.pipe( | ||
addresses, | ||
A.map((walletAddress) => { | ||
const { address, type, chain } = walletAddress | ||
return ( | ||
<Styled.MenuItem key={address} onClick={() => onChangeAddress(walletAddress)}> | ||
<Styled.MenuItemWrapper key={address} highlighted={highlight(walletAddress)}> | ||
<Styled.AssetIcon asset={getChainAsset(chain)} size={size} network={network} /> | ||
<Styled.WalletAddress>{address}</Styled.WalletAddress> | ||
{isLedgerWallet(type) && ( | ||
<Styled.WalletTypeLabel>{walletTypeToI18n(type, intl)}</Styled.WalletTypeLabel> | ||
)} | ||
</Styled.MenuItemWrapper> | ||
</Styled.MenuItem> | ||
) | ||
}) | ||
)} | ||
</Styled.Menu> | ||
), | ||
[addresses, intl, network, onChangeAddress, selectedAddress.walletAddress, size] | ||
) | ||
}, [addresses, intl, network, oSelectedAddress, onChangeAddress, size]) | ||
|
||
const renderSelectedAddress = FP.pipe( | ||
oSelectedAddress, | ||
O.fold( | ||
() => <></>, | ||
({ chain, type, address }) => ( | ||
<> | ||
<AssetIcon asset={getChainAsset(chain)} size={'xsmall'} network={network} /> | ||
<Styled.TruncatedAddress>{truncateAddress(address, chain, network)}</Styled.TruncatedAddress> | ||
{isLedgerWallet(type) && <WalletTypeLabel>{walletTypeToI18n(type, intl)}</WalletTypeLabel>} | ||
<Styled.CaretDownOutlined /> | ||
</> | ||
) | ||
) | ||
) | ||
|
||
return ( | ||
<Dropdown overlay={menu} trigger={['click']}> | ||
<Styled.DropdownSelectorWrapper> | ||
<AssetIcon asset={getChainAsset(selectedAddress.chain)} size={'xsmall'} network={network} /> | ||
<Styled.TruncatedAddress>{truncatedAddress}</Styled.TruncatedAddress> | ||
{isLedgerWallet(selectedAddress.walletType) && ( | ||
<WalletTypeLabel>{walletTypeToI18n(selectedAddress.walletType, intl)}</WalletTypeLabel> | ||
)} | ||
<Styled.CaretDownOutlined /> | ||
</Styled.DropdownSelectorWrapper> | ||
<Styled.DropdownSelectorWrapper>{renderSelectedAddress}</Styled.DropdownSelectorWrapper> | ||
</Dropdown> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.