Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvement) Invoices for not merchant users #565

Merged
merged 14 commits into from
Nov 1, 2022
6 changes: 5 additions & 1 deletion public/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@
"title": "Movements"
},
"nodata": "No related data in this time range. You can try another time range.",
"no_merchant": {
"title": "This section is only available for ",
"link": "merchant accounts"
},
"orders": {
"title": "Orders"
},
Expand Down Expand Up @@ -443,7 +447,7 @@
"status": {
"success": "{{topic}} Success at {{time}}",
"warn": "{{topic}}",
"fail": "{{topic}} fail {{detail}}",
"fail": "{{topic}} fail: {{detail}}",
"noid": "dev: the status action should contain the id param",
"request": {
"error": "{{topic}} request fail {{detail}}"
Expand Down
2 changes: 2 additions & 0 deletions src/components/Invoices/Invoices.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { getFullTime, getTimeOffset } from 'state/base/selectors'
import {
getEntries,
getIsMerchant,
getPageLoading,
getDataReceived,
getExistingCoins,
Expand All @@ -29,6 +30,7 @@ import Invoices from './Invoices'
const mapStateToProps = state => ({
getFullTime: getFullTime(state),
timeOffset: getTimeOffset(state),
isMerchant: getIsMerchant(state),
pageLoading: getPageLoading(state),
dataReceived: getDataReceived(state),
existingCoins: getExistingCoins(state),
Expand Down
7 changes: 6 additions & 1 deletion src/components/Invoices/Invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NoData from 'ui/NoData'
import Loading from 'ui/Loading'
import DataTable from 'ui/DataTable'
import TimeRange from 'ui/TimeRange'
import NoMerchant from 'ui/NoMerchant'
import Pagination from 'ui/Pagination'
import ColumnsFilter from 'ui/ColumnsFilter'
import RefreshButton from 'ui/RefreshButton'
Expand Down Expand Up @@ -52,6 +53,7 @@ class Invoices extends PureComponent {
id: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
})),
dataReceived: PropTypes.bool.isRequired,
entries: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
amount: PropTypes.number.isRequired,
Expand All @@ -68,7 +70,7 @@ class Invoices extends PureComponent {
})).isRequired,
existingCoins: PropTypes.arrayOf(PropTypes.string),
getFullTime: PropTypes.func.isRequired,
dataReceived: PropTypes.bool.isRequired,
isMerchant: PropTypes.bool.isRequired,
pageLoading: PropTypes.bool.isRequired,
refresh: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
Expand Down Expand Up @@ -102,6 +104,7 @@ class Invoices extends PureComponent {
refresh,
columns,
timeOffset,
isMerchant,
getFullTime,
pageLoading,
columnsWidth,
Expand All @@ -121,6 +124,8 @@ class Invoices extends PureComponent {
let showContent
if (!dataReceived && pageLoading) {
showContent = <Loading />
} else if (!isMerchant) {
showContent = <NoMerchant />
} else if (!entries.length) {
showContent = <NoData />
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/state/invoices/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,21 @@ export function clearTargetSymbols() {
}
}

export function setMerchantStatus(status) {
return {
type: types.SET_MERCHANT,
payload: status,
}
}

export default {
addTargetSymbol,
clearTargetSymbols,
fetchFail,
fetchInvoices,
refresh,
removeTargetSymbol,
setMerchantStatus,
setTargetSymbols,
updateInvoices,
}
1 change: 1 addition & 0 deletions src/state/invoices/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default {
REMOVE_SYMBOL: 'BITFINEX/INVOICES/SYMBOL/REMOVE',
CLEAR_SYMBOLS: 'BITFINEX/INVOICES/SYMBOL/CLEAR',
UPDATE_INVOICES: 'BITFINEX/INVOICES/UPDATE',
SET_MERCHANT: 'BITFINEX/INVOICES/MERCHANT/SET',
}
6 changes: 6 additions & 0 deletions src/state/invoices/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { updateInvoices } from './utils'

const initialState = {
...baseSymbolState,
isMerchant: true,
}

export function invoicesReducer(state = initialState, action) {
Expand Down Expand Up @@ -60,6 +61,11 @@ export function invoicesReducer(state = initialState, action) {
existingCoins: state.existingCoins,
targetCategory: state.targetCategory,
}
case types.SET_MERCHANT:
return {
...state,
isMerchant: payload,
}
case timeRangeTypes.SET_TIME_RANGE:
return {
...initialState,
Expand Down
20 changes: 15 additions & 5 deletions src/state/invoices/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ function* fetchInvoices() {
yield put(updatePagination(TYPE, result))

if (error) {
yield put(actions.fetchFail({
id: 'status.fail',
topic: 'invoices.title',
detail: JSON.stringify(error),
}))
const { code, message } = error
if (code === 409) {
yield put(actions.setMerchantStatus(false))
yield put(actions.fetchFail({
id: 'status.fail',
topic: 'invoices.title',
detail: message,
}))
} else {
yield put(actions.fetchFail({
id: 'status.fail',
topic: 'invoices.title',
detail: JSON.stringify(error),
}))
}
}
} catch (fail) {
yield put(actions.fetchFail({
Expand Down
2 changes: 2 additions & 0 deletions src/state/invoices/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export const getTargetSymbols = state => getInvoices(state).targetSymbols
export const getDataReceived = state => getInvoices(state).dataReceived
export const getEntries = state => getInvoices(state).entries
export const getPageLoading = state => getInvoices(state).pageLoading
export const getIsMerchant = state => getInvoices(state).isMerchant

export default {
getDataReceived,
getEntries,
getExistingCoins,
getInvoices,
getIsMerchant,
getPageLoading,
getTargetSymbols,
}
30 changes: 30 additions & 0 deletions src/ui/NoMerchant/NoMerchant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import PropTypes from 'prop-types'
import { withTranslation } from 'react-i18next'

import Icon from 'icons'

const NoMerchant = ({ t }) => (
<div className='no_merchant'>
<div className='no_merchant-wrapper'>
<Icon.WARNING />
<>
{t('no_merchant.title')}
<a
target='_blank'
rel='noreferrer'
href='https://pay.bitfinex.com/'
>
{t('no_merchant.link')}
</a>
.
</>
</div>
</div>
)

NoMerchant.propTypes = {
t: PropTypes.func.isRequired,
}

export default withTranslation('translations')(NoMerchant)
31 changes: 31 additions & 0 deletions src/ui/NoMerchant/_NoMerchant.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.no_merchant {
position: relative;

&-wrapper {
width: fit-content;
height: fit-content;
margin: 180px auto 0 auto;
text-align: center;

svg {
display: block;
margin: 0 auto 38px auto;
}
}
}

@media screen and (min-width: 2560px) {
.no_merchant {
&-wrapper {
margin: 262px auto 0 auto;
}
}
}

@media screen and (max-width: 390px) {
.no_merchant {
&-wrapper {
margin: 40px auto 0 auto;
}
}
}
1 change: 1 addition & 0 deletions src/ui/NoMerchant/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './NoMerchant'
1 change: 1 addition & 0 deletions src/ui/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import "./NavMenu/_NavMenu.scss";
@import "./NavSwitcher/_NavSwitcher.scss";
@import "./NoData/_NoData.scss";
@import "./NoMerchant/_NoMerchant.scss";
@import "./Pagination/_Pagination.scss";
@import "./PlatformLogo/_PlatformLogo.scss";
@import "./QueryButton/_QueryButton.scss";
Expand Down