diff --git a/common/config/bity.js b/common/config/bity.js
index 3aeeb40b..ea38a749 100644
--- a/common/config/bity.js
+++ b/common/config/bity.js
@@ -1,39 +1,52 @@
-export default {
- serverURL: 'https://bity.myetherapi.com',
- bityAPI: 'https://bity.com/api',
- ethExplorer: 'https://etherscan.io/tx/[[txHash]]',
- btcExplorer: 'https://blockchain.info/tx/[[txHash]]',
+import { ETHTxExplorer, BTCTxExplorer } from './data';
+
+type SupportedDestinationKind = 'ETH' | 'BTC' | 'REP';
+
+const serverURL = 'https://bity.myetherapi.com';
+const bityURL = 'https://bity.com/api';
+const BTCMin = 0.01;
+const BTCMax = 3;
+
+// while Bity is supposedly OK with any order that is at least 0.01 BTC Worth, the order will fail if you send 0.01 BTC worth of ETH.
+// This is a bad magic number, but will suffice for now
+// value = percent higher/lower than 0.01 BTC worth
+const buffers = {
+ ETH: 0.1,
+ REP: 0.2
+};
+
+// rate must be BTC[KIND]
+export function kindMin(
+ BTCKINDRate: number,
+ kind: SupportedDestinationKind
+): number {
+ const kindMin = BTCKINDRate * BTCMin;
+ return kindMin + kindMin * buffers[kind];
+}
+
+// rate must be BTC[KIND]
+export function kindMax(
+ BTCKINDRate: number,
+ kind: SupportedDestinationKind
+): number {
+ const kindMax = BTCKINDRate * BTCMax;
+ return kindMax - kindMax * buffers[kind];
+}
+
+const info = {
+ serverURL,
+ bityURL,
+ ETHTxExplorer,
+ BTCTxExplorer,
+ BTCMin,
+ BTCMax,
validStatus: ['RCVE', 'FILL', 'CONF', 'EXEC'],
invalidStatus: ['CANC'],
- // while Bity is supposedly OK with any order that is at least 0.01 BTC Worth, the order will fail if you send 0.01 BTC worth of ETH.
- // This is a bad magic number, but will suffice for now
- ETHBuffer: 0.1, // percent higher/lower than 0.01 BTC worth
- REPBuffer: 0.2, // percent higher/lower than 0.01 BTC worth
- BTCMin: 0.01,
- BTCMax: 3,
- ETHMin: function(BTCETHRate: number) {
- const ETHMin = BTCETHRate * this.BTCMin;
- const ETHMinWithPadding = ETHMin + ETHMin * this.ETHBuffer;
- return ETHMinWithPadding;
- },
- ETHMax: function(BTCETHRate: number) {
- const ETHMax = BTCETHRate * this.BTCMax;
- const ETHMaxWithPadding = ETHMax - ETHMax * this.ETHBuffer;
- return ETHMaxWithPadding;
- },
- REPMin: function(BTCREPRate: number) {
- const REPMin = BTCREPRate * this.BTCMin;
- const REPMinWithPadding = REPMin + REPMin * this.REPBuffer;
- return REPMinWithPadding;
- },
- REPMax: function(BTCREPRate: number) {
- const REPMax = BTCREPRate * this.BTCMax;
- const REPMaxWithPadding = REPMax - REPMax * this.ETHBuffer;
- return REPMaxWithPadding;
- },
postConfig: {
headers: {
'Content-Type': 'application/json; charset:UTF-8'
}
}
};
+
+export default info;
diff --git a/common/config/data.js b/common/config/data.js
index 0c5310a3..97cc8a5a 100644
--- a/common/config/data.js
+++ b/common/config/data.js
@@ -15,14 +15,25 @@ export const ANNOUNCEMENT_MESSAGE = `
If you're interested in recieving updates about the MyEtherWallet V4 Alpha, you can subscribe via
mailchimp :)
`;
-export const DONATION_ADDRESSES_MAP = {
+const etherScan = 'https://etherscan.io';
+const blockChainInfo = 'https://blockchain.info';
+const ethPlorer = 'https://ethplorer.io';
+
+export const ETHTxExplorer = (txHash: string): string =>
+ `${etherScan}/tx/${txHash}`;
+export const BTCTxExplorer = (txHash: string): string =>
+ `${blockChainInfo}/tx/${txHash}`;
+export const ETHAddressExplorer = (address: string): string =>
+ `${etherScan}/address/${address}`;
+export const ETHTokenExplorer = (address: string): string =>
+ `${ethPlorer}/address/${address}`;
+
+export const donationAddressMap = {
BTC: '1MEWT2SGbqtz6mPCgFcnea8XmWV5Z4Wc6',
ETH: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8',
REP: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8'
};
-export const donationAddressMap = DONATION_ADDRESSES_MAP;
-
export const gasPriceDefaults = {
gasPriceMinGwei: 1,
gasPriceMaxGwei: 60
@@ -142,12 +153,12 @@ export type NetworkConfig = {
unit: string,
blockExplorer?: {
name: string,
- tx: string,
- address: string
+ tx: Function,
+ address: Function
},
tokenExplorer?: {
name: string,
- address: string
+ address: Function
},
chainId: number,
tokens: Token[],
@@ -167,13 +178,13 @@ export const NETWORKS: { [key: string]: NetworkConfig } = {
unit: 'ETH',
chainId: 1,
blockExplorer: {
- name: 'https://etherscan.io',
- tx: 'https://etherscan.io/tx/[[txHash]]',
- address: 'https://etherscan.io/address/[[address]]'
+ name: etherScan,
+ tx: ETHTxExplorer,
+ address: ETHAddressExplorer
},
tokenExplorer: {
- name: 'Ethplorer.io',
- address: 'https://ethplorer.io/address/[[address]]'
+ name: ethPlorer,
+ address: ETHTokenExplorer
},
tokens: require('./tokens/eth').default,
contracts: require('./contracts/eth.json')
diff --git a/common/containers/Tabs/Swap/components/CurrencySwap.jsx b/common/containers/Tabs/Swap/components/CurrencySwap.jsx
index 62beccc0..6d2e40bf 100644
--- a/common/containers/Tabs/Swap/components/CurrencySwap.jsx
+++ b/common/containers/Tabs/Swap/components/CurrencySwap.jsx
@@ -11,7 +11,7 @@ import type {
DestinationAmountSwapAction,
ChangeStepSwapAction
} from 'actions/swapTypes';
-import bityConfig from 'config/bity';
+import bityConfig, { kindMin, kindMax } from 'config/bity';
import { toFixedIfLarger } from 'utils/formatters';
export type StateProps = {
@@ -46,8 +46,8 @@ export default class CurrencySwap extends Component {
let bityMax;
if (kind !== 'BTC') {
const bityPairRate = this.props.bityRates['BTC' + kind];
- bityMin = bityConfig[kind + 'Min'](bityPairRate);
- bityMax = bityConfig[kind + 'Max'](bityPairRate);
+ bityMin = kindMin(bityPairRate, kind);
+ bityMax = kindMax(bityPairRate, kind);
} else {
bityMin = bityConfig.BTCMin;
bityMax = bityConfig.BTCMax;
@@ -73,9 +73,9 @@ export default class CurrencySwap extends Component {
if (disabled && originAmount && !this.state.showedMinMaxError) {
const { bityRates } = this.props;
- const ETHMin = bityConfig.ETHMin(bityRates.BTCETH);
- const ETHMax = bityConfig.ETHMax(bityRates.BTCETH);
- const REPMin = bityConfig.REPMax(bityRates.BTCREP);
+ const ETHMin = kindMin(bityRates.BTCETH, 'ETH');
+ const ETHMax = kindMax(bityRates.BTCETH, 'ETH');
+ const REPMin = kindMin(bityRates.BTCREP, 'REP');
const notificationMessage = `
Minimum amount ${bityConfig.BTCMin} BTC,
diff --git a/common/containers/Tabs/Swap/components/SwapProgress.jsx b/common/containers/Tabs/Swap/components/SwapProgress.jsx
index 5a1b024e..1a38de7a 100644
--- a/common/containers/Tabs/Swap/components/SwapProgress.jsx
+++ b/common/containers/Tabs/Swap/components/SwapProgress.jsx
@@ -44,7 +44,7 @@ export default class SwapProgress extends Component {
const notificationMessage = translate('SUCCESS_3', true) + outputTx;
// everything but BTC is a token
if (destinationKind !== 'BTC') {
- link = bityConfig.ethExplorer.replace('[[txHash]]', outputTx);
+ link = bityConfig.ETHTxExplorer(outputTx);
linkElement = (
${notificationMessage}
@@ -52,7 +52,7 @@ export default class SwapProgress extends Component {
);
// BTC uses a different explorer
} else {
- link = bityConfig.btcExplorer.replace('[[txHash]]', outputTx);
+ link = bityConfig.BTCTxExplorer(outputTx);
linkElement = (
${notificationMessage}