2018-08-14 19:31:09 +00:00
|
|
|
import web3 from "Embark/web3"
|
2018-08-15 19:11:55 +00:00
|
|
|
import BigNumber from 'bignumber.js';
|
2018-08-14 19:31:09 +00:00
|
|
|
|
2018-08-15 19:11:55 +00:00
|
|
|
// By default BigNumber's `toString` method converts to exponential notation if the value has
|
|
|
|
// more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number
|
|
|
|
BigNumber.config({
|
|
|
|
EXPONENTIAL_AT: 1000,
|
|
|
|
});
|
|
|
|
const unlimitedAllowance = new BigNumber(2).pow(256).sub(1);
|
2018-08-14 19:31:09 +00:00
|
|
|
export const getDefaultAccount = () => web3.eth.defaultAccount;
|
2018-08-15 19:11:55 +00:00
|
|
|
export const toggleApproved = (token, spender, approved, onlyApprove = false) => {
|
|
|
|
const isApproved = !!Number(approved);
|
|
|
|
if (isApproved && onlyApprove) return;
|
|
|
|
const { approve } = token.methods;
|
|
|
|
const amountToApprove = isApproved ? 0 : unlimitedAllowance;
|
|
|
|
return approve(spender,amountToApprove).send();
|
|
|
|
}
|