From fb55b69a634865aa6d41afdf0878387878a77d01 Mon Sep 17 00:00:00 2001 From: Sigve Kvalsvik Date: Wed, 11 Oct 2017 10:49:41 +0200 Subject: [PATCH] Fix #545: Show gateway status as down for unavailable coins --- app/actions/GatewayActions.js | 13 ++++++----- app/assets/locales/locale-en.json | 3 ++- .../Account/AccountDepositWithdraw.jsx | 22 +++---------------- .../DepositWithdraw/BlockTradesGateway.jsx | 1 + .../BlockTradesGatewayDepositRequest.jsx | 8 +++++-- app/lib/common/blockTradesMethods.js | 8 ++++++- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/app/actions/GatewayActions.js b/app/actions/GatewayActions.js index fa988a3d65..98f281f9be 100644 --- a/app/actions/GatewayActions.js +++ b/app/actions/GatewayActions.js @@ -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 }); }); diff --git a/app/assets/locales/locale-en.json b/app/assets/locales/locale-en.json index ed4ec12965..68040691d4 100644 --- a/app/assets/locales/locale-en.json +++ b/app/assets/locales/locale-en.json @@ -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", diff --git a/app/components/Account/AccountDepositWithdraw.jsx b/app/components/Account/AccountDepositWithdraw.jsx index 0a3c2edd05..9f03d87ac9 100644 --- a/app/components/Account/AccountDepositWithdraw.jsx +++ b/app/components/Account/AccountDepositWithdraw.jsx @@ -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; @@ -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; }) @@ -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 ; diff --git a/app/components/DepositWithdraw/BlockTradesGateway.jsx b/app/components/DepositWithdraw/BlockTradesGateway.jsx index 69da001247..a2f4d8885c 100644 --- a/app/components/DepositWithdraw/BlockTradesGateway.jsx +++ b/app/components/DepositWithdraw/BlockTradesGateway.jsx @@ -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} /> diff --git a/app/components/DepositWithdraw/blocktrades/BlockTradesGatewayDepositRequest.jsx b/app/components/DepositWithdraw/blocktrades/BlockTradesGatewayDepositRequest.jsx index f2d2a788b8..9a1e80f59a 100644 --- a/app/components/DepositWithdraw/blocktrades/BlockTradesGatewayDepositRequest.jsx +++ b/app/components/DepositWithdraw/blocktrades/BlockTradesGatewayDepositRequest.jsx @@ -5,7 +5,6 @@ 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"; @@ -13,6 +12,7 @@ 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 = { @@ -160,7 +160,7 @@ class BlockTradesGatewayDepositRequest extends React.Component { if( !receive_address ) { requestDepositAddress(this._getDepositObject()); - return emptyRow; + return
; } let withdraw_modal_id = this.getWithdrawModalId(); @@ -200,6 +200,10 @@ class BlockTradesGatewayDepositRequest extends React.Component { var withdraw_memo_prefix = ""; } + if (!this.props.isAvailable) { + return
; + } + if (this.props.action === "deposit") { return (
diff --git a/app/lib/common/blockTradesMethods.js b/app/lib/common/blockTradesMethods.js index 3f29c576ff..cba3335153 100644 --- a/app/lib/common/blockTradesMethods.js +++ b/app/lib/common/blockTradesMethods.js @@ -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, @@ -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]; }); }