Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
[Deposit] Update UI to show pending assets (#1505)
Browse files Browse the repository at this point in the history
- [x] Show alert box in case of pending assets
- [x] Disable deposit form in case of pending assets
- [x] Reload data of pending assets by clicking "reload" button
- [x] Link to asgard.exchange to recover pending asset
- [x] Update i18n
  • Loading branch information
veado authored Jun 7, 2021
1 parent 82246e6 commit 8d7537b
Show file tree
Hide file tree
Showing 20 changed files with 449 additions and 127 deletions.
4 changes: 3 additions & 1 deletion src/main/api/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const EXTERNALS_WHITELIST = [
'ropsten.etherscan.io',
'tltc.bitaps.com',
'ltc.bitaps.com',
'www.blockchain.com'
'www.blockchain.com',
'testnet.asgard.exchange',
'asgard.exchange'
]

const openExternal = (target: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/deposit/Deposit.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const defaultProps: DepositProps = {
AsymDepositContent: AsymDeposit,
WidthdrawContent: Withdraw,
AsymWidthdrawContent: AsymWidthdraw,
keystoreState: O.some(O.some({ phrase: 'phrase' }))
keystoreState: O.some(O.some({ phrase: 'phrase' })),
liquidityProvider: RD.initial
}

export const Default: Story = () => <Deposit {...defaultProps} />
Expand Down
27 changes: 24 additions & 3 deletions src/renderer/components/deposit/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useIntl } from 'react-intl'

import { PoolDetailRD, PoolShareRD, PoolSharesRD } from '../../services/midgard/types'
import { getSharesByAssetAndType, combineSharesByAsset } from '../../services/midgard/utils'
import { LiquidityProviderRD } from '../../services/thorchain/types'
import { KeystoreState } from '../../services/wallet/types'
import { hasImportedKeystore, isLocked } from '../../services/wallet/util'
import { AssetWithDecimal } from '../../types/asgardex'
Expand Down Expand Up @@ -40,6 +41,7 @@ export type Props = {
haltedChains: Chain[]
asset: AssetWithDecimal
poolDetail: PoolDetailRD
liquidityProvider: LiquidityProviderRD
}>
WidthdrawContent: React.ComponentType<{
asset: AssetWithDecimal
Expand All @@ -54,6 +56,7 @@ export type Props = {
haltedChains: Chain[]
}>
keystoreState: KeystoreState
liquidityProvider: LiquidityProviderRD
}

export const Deposit: React.FC<Props> = (props) => {
Expand All @@ -69,9 +72,10 @@ export const Deposit: React.FC<Props> = (props) => {
// AsymWidthdrawContent,
keystoreState,
shares: poolSharesRD,
poolDetail: poolDetailRD
poolDetail: poolDetailRD,
// TODO (@asgdx-team) Think how to handle different wallets
// walletAddress: Address
liquidityProvider: liquidityProviderRD
} = props

const { asset } = assetWD
Expand Down Expand Up @@ -127,7 +131,14 @@ export const Deposit: React.FC<Props> = (props) => {
key: 'deposit-sym',
disabled: false,
label: intl.formatMessage({ id: 'deposit.add.sym' }),
content: <SymDepositContent poolDetail={poolDetailRD} asset={assetWD} haltedChains={haltedChains} />
content: (
<SymDepositContent
poolDetail={poolDetailRD}
asset={assetWD}
haltedChains={haltedChains}
liquidityProvider={liquidityProviderRD}
/>
)
},
{
key: 'withdraw-sym',
Expand All @@ -149,7 +160,17 @@ export const Deposit: React.FC<Props> = (props) => {
// content: <AsymWidthdrawContent asset={asset} poolShare={asymPoolShareAsset} haltedChains={haltedChains} />
// }
],
[intl, SymDepositContent, poolDetailRD, assetWD, hasSymPoolShare, WidthdrawContent, combinedPoolShare, haltedChains]
[
intl,
SymDepositContent,
poolDetailRD,
assetWD,
haltedChains,
liquidityProviderRD,
hasSymPoolShare,
WidthdrawContent,
combinedPoolShare
]
)

const alignTopShareContent: boolean = useMemo(
Expand Down
86 changes: 82 additions & 4 deletions src/renderer/components/deposit/add/Deposit.style.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CaretRightOutlined } from '@ant-design/icons/lib'
import { Row } from 'antd'
import styled from 'styled-components'
import { palette } from 'styled-theme'

import { media } from '../../../helpers/styleHelper'
import { Alert as UIAlert } from '../../uielements/alert'
import { AssetCard as UIAssetCard } from '../../uielements/assets/assetCard'
import { AssetIcon as UIAssetIcon } from '../../uielements/assets/assetIcon'
import { AssetLabel as UIAssetLabel } from '../../uielements/assets/assetLabel'
import { Button as UIButton } from '../../uielements/button'
import { ViewTxButton as UIViewTxButton } from '../../uielements/button'
import { ExternalLinkIcon as UIExternalLinkIcon } from '../../uielements/common/Common.style'
import { Label as UILabel } from '../../uielements/label'

export const Container = styled.div`
Expand All @@ -25,18 +29,22 @@ export const CardsRow = styled(Row).attrs({
width: 100%;
`

export const BalanceErrorRow = styled(Row)`
export const AlertRow = styled(Row)`
width: 100%;
padding: 20px 0px;
padding: 0 0 20px 0;
${media.xl`
padding: 20px;
padding: 0 20px 20px 20px;
`}
`

export const BalanceAlert = styled(UIAlert)`
export const Alert = styled(UIAlert)`
width: 100%;
margin: 0;
${media.xl`
margin-right: 20px;
`}
`

export const BalanceErrorLabel = styled(UILabel).attrs({
Expand Down Expand Up @@ -146,3 +154,73 @@ export const SubmitButton = styled(UIButton).attrs({
padding: 0 30px;
margin-bottom: 20px;
`

export const PendingAssetContainer = styled('div')`
display: flex;
flex-direction: row;
justify-content: center;
height: 32px;
margin: 10px 0;
&:last-child {
margin: 0;
}
> div:first-child {
margin-right: 10px;
}
`

export const PendingAssetIcon = styled(UIAssetIcon).attrs({ size: 'small' })`
margin-right: 5px;
`
export const PendingAssetLabel = styled(UIAssetLabel)`
padding: 0px;
`
export const PendingAssetAmountLabel = styled(UILabel)`
font-family: 'MainFontBold';
padding: 0;
font-size: 17px;
line-height: 17px;
${media.md`
font-size: 24px;
line-height: 24px;
`}
`

export const RecoveryInfoButton = styled(UIButton).attrs({
typevalue: 'transparent'
})<{ selected: boolean }>`
&.ant-btn {
display: inline-flex;
color: inherit;
}
padding-left: 0px;
`
export const RecoveryInfoButtonIcon = styled(CaretRightOutlined)<{ selected: boolean }>`
transform: ${({ selected }) => (selected ? 'rotateZ(90deg)' : 'rotateZ(0)')};
color: ${palette('primary', 0)};
`

export const RecoveryInfoButtonLabel = styled(UILabel)`
font-family: 'MainFontBold';
text-transform: uppercase;
font-size: 12px;
line-height: 15px;
padding-right: 5px;
`

export const RecoveryDescription = styled(UILabel)`
font-family: 'MainFontRegular';
text-transform: uppercase;
font-size: 12px;
line-height: 17px;
`

export const OpenRecoveryToolIcon = styled(UIExternalLinkIcon)`
svg {
margin-left: 10px;
color: inherit;
}
`
97 changes: 97 additions & 0 deletions src/renderer/components/deposit/add/Deposit.subcomponents.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useState } from 'react'

import { assetToString, baseToAsset, formatAssetAmount } from '@xchainjs/xchain-util'
import * as FP from 'fp-ts/lib/function'
import { useIntl } from 'react-intl'

import { Network } from '../../../../shared/api/types'
import { AssetWithAmount } from '../../../types/asgardex'
import { Button } from '../../uielements/button'
import * as Styled from './Deposit.style'

type AssetIconAmountProps = {
assetWB: AssetWithAmount
network: Network
loading: boolean
}

const AssetIconAmount: React.FC<AssetIconAmountProps> = (props): JSX.Element => {
const {
assetWB: { asset, amount },
network,
loading
} = props
return (
<Styled.PendingAssetContainer>
<Styled.PendingAssetIcon asset={asset} network={network} />
<Styled.PendingAssetLabel asset={asset} />
<Styled.PendingAssetAmountLabel loading={loading}>
{formatAssetAmount({
amount: baseToAsset(amount),
decimal: amount.decimal,
trimZeros: true
})}
</Styled.PendingAssetAmountLabel>
</Styled.PendingAssetContainer>
)
}

type PendingAssetsProps = {
network: Network
assets: AssetWithAmount[]
loading: boolean
onClickRecovery: FP.Lazy<void>
}

export const PendingAssets: React.FC<PendingAssetsProps> = (props): JSX.Element => {
const { assets, network, loading, onClickRecovery } = props

const intl = useIntl()

const [collapsed, setCollapsed] = useState(false)

const subContent = (
<>
<Styled.RecoveryInfoButton selected={collapsed} onClick={() => setCollapsed((v) => !v)}>
<Styled.RecoveryInfoButtonLabel>
{intl.formatMessage({ id: 'common.informationMore' })}
</Styled.RecoveryInfoButtonLabel>
<Styled.RecoveryInfoButtonIcon selected={collapsed} />
</Styled.RecoveryInfoButton>
<>
{collapsed ? (
<>
<Styled.RecoveryDescription>
{intl.formatMessage({ id: 'deposit.add.pendingAssets.description' })}
</Styled.RecoveryDescription>
{assets.map((assetWB, index) => (
<AssetIconAmount
network={network}
assetWB={assetWB}
loading={loading}
key={`${assetToString(assetWB.asset)}-${index}`}
/>
))}
<Styled.RecoveryDescription>
{intl.formatMessage({ id: 'deposit.add.pendingAssets.recoveryDescription' })}
</Styled.RecoveryDescription>
<Button onClick={onClickRecovery} typevalue="outline" color="warning">
{intl.formatMessage({ id: 'deposit.add.pendingAssets.recoveryTitle' })}
<Styled.OpenRecoveryToolIcon />
</Button>
</>
) : (
<></>
)}
</>
</>
)

return (
<Styled.Alert
type="warning"
message={intl.formatMessage({ id: 'deposit.add.pendingAssets.title' })}
description={subContent}
/>
)
}
4 changes: 3 additions & 1 deletion src/renderer/components/deposit/add/SymDeposit.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ const defaultProps: SymDepositProps = {
assetBalance: baseAmount(30),
runeBalance: baseAmount(10)
}
}
},
pendingAssets: RD.initial,
openRecoveryTool: () => console.log('openRecoveryTool')
}

export const Default: Story = () => <SymDeposit {...defaultProps} />
Expand Down
Loading

0 comments on commit 8d7537b

Please sign in to comment.