Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #270 from juan-cortes/useAllAmount
Browse files Browse the repository at this point in the history
Added useAllAmount field to Transaction
  • Loading branch information
gre authored Jun 11, 2019
2 parents 51611cc + faf50b3 commit a5d0d2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
34 changes: 26 additions & 8 deletions src/bridge/LibcoreBitcoinAccountBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ export type Transaction = {
amount: BigNumber | string,
recipient: string,
feePerByte: ?(BigNumber | string),
networkInfo: ?{ feeItems: FeeItems }
networkInfo: ?{ feeItems: FeeItems },
useAllAmount?: boolean
};

const asLibcoreTransaction = ({ amount, recipient, feePerByte }) => ({
const asLibcoreTransaction = ({
amount,
recipient,
feePerByte
feePerByte,
useAllAmount
}) => ({
amount,
recipient,
feePerByte,
useAllAmount
});

const startSync = (initialAccount, _observation) => syncAccount(initialAccount);
Expand All @@ -41,7 +48,8 @@ const createTransaction = () => ({
amount: BigNumber(0),
recipient: "",
feePerByte: undefined,
networkInfo: null
networkInfo: null,
useAllAmount: false
});

const fetchTransactionNetworkInfo = async ({ currency }) => {
Expand Down Expand Up @@ -81,7 +89,12 @@ const editTransactionExtra = (a, t, field, value) => {
"editTransactionExtra(a,t,'feePerByte',value): BigNumber value expected"
);
return { ...t, feePerByte: value };

case "useAllAmount":
invariant(
typeof value === "boolean",
"editTransactionExtra(a,t,'useAllAmount',value): boolean value expected"
);
return { ...t, useAllAmount: value };
default:
return t;
}
Expand All @@ -91,7 +104,8 @@ const getTransactionExtra = (a, t, field) => {
switch (field) {
case "feePerByte":
return t.feePerByte;

case "useAllAmount":
return t.useAllAmount;
default:
return undefined;
}
Expand Down Expand Up @@ -131,9 +145,13 @@ const checkValidTransaction = async (a, t) =>
: getFees(a, t).then(() => null);

const getTotalSpent = async (a, t) =>
BigNumber(t.amount).isZero()
t.useAllAmount
? a.balance
: !t.amount || BigNumber(t.amount).isZero()
? Promise.resolve(BigNumber(0))
: getFees(a, t).then(totalFees => BigNumber(t.amount).plus(totalFees || 0));
: getFees(a, t).then(totalFees =>
BigNumber(t.amount || "0").plus(totalFees || 0)
);

const getMaxAmount = async (a, t) =>
getFees(a, t).then(totalFees => a.balance.minus(totalFees || 0));
Expand Down
4 changes: 1 addition & 3 deletions src/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ export function getAssetsDistribution(
const cur = account.type === "Account" ? account.currency : account.token;
const id = cur.id;
idCurrencies[id] = cur;
idBalances[id] = (idBalances[id] || BigNumber(0)).plus(
account.balance
);
idBalances[id] = (idBalances[id] || BigNumber(0)).plus(account.balance);
}

const idCountervalues = {};
Expand Down

0 comments on commit a5d0d2f

Please sign in to comment.