Refactor Bity (#166)
* Refactor bity config * fix bug in refactor that would cause destinationKind amount to not load * use function instead of string replace for building blockexplorers per PR comment
This commit is contained in:
parent
de7d4fbaa2
commit
0989424d73
|
@ -57,7 +57,7 @@ export function getOrderStatus(orderid: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getAllRates() {
|
function _getAllRates() {
|
||||||
return fetch(`${bityConfig.bityAPI}/v1/rate2/`)
|
return fetch(`${bityConfig.bityURL}/v1/rate2/`)
|
||||||
.then(checkHttpStatus)
|
.then(checkHttpStatus)
|
||||||
.then(parseJSON);
|
.then(parseJSON);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,19 +96,13 @@ export class BalanceSidebar extends React.Component {
|
||||||
<ul className="account-info">
|
<ul className="account-info">
|
||||||
{!!blockExplorer &&
|
{!!blockExplorer &&
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a href={blockExplorer.address(address)} target="_blank">
|
||||||
href={blockExplorer.address.replace('[[address]]', address)}
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
{`${network.name} (${blockExplorer.name})`}
|
{`${network.name} (${blockExplorer.name})`}
|
||||||
</a>
|
</a>
|
||||||
</li>}
|
</li>}
|
||||||
{!!tokenExplorer &&
|
{!!tokenExplorer &&
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a href={tokenExplorer.address(address)} target="_blank">
|
||||||
href={tokenExplorer.address.replace('[[address]]', address)}
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
{`Tokens (${tokenExplorer.name})`}
|
{`Tokens (${tokenExplorer.name})`}
|
||||||
</a>
|
</a>
|
||||||
</li>}
|
</li>}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import bityConfig from 'config/bity';
|
import { ETHTxExplorer } from 'config/data';
|
||||||
import translate from 'translations';
|
import translate from 'translations';
|
||||||
export type TransactionSucceededProps = {
|
export type TransactionSucceededProps = {
|
||||||
txHash: string
|
txHash: string
|
||||||
|
@ -7,7 +7,7 @@ export type TransactionSucceededProps = {
|
||||||
|
|
||||||
const TransactionSucceeded = ({ txHash }: TransactionSucceededProps) => {
|
const TransactionSucceeded = ({ txHash }: TransactionSucceededProps) => {
|
||||||
// const checkTxLink = `https://www.myetherwallet.com?txHash=${txHash}/#check-tx-status`;
|
// const checkTxLink = `https://www.myetherwallet.com?txHash=${txHash}/#check-tx-status`;
|
||||||
const txHashLink = bityConfig.ethExplorer.replace('[[txHash]]', txHash);
|
const txHashLink = ETHTxExplorer(txHash);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,39 +1,52 @@
|
||||||
export default {
|
import { ETHTxExplorer, BTCTxExplorer } from './data';
|
||||||
serverURL: 'https://bity.myetherapi.com',
|
|
||||||
bityAPI: 'https://bity.com/api',
|
type SupportedDestinationKind = 'ETH' | 'BTC' | 'REP';
|
||||||
ethExplorer: 'https://etherscan.io/tx/[[txHash]]',
|
|
||||||
btcExplorer: 'https://blockchain.info/tx/[[txHash]]',
|
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'],
|
validStatus: ['RCVE', 'FILL', 'CONF', 'EXEC'],
|
||||||
invalidStatus: ['CANC'],
|
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: {
|
postConfig: {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json; charset:UTF-8'
|
'Content-Type': 'application/json; charset:UTF-8'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default info;
|
||||||
|
|
|
@ -15,14 +15,25 @@ export const ANNOUNCEMENT_MESSAGE = `
|
||||||
If you're interested in recieving updates about the MyEtherWallet V4 Alpha, you can subscribe via <a href="http://myetherwallet.us16.list-manage.com/subscribe?u=afced8afb6eb2968ba407a144&id=15a7c74eab">mailchimp</a> :)
|
If you're interested in recieving updates about the MyEtherWallet V4 Alpha, you can subscribe via <a href="http://myetherwallet.us16.list-manage.com/subscribe?u=afced8afb6eb2968ba407a144&id=15a7c74eab">mailchimp</a> :)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
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',
|
BTC: '1MEWT2SGbqtz6mPCgFcnea8XmWV5Z4Wc6',
|
||||||
ETH: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8',
|
ETH: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8',
|
||||||
REP: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8'
|
REP: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const donationAddressMap = DONATION_ADDRESSES_MAP;
|
|
||||||
|
|
||||||
export const gasPriceDefaults = {
|
export const gasPriceDefaults = {
|
||||||
gasPriceMinGwei: 1,
|
gasPriceMinGwei: 1,
|
||||||
gasPriceMaxGwei: 60
|
gasPriceMaxGwei: 60
|
||||||
|
@ -142,12 +153,12 @@ export type NetworkConfig = {
|
||||||
unit: string,
|
unit: string,
|
||||||
blockExplorer?: {
|
blockExplorer?: {
|
||||||
name: string,
|
name: string,
|
||||||
tx: string,
|
tx: Function,
|
||||||
address: string
|
address: Function
|
||||||
},
|
},
|
||||||
tokenExplorer?: {
|
tokenExplorer?: {
|
||||||
name: string,
|
name: string,
|
||||||
address: string
|
address: Function
|
||||||
},
|
},
|
||||||
chainId: number,
|
chainId: number,
|
||||||
tokens: Token[],
|
tokens: Token[],
|
||||||
|
@ -167,13 +178,13 @@ export const NETWORKS: { [key: string]: NetworkConfig } = {
|
||||||
unit: 'ETH',
|
unit: 'ETH',
|
||||||
chainId: 1,
|
chainId: 1,
|
||||||
blockExplorer: {
|
blockExplorer: {
|
||||||
name: 'https://etherscan.io',
|
name: etherScan,
|
||||||
tx: 'https://etherscan.io/tx/[[txHash]]',
|
tx: ETHTxExplorer,
|
||||||
address: 'https://etherscan.io/address/[[address]]'
|
address: ETHAddressExplorer
|
||||||
},
|
},
|
||||||
tokenExplorer: {
|
tokenExplorer: {
|
||||||
name: 'Ethplorer.io',
|
name: ethPlorer,
|
||||||
address: 'https://ethplorer.io/address/[[address]]'
|
address: ETHTokenExplorer
|
||||||
},
|
},
|
||||||
tokens: require('./tokens/eth').default,
|
tokens: require('./tokens/eth').default,
|
||||||
contracts: require('./contracts/eth.json')
|
contracts: require('./contracts/eth.json')
|
||||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
||||||
DestinationAmountSwapAction,
|
DestinationAmountSwapAction,
|
||||||
ChangeStepSwapAction
|
ChangeStepSwapAction
|
||||||
} from 'actions/swapTypes';
|
} from 'actions/swapTypes';
|
||||||
import bityConfig from 'config/bity';
|
import bityConfig, { kindMin, kindMax } from 'config/bity';
|
||||||
import { toFixedIfLarger } from 'utils/formatters';
|
import { toFixedIfLarger } from 'utils/formatters';
|
||||||
|
|
||||||
export type StateProps = {
|
export type StateProps = {
|
||||||
|
@ -46,8 +46,8 @@ export default class CurrencySwap extends Component {
|
||||||
let bityMax;
|
let bityMax;
|
||||||
if (kind !== 'BTC') {
|
if (kind !== 'BTC') {
|
||||||
const bityPairRate = this.props.bityRates['BTC' + kind];
|
const bityPairRate = this.props.bityRates['BTC' + kind];
|
||||||
bityMin = bityConfig[kind + 'Min'](bityPairRate);
|
bityMin = kindMin(bityPairRate, kind);
|
||||||
bityMax = bityConfig[kind + 'Max'](bityPairRate);
|
bityMax = kindMax(bityPairRate, kind);
|
||||||
} else {
|
} else {
|
||||||
bityMin = bityConfig.BTCMin;
|
bityMin = bityConfig.BTCMin;
|
||||||
bityMax = bityConfig.BTCMax;
|
bityMax = bityConfig.BTCMax;
|
||||||
|
@ -73,9 +73,9 @@ export default class CurrencySwap extends Component {
|
||||||
|
|
||||||
if (disabled && originAmount && !this.state.showedMinMaxError) {
|
if (disabled && originAmount && !this.state.showedMinMaxError) {
|
||||||
const { bityRates } = this.props;
|
const { bityRates } = this.props;
|
||||||
const ETHMin = bityConfig.ETHMin(bityRates.BTCETH);
|
const ETHMin = kindMin(bityRates.BTCETH, 'ETH');
|
||||||
const ETHMax = bityConfig.ETHMax(bityRates.BTCETH);
|
const ETHMax = kindMax(bityRates.BTCETH, 'ETH');
|
||||||
const REPMin = bityConfig.REPMax(bityRates.BTCREP);
|
const REPMin = kindMin(bityRates.BTCREP, 'REP');
|
||||||
|
|
||||||
const notificationMessage = `
|
const notificationMessage = `
|
||||||
Minimum amount ${bityConfig.BTCMin} BTC,
|
Minimum amount ${bityConfig.BTCMin} BTC,
|
||||||
|
|
|
@ -44,7 +44,7 @@ export default class SwapProgress extends Component {
|
||||||
const notificationMessage = translate('SUCCESS_3', true) + outputTx;
|
const notificationMessage = translate('SUCCESS_3', true) + outputTx;
|
||||||
// everything but BTC is a token
|
// everything but BTC is a token
|
||||||
if (destinationKind !== 'BTC') {
|
if (destinationKind !== 'BTC') {
|
||||||
link = bityConfig.ethExplorer.replace('[[txHash]]', outputTx);
|
link = bityConfig.ETHTxExplorer(outputTx);
|
||||||
linkElement = (
|
linkElement = (
|
||||||
<a href={link} target="_blank" rel="noopener">
|
<a href={link} target="_blank" rel="noopener">
|
||||||
${notificationMessage}
|
${notificationMessage}
|
||||||
|
@ -52,7 +52,7 @@ export default class SwapProgress extends Component {
|
||||||
);
|
);
|
||||||
// BTC uses a different explorer
|
// BTC uses a different explorer
|
||||||
} else {
|
} else {
|
||||||
link = bityConfig.btcExplorer.replace('[[txHash]]', outputTx);
|
link = bityConfig.BTCTxExplorer(outputTx);
|
||||||
linkElement = (
|
linkElement = (
|
||||||
<a href={link} target="_blank" rel="noopener">
|
<a href={link} target="_blank" rel="noopener">
|
||||||
${notificationMessage}
|
${notificationMessage}
|
||||||
|
|
Loading…
Reference in New Issue