Skip to content

Commit 1b9209a

Browse files
committed
Fix bitshares#1463: Handle non-existant assets in exchange and asset pages
1 parent 7ff4da0 commit 1b9209a

File tree

7 files changed

+63
-21
lines changed

7 files changed

+63
-21
lines changed

app/assets/locales/locale-en.json

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"page404": {
33
"page_not_found_title": "404 page not found",
44
"page_not_found_subtitle": "This page does not exist",
5+
"asset_not_found_subtitle": "That asset does not exist",
6+
"market_not_found_subtitle": "That market does not exist",
57
"home": "Home"
68
},
79
"counterpart": {

app/components/Blockchain/Asset.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {ChainStore} from "bitsharesjs/es";
1515
import {Apis} from "bitsharesjs-ws";
1616
import {Tabs, Tab} from "../Utility/Tabs";
1717
import {CallOrder, FeedPrice} from "common/MarketClasses";
18+
import Page404 from "../Page404/Page404";
1819

1920
class AssetFlag extends React.Component {
2021
render() {
@@ -1148,6 +1149,9 @@ Asset = AssetWrapper(Asset, {
11481149

11491150
class AssetContainer extends React.Component {
11501151
render() {
1152+
if (this.props.asset === null) {
1153+
return <Page404 subtitle="asset_not_found_subtitle" />;
1154+
}
11511155
let backingAsset = this.props.asset.has("bitasset")
11521156
? this.props.asset.getIn([
11531157
"bitasset",
@@ -1164,7 +1168,7 @@ AssetContainer = AssetWrapper(AssetContainer, {
11641168

11651169
export default class AssetSymbolSplitter extends React.Component {
11661170
render() {
1167-
let symbol = this.props.params.symbol;
1171+
let symbol = this.props.params.symbol.toUpperCase();
11681172
return <AssetContainer {...this.props} asset={symbol} />;
11691173
}
11701174
}

app/components/Exchange/ExchangeContainer.jsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExchangeContainer extends React.Component {
1616
render() {
1717
let symbols = this.props.params.marketID.toUpperCase().split("_");
1818
if (symbols[0] === symbols[1]) {
19-
return <Page404 />;
19+
return <Page404 subtitle="market_not_found_subtitle" />;
2020
}
2121
return (
2222
<AltContainer
@@ -151,6 +151,9 @@ class ExchangeSubscriber extends React.Component {
151151
}
152152

153153
componentWillMount() {
154+
if (this.props.quoteAsset === null || this.props.baseAsset === null) {
155+
return;
156+
}
154157
if (this.props.quoteAsset.toJS && this.props.baseAsset.toJS) {
155158
this._subToMarket(this.props);
156159
// this._addMarket(this.props.quoteAsset.get("symbol"), this.props.baseAsset.get("symbol"));
@@ -203,6 +206,9 @@ class ExchangeSubscriber extends React.Component {
203206
}
204207

205208
componentWillReceiveProps(nextProps) {
209+
if (nextProps.quoteAsset === null || nextProps.baseAsset === null) {
210+
return;
211+
}
206212
/* Prediction markets should only be shown in one direction, if the link goes to the wrong one we flip it */
207213
if (
208214
nextProps.baseAsset &&
@@ -238,6 +244,10 @@ class ExchangeSubscriber extends React.Component {
238244

239245
componentWillUnmount() {
240246
let {quoteAsset, baseAsset} = this.props;
247+
if (quoteAsset === null || baseAsset === null) {
248+
return;
249+
}
250+
241251
MarketsActions.unSubscribeMarket(
242252
quoteAsset.get("id"),
243253
baseAsset.get("id")
@@ -269,6 +279,9 @@ class ExchangeSubscriber extends React.Component {
269279
}
270280

271281
render() {
282+
if (this.props.quoteAsset === null || this.props.baseAsset === null)
283+
return <Page404 subtitle="market_not_found_subtitle" />;
284+
272285
return (
273286
<Exchange
274287
{...this.props}

app/components/Page404/Page404.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const dark = require("assets/logo-404-dark.png");
99
const midnight = require("assets/logo-404-midnight.png");
1010

1111
class Page404 extends React.Component {
12+
static defaultProps = {
13+
subtitle: "page_not_found_subtitle"
14+
};
1215
render() {
1316
let logo;
1417

@@ -34,7 +37,7 @@ class Page404 extends React.Component {
3437
<Translate content="page404.page_not_found_title" />
3538
</div>
3639
<div className="page-404-subtitle">
37-
<Translate content="page404.page_not_found_subtitle" />
40+
<Translate content={"page404." + this.props.subtitle} />
3841
</div>
3942
<div className="page-404-button-back">
4043
<Link to={"/"}>

app/components/Utility/AssetWrapper.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ function AssetWrapper(Component, options = {}) {
7474
let passTroughProps = {};
7575
let dos = List();
7676
Object.keys(this.props).forEach(prop => {
77-
if (options.propNames.indexOf(prop) !== -1) {
77+
if (
78+
this.props[prop] &&
79+
options.propNames.indexOf(prop) !== -1
80+
) {
7881
if (options.withDynamic) {
7982
if (!options.asList) {
8083
dos = dos.push(

app/components/Utility/BindToChainState.jsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,17 @@ function BindToChainState(Component, options = {}) {
339339
this.default_props[key];
340340
if (prop) {
341341
let new_obj = ChainStore.getAsset(prop);
342+
342343
if (
343344
new_obj === undefined &&
344345
this.required_props.indexOf(key) === -1 &&
345346
new_obj !== this.state[key]
346347
)
347348
new_state[key] = new_obj;
348-
else if (new_obj && new_obj !== this.state[key])
349+
else if (
350+
(new_obj && new_obj !== this.state[key]) ||
351+
new_obj === null
352+
)
349353
new_state[key] = new_obj;
350354
++all_objects_counter;
351355
if (new_obj !== undefined) ++resolved_objects_counter;
@@ -513,7 +517,13 @@ function BindToChainState(Component, options = {}) {
513517

514518
render() {
515519
const props = omit(this.props, this.all_chain_props);
516-
520+
if (Component.name === "ExchangeSubscriber")
521+
console.log(
522+
"props:",
523+
this.all_chain_props,
524+
"state:",
525+
this.state
526+
);
517527
for (let prop of this.required_props) {
518528
if (this.state[prop] === undefined) {
519529
if (typeof options !== "undefined" && options.show_loader) {

app/components/Utility/ChainTypes.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ const {object_type} = grapheneChainTypes;
99
function createChainableTypeChecker(validate) {
1010
function checkType(isRequired, props, propName, componentName, location) {
1111
componentName = componentName || ANONYMOUS;
12-
if (props[propName] == null) {
13-
if (isRequired) {
14-
return new Error(
15-
"Required " +
16-
location +
17-
" `" +
18-
propName +
19-
"` was not specified in " +
20-
("`" + componentName + "`.")
21-
);
22-
}
23-
return null;
24-
} else {
25-
return validate(props, propName, componentName, location);
26-
}
12+
if (componentName === "ExchangeSubscriber")
13+
console.log(
14+
componentName,
15+
propName,
16+
props[propName],
17+
validate(props, propName, componentName, location)
18+
);
19+
// if (props[propName] == null) {
20+
// if (isRequired) {
21+
// return new Error(
22+
// "Required " +
23+
// location +
24+
// " `" +
25+
// propName +
26+
// "` was not specified in " +
27+
// ("`" + componentName + "`.")
28+
// );
29+
// }
30+
// return null;
31+
// } else {
32+
return validate(props, propName, componentName, location);
33+
// }
2734
}
2835

2936
let chainedCheckType = checkType.bind(null, false);

0 commit comments

Comments
 (0)