Skip to content

Commit

Permalink
Merge branch 'staging' into mv/rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari authored Jan 10, 2023
2 parents 5c89ec4 + 05f5904 commit bc24c00
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 192 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"moxios",
"NFTSANDBOX",
"pageview",
"paychannels",
"paystrings",
"testid",
"topojson"
Expand Down
11 changes: 8 additions & 3 deletions src/containers/Accounts/AccountHeader/test/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ describe('AccountHeader Actions', () => {
flags: [],
balance: '123456000',
gravatar: undefined,
nftMinter: undefined,
previousTxn:
'6B6F2CA1633A22247058E988372BA9EFFFC5BF10212230B67341CA32DC9D4A82',
previousLedger: 68990183,
},
deleted: false,
balances: { XRP: 123.456 },
signerList: undefined,
tokens: [],
Expand All @@ -66,7 +68,7 @@ describe('AccountHeader Actions', () => {
})
})

fit('should dispatch correct actions on ripple account with tokens', () => {
it('should dispatch correct actions on account with tokens', () => {
client.addResponses(actWithTokens)
const expectedData = {
account: 'rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY',
Expand Down Expand Up @@ -194,10 +196,12 @@ describe('AccountHeader Actions', () => {
flags: [],
balance: '123456000',
gravatar: undefined,
nftMinter: undefined,
previousTxn:
'6B6F2CA1633A22247058E988372BA9EFFFC5BF10212230B67341CA32DC9D4A82',
previousLedger: 68990183,
},
deleted: false,
balances: { XRP: 123.456 },
signerList: undefined,
tokens: [],
Expand Down Expand Up @@ -242,7 +246,7 @@ describe('AccountHeader Actions', () => {
})
})

it('should dispatch correct actions on ripple address not found', () => {
it('should dispatch correct actions on address not found', () => {
const expectedActions = [
{ type: actionTypes.START_LOADING_ACCOUNT_STATE },
{ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE },
Expand All @@ -253,6 +257,7 @@ describe('AccountHeader Actions', () => {
},
]
client.addResponse('account_info', { result: actNotFound })
client.addResponse('account_tx', { result: actNotFound })
const store = mockStore({ news: initialState })
return store
.dispatch(actions.loadAccountState(TEST_ADDRESS, client))
Expand All @@ -261,7 +266,7 @@ describe('AccountHeader Actions', () => {
})
})

it('should dispatch correct actions on invalid ripple address', () => {
it('should dispatch correct actions on invalid address', () => {
const expectedActions = [
{
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Header/MobileMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
BREAKPOINTS,
} from '../shared/utils'
import defaultRoutes from './routes'
import Search from './Search'
import { Search } from './Search'
import arrowIcon from '../shared/images/down_arrow_black_50.png'
import closeIcon from '../shared/images/close.png'
import unionIcon from '../shared/images/union.png'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withTranslation } from 'react-i18next'
import { Redirect } from 'react-router-dom'
import React, { KeyboardEventHandler, useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { useHistory } from 'react-router-dom'
import { XrplClient } from 'xrpl-client'

import {
isValidClassicAddress,
isValidXAddress,
classicAddressToXAddress,
} from 'ripple-address-codec'
import { isValidPayId as isValidPayString } from 'payid-lib'
import SocketContext from '../shared/SocketContext'
import {
analytics,
ANALYTIC_TYPES,
Expand All @@ -19,9 +21,8 @@ import {
} from '../shared/utils'
import './search.scss'
import { getTransaction } from '../../rippled/lib/rippled'
import SocketContext from '../shared/SocketContext'

const determineHashType = async (id, rippledContext) => {
const determineHashType = async (id: string, rippledContext: XrplClient) => {
try {
await getTransaction(rippledContext, id)
return 'transactions'
Expand All @@ -30,7 +31,7 @@ const determineHashType = async (id, rippledContext) => {
}
}

const getIdType = async (id, rippledContext) => {
const getIdType = async (id: string, rippledContext: XrplClient) => {
if (DECIMAL_REGEX.test(id)) {
return 'ledgers'
}
Expand Down Expand Up @@ -63,7 +64,7 @@ const getIdType = async (id, rippledContext) => {

// normalize classicAddress:tag to X-address
// TODO: Take network into account (!)
const normalize = (id, type) => {
const normalize = (id: string, type: string) => {
if (type === 'transactions') {
return id.toUpperCase()
}
Expand All @@ -75,7 +76,7 @@ const normalize = (id, type) => {
components[0],
components[1] === undefined || components[1] === 'false'
? false
: components[1],
: Number(components[1]),
false,
) // TODO: Take network into account (!)
return xAddress
Expand All @@ -93,73 +94,47 @@ const normalize = (id, type) => {
return id
}

class Search extends Component {
constructor(props) {
super(props)
this.state = { redirect: '' }
this.onKeyDown = this.onKeyDown.bind(this)
}
export interface SearchProps {
mobile: boolean
callback: Function
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({ redirect: '' })
}
export const Search = ({
callback = () => {},
mobile = false,
}: SearchProps) => {
const { t } = useTranslation()
const socket = useContext(SocketContext)
const history = useHistory()

async handleSearch(id) {
const { callback } = this.props
const type = await getIdType(id, this.context)
const handleSearch = async (id: string) => {
const type = await getIdType(id, socket)

analytics(ANALYTIC_TYPES.event, {
eventCategory: 'globalSearch',
eventAction: type,
eventLabel: id,
})

this.setState(
{
redirect:
type === 'invalid'
? `/search/${id}`
: `/${type}/${normalize(id, type)}`,
},
callback,
history.push(
type === 'invalid' ? `/search/${id}` : `/${type}/${normalize(id, type)}`,
)
callback()
}

onKeyDown(event) {
const onKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
if (event.key === 'Enter') {
this.handleSearch(event.currentTarget.value.trim())
handleSearch(event.currentTarget?.value?.trim())
}
}

render() {
const { t, mobile } = this.props
const { redirect } = this.state
return redirect ? (
<Redirect push to={redirect} />
) : (
<div className={mobile ? 'search' : 'search in-header'}>
<input
type="text"
placeholder={t('header.search.placeholder')}
onKeyDown={this.onKeyDown}
/>
</div>
)
}
}

Search.contextType = SocketContext

Search.propTypes = {
t: PropTypes.func.isRequired,
mobile: PropTypes.bool,
callback: PropTypes.func,
return (
<div className={mobile ? 'search' : 'search in-header'}>
<input
type="text"
placeholder={t('header.search.placeholder')}
onKeyDown={onKeyDown}
/>
</div>
)
}

Search.defaultProps = {
mobile: false,
callback: () => {},
}

export default withTranslation()(Search)
2 changes: 1 addition & 1 deletion src/containers/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BREAKPOINTS, ANALYTIC_TYPES, analytics } from '../shared/utils'
import Menu from './Menu'
import MobileMenu from './MobileMenu'
import Banner from './Banner'
import Search from './Search'
import { Search } from './Search'
import { ReactComponent as Logo } from '../shared/images/XRPLedger.svg'
import { ReactComponent as ArrowIcon } from '../shared/images/down_arrow.svg'
import { ReactComponent as CheckIcon } from '../shared/images/checkmark.svg'
Expand Down
24 changes: 10 additions & 14 deletions src/containers/Header/test/Search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ import React from 'react'
import { mount } from 'enzyme'
import { I18nextProvider } from 'react-i18next'
import { BrowserRouter as Router } from 'react-router-dom'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { Provider } from 'react-redux'
import { initialState } from '../../../rootReducer'
import i18n from '../../../i18nTestConfig'
import Search from '../Search'
import { Search } from '../Search'
import * as rippled from '../../../rippled/lib/rippled'
import SocketContext from '../../shared/SocketContext'
import MockWsClient from '../../test/mockWsClient'

describe('Header component', () => {
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
const createWrapper = (state = {}) => {
const store = mockStore({ ...initialState, ...state })
describe('Search component', () => {
const createWrapper = () => {
const client = new MockWsClient()
return mount(
<I18nextProvider i18n={i18n}>
<Router>
<Provider store={store}>
<SocketContext.Provider value={client}>
<Router>
<Search />
</Provider>
</Router>
</Router>
</SocketContext.Provider>
</I18nextProvider>,
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Ledgers/Ledgers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Ledgers extends Component {
const partial = v.partial ? <div className="partial" /> : null
return (
<div
key={v.pubkey}
key={`${v.pubkey}_${v.cookie}`}
role="button"
tabIndex={i}
className={className}
Expand Down
Loading

0 comments on commit bc24c00

Please sign in to comment.