Skip to content

Commit bc24c00

Browse files
authored
Merge branch 'staging' into mv/rtl
2 parents 5c89ec4 + 05f5904 commit bc24c00

File tree

12 files changed

+149
-192
lines changed

12 files changed

+149
-192
lines changed

.github/workflows/nodejs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Cache node modules
2828
id: cache-nodemodules
29-
uses: actions/cache@v2
29+
uses: actions/cache@v3
3030
env:
3131
cache-name: cache-node-modules
3232
with:
@@ -59,7 +59,7 @@ jobs:
5959

6060
- name: Cache node modules
6161
id: cache-nodemodules
62-
uses: actions/cache@v2
62+
uses: actions/cache@v3
6363
env:
6464
cache-name: cache-node-modules
6565
with:
@@ -99,7 +99,7 @@ jobs:
9999

100100
- name: Cache node modules
101101
id: cache-nodemodules
102-
uses: actions/cache@v2
102+
uses: actions/cache@v3
103103
env:
104104
cache-name: cache-node-modules
105105
with:

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"moxios",
6969
"NFTSANDBOX",
7070
"pageview",
71+
"paychannels",
7172
"paystrings",
7273
"testid",
7374
"topojson"

src/containers/Accounts/AccountHeader/test/actions.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ describe('AccountHeader Actions', () => {
4141
flags: [],
4242
balance: '123456000',
4343
gravatar: undefined,
44+
nftMinter: undefined,
4445
previousTxn:
4546
'6B6F2CA1633A22247058E988372BA9EFFFC5BF10212230B67341CA32DC9D4A82',
4647
previousLedger: 68990183,
4748
},
49+
deleted: false,
4850
balances: { XRP: 123.456 },
4951
signerList: undefined,
5052
tokens: [],
@@ -66,7 +68,7 @@ describe('AccountHeader Actions', () => {
6668
})
6769
})
6870

69-
fit('should dispatch correct actions on ripple account with tokens', () => {
71+
it('should dispatch correct actions on account with tokens', () => {
7072
client.addResponses(actWithTokens)
7173
const expectedData = {
7274
account: 'rB5TihdPbKgMrkFqrqUC3yLdE8hhv4BdeY',
@@ -194,10 +196,12 @@ describe('AccountHeader Actions', () => {
194196
flags: [],
195197
balance: '123456000',
196198
gravatar: undefined,
199+
nftMinter: undefined,
197200
previousTxn:
198201
'6B6F2CA1633A22247058E988372BA9EFFFC5BF10212230B67341CA32DC9D4A82',
199202
previousLedger: 68990183,
200203
},
204+
deleted: false,
201205
balances: { XRP: 123.456 },
202206
signerList: undefined,
203207
tokens: [],
@@ -242,7 +246,7 @@ describe('AccountHeader Actions', () => {
242246
})
243247
})
244248

245-
it('should dispatch correct actions on ripple address not found', () => {
249+
it('should dispatch correct actions on address not found', () => {
246250
const expectedActions = [
247251
{ type: actionTypes.START_LOADING_ACCOUNT_STATE },
248252
{ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE },
@@ -253,6 +257,7 @@ describe('AccountHeader Actions', () => {
253257
},
254258
]
255259
client.addResponse('account_info', { result: actNotFound })
260+
client.addResponse('account_tx', { result: actNotFound })
256261
const store = mockStore({ news: initialState })
257262
return store
258263
.dispatch(actions.loadAccountState(TEST_ADDRESS, client))
@@ -261,7 +266,7 @@ describe('AccountHeader Actions', () => {
261266
})
262267
})
263268

264-
it('should dispatch correct actions on invalid ripple address', () => {
269+
it('should dispatch correct actions on invalid address', () => {
265270
const expectedActions = [
266271
{
267272
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL,

src/containers/Header/MobileMenu.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
BREAKPOINTS,
1010
} from '../shared/utils'
1111
import defaultRoutes from './routes'
12-
import Search from './Search'
12+
import { Search } from './Search'
1313
import arrowIcon from '../shared/images/down_arrow_black_50.png'
1414
import closeIcon from '../shared/images/close.png'
1515
import unionIcon from '../shared/images/union.png'
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import React, { Component } from 'react'
2-
import PropTypes from 'prop-types'
3-
import { withTranslation } from 'react-i18next'
4-
import { Redirect } from 'react-router-dom'
1+
import React, { KeyboardEventHandler, useContext } from 'react'
2+
import { useTranslation } from 'react-i18next'
3+
import { useHistory } from 'react-router-dom'
4+
import { XrplClient } from 'xrpl-client'
5+
56
import {
67
isValidClassicAddress,
78
isValidXAddress,
89
classicAddressToXAddress,
910
} from 'ripple-address-codec'
1011
import { isValidPayId as isValidPayString } from 'payid-lib'
12+
import SocketContext from '../shared/SocketContext'
1113
import {
1214
analytics,
1315
ANALYTIC_TYPES,
@@ -19,9 +21,8 @@ import {
1921
} from '../shared/utils'
2022
import './search.scss'
2123
import { getTransaction } from '../../rippled/lib/rippled'
22-
import SocketContext from '../shared/SocketContext'
2324

24-
const determineHashType = async (id, rippledContext) => {
25+
const determineHashType = async (id: string, rippledContext: XrplClient) => {
2526
try {
2627
await getTransaction(rippledContext, id)
2728
return 'transactions'
@@ -30,7 +31,7 @@ const determineHashType = async (id, rippledContext) => {
3031
}
3132
}
3233

33-
const getIdType = async (id, rippledContext) => {
34+
const getIdType = async (id: string, rippledContext: XrplClient) => {
3435
if (DECIMAL_REGEX.test(id)) {
3536
return 'ledgers'
3637
}
@@ -63,7 +64,7 @@ const getIdType = async (id, rippledContext) => {
6364

6465
// normalize classicAddress:tag to X-address
6566
// TODO: Take network into account (!)
66-
const normalize = (id, type) => {
67+
const normalize = (id: string, type: string) => {
6768
if (type === 'transactions') {
6869
return id.toUpperCase()
6970
}
@@ -75,7 +76,7 @@ const normalize = (id, type) => {
7576
components[0],
7677
components[1] === undefined || components[1] === 'false'
7778
? false
78-
: components[1],
79+
: Number(components[1]),
7980
false,
8081
) // TODO: Take network into account (!)
8182
return xAddress
@@ -93,73 +94,47 @@ const normalize = (id, type) => {
9394
return id
9495
}
9596

96-
class Search extends Component {
97-
constructor(props) {
98-
super(props)
99-
this.state = { redirect: '' }
100-
this.onKeyDown = this.onKeyDown.bind(this)
101-
}
97+
export interface SearchProps {
98+
mobile: boolean
99+
callback: Function
100+
}
102101

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

108-
async handleSearch(id) {
109-
const { callback } = this.props
110-
const type = await getIdType(id, this.context)
110+
const handleSearch = async (id: string) => {
111+
const type = await getIdType(id, socket)
111112

112113
analytics(ANALYTIC_TYPES.event, {
113114
eventCategory: 'globalSearch',
114115
eventAction: type,
115116
eventLabel: id,
116117
})
117118

118-
this.setState(
119-
{
120-
redirect:
121-
type === 'invalid'
122-
? `/search/${id}`
123-
: `/${type}/${normalize(id, type)}`,
124-
},
125-
callback,
119+
history.push(
120+
type === 'invalid' ? `/search/${id}` : `/${type}/${normalize(id, type)}`,
126121
)
122+
callback()
127123
}
128124

129-
onKeyDown(event) {
125+
const onKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {
130126
if (event.key === 'Enter') {
131-
this.handleSearch(event.currentTarget.value.trim())
127+
handleSearch(event.currentTarget?.value?.trim())
132128
}
133129
}
134130

135-
render() {
136-
const { t, mobile } = this.props
137-
const { redirect } = this.state
138-
return redirect ? (
139-
<Redirect push to={redirect} />
140-
) : (
141-
<div className={mobile ? 'search' : 'search in-header'}>
142-
<input
143-
type="text"
144-
placeholder={t('header.search.placeholder')}
145-
onKeyDown={this.onKeyDown}
146-
/>
147-
</div>
148-
)
149-
}
150-
}
151-
152-
Search.contextType = SocketContext
153-
154-
Search.propTypes = {
155-
t: PropTypes.func.isRequired,
156-
mobile: PropTypes.bool,
157-
callback: PropTypes.func,
131+
return (
132+
<div className={mobile ? 'search' : 'search in-header'}>
133+
<input
134+
type="text"
135+
placeholder={t('header.search.placeholder')}
136+
onKeyDown={onKeyDown}
137+
/>
138+
</div>
139+
)
158140
}
159-
160-
Search.defaultProps = {
161-
mobile: false,
162-
callback: () => {},
163-
}
164-
165-
export default withTranslation()(Search)

src/containers/Header/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BREAKPOINTS, ANALYTIC_TYPES, analytics } from '../shared/utils'
99
import Menu from './Menu'
1010
import MobileMenu from './MobileMenu'
1111
import Banner from './Banner'
12-
import Search from './Search'
12+
import { Search } from './Search'
1313
import { ReactComponent as Logo } from '../shared/images/XRPLedger.svg'
1414
import { ReactComponent as ArrowIcon } from '../shared/images/down_arrow.svg'
1515
import { ReactComponent as CheckIcon } from '../shared/images/checkmark.svg'

src/containers/Header/test/Search.test.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@ import React from 'react'
22
import { mount } from 'enzyme'
33
import { I18nextProvider } from 'react-i18next'
44
import { BrowserRouter as Router } from 'react-router-dom'
5-
import configureMockStore from 'redux-mock-store'
6-
import thunk from 'redux-thunk'
7-
import { Provider } from 'react-redux'
8-
import { initialState } from '../../../rootReducer'
95
import i18n from '../../../i18nTestConfig'
10-
import Search from '../Search'
6+
import { Search } from '../Search'
117
import * as rippled from '../../../rippled/lib/rippled'
8+
import SocketContext from '../../shared/SocketContext'
9+
import MockWsClient from '../../test/mockWsClient'
1210

13-
describe('Header component', () => {
14-
const middlewares = [thunk]
15-
const mockStore = configureMockStore(middlewares)
16-
const createWrapper = (state = {}) => {
17-
const store = mockStore({ ...initialState, ...state })
11+
describe('Search component', () => {
12+
const createWrapper = () => {
13+
const client = new MockWsClient()
1814
return mount(
1915
<I18nextProvider i18n={i18n}>
20-
<Router>
21-
<Provider store={store}>
16+
<SocketContext.Provider value={client}>
17+
<Router>
2218
<Search />
23-
</Provider>
24-
</Router>
19+
</Router>
20+
</SocketContext.Provider>
2521
</I18nextProvider>,
2622
)
2723
}

src/containers/Ledgers/Ledgers.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class Ledgers extends Component {
220220
const partial = v.partial ? <div className="partial" /> : null
221221
return (
222222
<div
223-
key={v.pubkey}
223+
key={`${v.pubkey}_${v.cookie}`}
224224
role="button"
225225
tabIndex={i}
226226
className={className}

0 commit comments

Comments
 (0)