Skip to content

Commit

Permalink
Fix bitshares#545: Show gateway status as down for unavailable coins
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Oct 11, 2017
1 parent 38906a6 commit fb55b69
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
13 changes: 8 additions & 5 deletions app/actions/GatewayActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ class GatewayActions {
if (!inProgress["fetchCoins_" + backer]) {
inProgress["fetchCoins_" + backer] = true;
return (dispatch) => {
Promise.all([fetchCoins(url),
Promise.all([
fetchCoins(url),
fetchBridgeCoins(blockTradesAPIs.BASE_OL),
getActiveWallets(url)
]).then(result => {
delete inProgress["fetchCoins_" + backer];
let [coins, tradingPairs, wallets] = result;
let backedCoins = getBackedCoins({allCoins: coins, tradingPairs: tradingPairs, backer: backer}).filter(a => !!a.walletType);
backedCoins.forEach(a => {
a.isAvailable = wallets.indexOf(a.walletType) !== -1;
});
dispatch({
coins: coins,
backedCoins: getBackedCoins({allCoins: coins, tradingPairs: tradingPairs, backer: backer}).filter(a => {
return wallets.indexOf(a.walletType) !== -1;
}),
coins,
backedCoins,
backer
});
});
Expand Down
3 changes: 2 additions & 1 deletion app/assets/locales/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,8 @@
"min_amount": "Minimum amount: %(minAmount)s %(symbol)s",
"min_amount_error": "Please enter number >= minimum",
"coming_soon": "Coming soon"
}
},
"unavailable": "The gateway service for this asset is currently down, please try again later"
},
"chat": {
"title": "Chat",
Expand Down
22 changes: 3 additions & 19 deletions app/components/Account/AccountDepositWithdraw.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AccountDepositWithdraw extends React.Component {
});
}

renderServices(blockTradesGatewayCoins, openLedgerGatewayCoins, rudexGatewayCoins) {
renderServices(openLedgerGatewayCoins, rudexGatewayCoins) {
//let services = ["Openledger (OPEN.X)", "BlockTrades (TRADE.X)", "Transwiser", "BitKapital"];
let serList = [];
let { account } = this.props;
Expand Down Expand Up @@ -236,23 +236,7 @@ class AccountDepositWithdraw extends React.Component {
let { account } = this.props;
let { activeService } = this.state;

let blockTradesGatewayCoins = this.props.blockTradesBackedCoins.filter(coin => {
if (coin.backingCoinType.toLowerCase() === "muse") {
return false;
}
return coin.symbol.toUpperCase().indexOf("TRADE") !== -1;
})
.map(coin => {
return coin;
})
.sort((a, b) => {
if (a.symbol < b.symbol)
return -1;
if (a.symbol > b.symbol)
return 1;
return 0;
});

console.log("openLedgerBackedCoins", this.props.openLedgerBackedCoins);
let openLedgerGatewayCoins = this.props.openLedgerBackedCoins.map(coin => {
return coin;
})
Expand All @@ -275,7 +259,7 @@ class AccountDepositWithdraw extends React.Component {
return 0;
});

let services = this.renderServices(blockTradesGatewayCoins, openLedgerGatewayCoins, rudexGatewayCoins);
let services = this.renderServices(openLedgerGatewayCoins, rudexGatewayCoins);

let options = services.map((services_obj, index) => {
return <option key={index} value={index}>{services_obj.name}</option>;
Expand Down
1 change: 1 addition & 0 deletions app/components/DepositWithdraw/BlockTradesGateway.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class BlockTradesGateway extends React.Component {
receive_asset={coin.symbol}
receive_coin_type={coin.symbol.toLowerCase()}
supports_output_memos={coin.supportsMemos}
isAvailable={coin.isAvailable}
action={this.state.action}
/>
<label className="left-label">Support</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ChainTypes from "components/Utility/ChainTypes";
import BindToChainState from "components/Utility/BindToChainState";
import WithdrawModalBlocktrades from "./WithdrawModalBlocktrades";
import BaseModal from "../../Modal/BaseModal";
import Trigger from "react-foundation-apps/src/trigger";
import ZfApi from "react-foundation-apps/src/utils/foundation-api";
import AccountBalance from "../../Account/AccountBalance";
import BlockTradesDepositAddressCache from "common/BlockTradesDepositAddressCache";
import AssetName from "components/Utility/AssetName";
import LinkToAccountById from "components/Blockchain/LinkToAccountById";
import {requestDepositAddress} from "common/blockTradesMethods";
import { blockTradesAPIs } from "api/apiConfig";
import LoadingIndicator from "components/LoadingIndicator";

class BlockTradesGatewayDepositRequest extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -160,7 +160,7 @@ class BlockTradesGatewayDepositRequest extends React.Component {

if( !receive_address ) {
requestDepositAddress(this._getDepositObject());
return emptyRow;
return <div style={{margin: "3rem"}}><LoadingIndicator type="three-bounce"/></div>;
}

let withdraw_modal_id = this.getWithdrawModalId();
Expand Down Expand Up @@ -200,6 +200,10 @@ class BlockTradesGatewayDepositRequest extends React.Component {
var withdraw_memo_prefix = "";
}

if (!this.props.isAvailable) {
return <div><Translate className="txtlabel cancel" content="gateway.unavailable" component="h4" /></div>;
}

if (this.props.action === "deposit") {
return (
<div className="Blocktrades__gateway grid-block no-padding no-margin">
Expand Down
8 changes: 7 additions & 1 deletion app/lib/common/blockTradesMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function getActiveWallets(url = (blockTradesAPIs.BASE_OL + blockTradesAPI
});
}

let depositRequests = {};
export function requestDepositAddress({inputCoinType, outputCoinType, outputAddress, url = blockTradesAPIs.BASE_OL, stateCallback}) {
let body = {
inputCoinType,
Expand All @@ -61,25 +62,30 @@ export function requestDepositAddress({inputCoinType, outputCoinType, outputAddr
};

let body_string = JSON.stringify(body);

if (depositRequests[body_string]) return;
depositRequests[body_string] = true;
fetch( url + "/simple-api/initiate-trade", {
method:"post",
headers: new Headers( { "Accept": "application/json", "Content-Type":"application/json" } ),
body: body_string
}).then( reply => { reply.json()
.then( json => {
delete depositRequests[body_string];
// console.log( "reply: ", json )
let address = {"address": json.inputAddress || "unknown", "memo": json.inputMemo, error: json.error || null};
if (stateCallback) stateCallback(address);
}, error => {
// console.log( "error: ",error );
delete depositRequests[body_string];
if (stateCallback) stateCallback({"address": "unknown", "memo": null});
});
}, error => {
// console.log( "error: ",error );
delete depositRequests[body_string];
if (stateCallback) stateCallback({"address": "unknown", "memo": null});
}).catch(err => {
console.log("fetch error:", err);
delete depositRequests[body_string];
});
}

Expand Down

0 comments on commit fb55b69

Please sign in to comment.