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

[WalletHistory] Add link to viewblock #1854

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as O from 'fp-ts/Option'

import { eqAssetsWithAmount } from '../../helpers/fp/eq'
import { Action, Tx } from '../../services/midgard/types'
import { getTxId, getValues, getRowKey } from './PoolActionsHistory.helper'
import { getTxId, getValues, getRowKey, historyFilterToViewblockFilter } from './PoolActionsHistory.helper'

const defaultPoolAction: Action = {
date: new Date(0),
Expand Down Expand Up @@ -187,4 +187,28 @@ describe('PoolActionsHistory.helper', () => {
expect(getRowKey(defaultPoolAction, 1)).toEqual(`${new Date(0)}-SWAP-1`)
})
})

describe('historyFilterToViewblockFilter', () => {
it('SWAP', () => {
expect(historyFilterToViewblockFilter('SWAP')).toEqual('swap')
})
it('DEPOSIT', () => {
expect(historyFilterToViewblockFilter('DEPOSIT')).toEqual('addLiquidity')
})
it('DONATE', () => {
expect(historyFilterToViewblockFilter('DONATE')).toEqual('donate')
})
it('REFUND', () => {
expect(historyFilterToViewblockFilter('REFUND')).toEqual('all')
})
it('SWITCH', () => {
expect(historyFilterToViewblockFilter('SWITCH')).toEqual('switch')
})
it('ALL', () => {
expect(historyFilterToViewblockFilter('ALL')).toEqual('all')
})
it('UNKNOWN', () => {
expect(historyFilterToViewblockFilter('UNKNOWN')).toEqual('all')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FormattedDate, FormattedTime } from 'react-intl'
import { Action, Actions, ActionsPage, Tx } from '../../services/midgard/types'
import { AssetWithAmount } from '../../types/asgardex'
import * as Styled from './PoolActionsHistory.styles'
import { Filter } from './types'

export const getTxId = (action: Action): O.Option<TxHash> => {
return FP.pipe(
Expand Down Expand Up @@ -46,3 +47,23 @@ export const getRowKey: GetRowKey<Action> = (action, index) =>
)

export const emptyData: ActionsPage = { total: 0, actions: [] as Actions }

export const historyFilterToViewblockFilter = (filter: Filter) => {
switch (filter) {
case 'DEPOSIT':
return 'addLiquidity'
case 'SWAP':
return 'swap'
case 'WITHDRAW':
return 'withdrawLiquidity'
case 'DONATE':
return 'donate'
case 'SWITCH':
return 'switch'
// 'ALL' and others will be matched to viewblock's 'all'
case 'ALL':
case 'REFUND': // does not exist at viewblock
case 'UNKNOWN':
return 'all'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ export const History: Story<{ dataStatus: RDStatus }> = ({ dataStatus }) => {
onWalletAddressChanged={(address: WalletAddress) => {
console.log('selected address', address)
}}
openViewblockUrl={() => {
console.log('open viewblock')
return Promise.resolve(true)
onClickAddressIcon={() => {
console.log('on click address icon')
}}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import styled from 'styled-components'
import { palette } from 'styled-theme'

import { media } from '../../helpers/styleHelper'
import { ExternalLinkIcon as ExternalLinkIconUI } from '../uielements/common/Common.styles'
import { Headline as HeadlineUI } from '../uielements/headline'

export const DateContainer = styled.span`
color: ${palette('text', 0)};
Expand All @@ -24,39 +22,3 @@ export const Header = styled.div`
flex-direction: row;
`}
`

export const HeaderFilterContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20px;

${media.md`
flex-direction: row;
`}
`

export const HeaderLinkContainer = styled.div`
display: flex;
align-items: center;
justify-content: cemter;
padding-top: 20px;
${media.md`
padding-top: 0;
flex-grow: 1;
justify-content: right;
`}
`

export const ExplorerLinkIcon = styled(ExternalLinkIconUI)`
margin-left: 10px;
svg {
color: inherit;
}
`
export const Headline = styled(HeadlineUI)`
/* TODO (@asgdx-team) Will be enabled with #1811 */
display: none;
width: auto;
`
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ export const Menu = styled(A.Menu)`

export const FilterButton = styled(Button).attrs({ typevalue: 'outline' })`
& .anticon-caret-down {
margin: 0 !important;
transition: transform 0.3s;
transform: translateY(0px);
width: 20px;
height: 20px;
width: 14px;
height: 14px;
position: absolute !important;
right: 7px;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import styled from 'styled-components'

import { media } from '../../helpers/styleHelper'
import { ExternalLinkIcon as ExternalLinkIconUI } from '../uielements/common/Common.styles'
import { Headline as HeadlineUI } from '../uielements/headline'

export const FilterContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20px;

${media.md`
flex-direction: row;
`}
`

export const LinkContainer = styled.div`
display: flex;
align-items: center;
justify-content: cemter;
padding-top: 20px;
${media.md`
padding-top: 0;
flex-grow: 1;
justify-content: right;
`}
`

export const ExplorerLinkIcon = styled(ExternalLinkIconUI)`
margin-left: 10px;
svg {
color: inherit;
}
`
export const Headline = styled(HeadlineUI)`
width: auto;
`
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'

import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'

import { Network } from '../../../shared/api/types'
import { WalletAddress, WalletAddresses } from '../../../shared/wallet/types'
import { AccountAddressSelector } from '../AccountAddressSelector'
import * as Styled from './PoolActionsHistory.styles'
import { PoolActionsHistoryFilter } from './PoolActionsHistoryFilter'
import { Filter } from './types'
import * as Styled from './WalletPoolActionsHistoryHeader.styles'

export type Props = {
network: Network
Expand All @@ -17,7 +18,7 @@ export type Props = {
currentFilter: Filter
setFilter: (filter: Filter) => void
onWalletAddressChanged: (address: WalletAddress) => void
openViewblockUrl: () => Promise<boolean>
onClickAddressIcon: FP.Lazy<void>
disabled?: boolean
}

Expand All @@ -29,14 +30,14 @@ export const WalletPoolActionsHistoryHeader: React.FC<Props> = (props) => {
availableFilters,
currentFilter,
setFilter,
openViewblockUrl,
onClickAddressIcon,
onWalletAddressChanged,
disabled = false
} = props

return (
<>
<Styled.HeaderFilterContainer>
<Styled.FilterContainer>
<PoolActionsHistoryFilter
availableFilters={availableFilters}
currentFilter={currentFilter}
Expand All @@ -49,12 +50,12 @@ export const WalletPoolActionsHistoryHeader: React.FC<Props> = (props) => {
selectedAddress={selectedAddress}
onChangeAddress={onWalletAddressChanged}
/>
</Styled.HeaderFilterContainer>
<Styled.HeaderLinkContainer>
<Styled.Headline onClick={openViewblockUrl}>
</Styled.FilterContainer>
<Styled.LinkContainer>
<Styled.Headline onClick={onClickAddressIcon}>
viewblock <Styled.ExplorerLinkIcon />
</Styled.Headline>
</Styled.HeaderLinkContainer>
</Styled.LinkContainer>
</>
)
}
8 changes: 5 additions & 3 deletions src/renderer/hooks/useOpenAddressUrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback } from 'react'

import { TxHash, XChainClient } from '@xchainjs/xchain-client'
import { Address, XChainClient } from '@xchainjs/xchain-client'
import { Chain } from '@xchainjs/xchain-util'
import * as FP from 'fp-ts/function'
import * as O from 'fp-ts/Option'
Expand All @@ -14,11 +14,13 @@ export const useOpenAddressUrl = (chain: Chain): OpenAddressUrl => {
const [oClient] = useObservableState<O.Option<XChainClient>>(() => clientByChain$(chain), O.none)

const openAddressUrl: OpenExplorerTxUrl = useCallback(
(txHash: TxHash) =>
(address: Address, params = '') =>
FP.pipe(
oClient,
O.map(async (client) => {
const url = client.getExplorerAddressUrl(txHash)
let url = client.getExplorerAddressUrl(address)
// add optional params if set before
url = params ? `${url}&${params}` : url
await window.apiUrl.openExternal(url)
return true
}),
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/services/clients/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type WalletBalancesLD = LiveData<ApiError, WalletBalances>

export type ExplorerUrl$ = Rx.Observable<O.Option<string>>
export type OpenExplorerTxUrl = (txHash: string) => Promise<boolean>
export type OpenAddressUrl = (address: Address) => Promise<boolean>
export type OpenAddressUrl = (address: Address, params?: string) => Promise<boolean>
export type AddressValidation = (address: Address) => boolean
export type AddressValidationAsync = (address: Address) => Promise<boolean>

Expand Down
27 changes: 18 additions & 9 deletions src/renderer/views/wallet/history/WalletHistoryView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from 'react'
import React, { useMemo, useCallback } from 'react'

import * as RD from '@devexperts/remote-data-ts'
import { THORChain } from '@xchainjs/xchain-util'
Expand All @@ -11,13 +11,15 @@ import * as RxOp from 'rxjs/operators'

import { WalletAddress, WalletAddresses } from '../../../../shared/wallet/types'
import { PoolActionsHistory } from '../../../components/poolActionsHistory'
import { historyFilterToViewblockFilter } from '../../../components/poolActionsHistory/PoolActionsHistory.helper'
import { Filter } from '../../../components/poolActionsHistory/types'
import { WalletPoolActionsHistoryHeader } from '../../../components/poolActionsHistory/WalletPoolActionsHistoryHeader'
import { useChainContext } from '../../../contexts/ChainContext'
import { useWalletContext } from '../../../contexts/WalletContext'
import { eqString } from '../../../helpers/fp/eq'
import { ordWalletAddressByChain } from '../../../helpers/fp/ord'
import { useNetwork } from '../../../hooks/useNetwork'
import { useOpenAddressUrl } from '../../../hooks/useOpenAddressUrl'
import { useOpenExplorerTxUrl } from '../../../hooks/useOpenExplorerTxUrl'
import { ENABLED_CHAINS } from '../../../services/const'
import { WalletHistoryActions } from './WalletHistoryView.types'
Expand Down Expand Up @@ -101,12 +103,19 @@ export const WalletHistoryView: React.FC<Props> = ({ className, historyActions }
[addresses, requestParams]
)

const openViewblockUrlHandler = useCallback(async () => {
// TODO (@asgdx-team): As part of #1811 - Get viewblock url using THORChain client
// const addressUrl = client.getExplorerAddressUrl(address)
// const addressUrl = url&txsType={type}
return true
}, [])
const openAddressUrl = useOpenAddressUrl(THORChain)

const openAddressUrlHandler = useCallback(() => {
FP.pipe(
oSelectedWalletAddress,
O.map(({ address }) => {
// add extra params for selected filter
const params = `txsType=${historyFilterToViewblockFilter(currentFilter)}`
openAddressUrl(address, params)
return true
})
)
}, [currentFilter, oSelectedWalletAddress, openAddressUrl])

const headerContent = useMemo(
() => (
Expand All @@ -118,7 +127,7 @@ export const WalletHistoryView: React.FC<Props> = ({ className, historyActions }
currentFilter={currentFilter}
setFilter={setFilter}
onWalletAddressChanged={setAddress}
openViewblockUrl={openViewblockUrlHandler}
onClickAddressIcon={openAddressUrlHandler}
disabled={!RD.isSuccess(historyPage)}
/>
),
Expand All @@ -128,7 +137,7 @@ export const WalletHistoryView: React.FC<Props> = ({ className, historyActions }
historyPage,
network,
oSelectedWalletAddress,
openViewblockUrlHandler,
openAddressUrlHandler,
setAddress,
setFilter
]
Expand Down