import React from react import connect from alt-react import BindToCha

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
import React from "react";
import {connect} from "alt-react";
import BindToChainState from "../Utility/BindToChainState";
import GatewayStore from "stores/GatewayStore";
import TypeAhead from "../Utility/TypeAhead";
import AssetImage from "../Utility/AssetImage";
import AssetName from "../Utility/AssetName";
import counterpart from "counterpart";
class DepositWithdrawAssetSelector extends React.Component {
constructor(props) {
super(props);
}
render() {
const {props} = this;
const {include} = props;
let idMap = {};
let getCoinOption = item => {
/* Gateway Specific Settings */
let [gateway, backedCoin] = item.symbol.split(".");
// Return null if backedCoin is already stored
if (!idMap[backedCoin] && backedCoin && gateway) {
idMap[backedCoin] = true;
return {
id: backedCoin,
label: backedCoin,
labelSearch: backedCoin + item.name,
labelRender: (
<span>
<AssetImage
name={item.symbol}
style={{height: 22, marginRight: 10}}
/>
<AssetName name={item.symbol} />
<span
style={{
marginLeft: 10,
fontWeight: "normal",
opacity: 0.5
}}
>
({item.name})
</span>
</span>
),
gateway: gateway,
gateFee: item.gateFee,
issuer: item.issuerId || "1.2.96397" //Fall back to open ledger
};
} else {
return null;
}
};
let coinArr = [];
if (!(this.props.includeBTS === false)) {
coinArr.push({id: "BTS", label: "BTS", gateway: ""});
}
props.backedCoins.forEach(coin => {
coinArr = coinArr
.concat(coin.map(getCoinOption))
.filter(item => {
return item;
})
.filter(item => {
if (item.id == "BTS") return true;
if (include) {
return include.includes(item.id);
}
return true;
});
});
let coinItems = coinArr.sort(function(a, b) {
if (a.id && b.id) return a.id.localeCompare(b.id);
});
let i18n = props.placeholder
? props.placeholder
: props.usageContext == "withdraw"
? "gateway.asset_search_withdraw"
: "gateway.asset_search_deposit";
return (
<TypeAhead
items={coinItems}
{...this.props}
inputProps={{placeholder: counterpart.translate(i18n)}}
label={props.noLabel ? null : "gateway.asset"}
/>
);
}
}
DepositWithdrawAssetSelector = BindToChainState(DepositWithdrawAssetSelector);
export default connect(DepositWithdrawAssetSelector, {
listenTo() {
return [GatewayStore];
},
getProps() {
return {
backedCoins: GatewayStore.getState().backedCoins
};
}
});