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

LIVE-1940 Ledger first inside cosmos validator list #1948

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/families/cosmos/js-buildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ export const buildTransaction = async (
if (!transaction.validators || transaction.validators.length < 1) {
isComplete = false;
} else {
transaction.validators.forEach((validator) => {
if (!validator.address || validator.amount.lte(0)) {
isComplete = false;
}

msg.push({
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: {
delegatorAddress: account.freshAddress,
validatorAddress: validator.address,
amount: {
denom: account.currency.units[1].code,
amount: validator.amount.toString(),
},
const validator = transaction.validators[0];
if (!validator) {
isComplete = false;
break;
henri-ly marked this conversation as resolved.
Show resolved Hide resolved
} else if (!validator.address || transaction.amount.lte(0)) {
isComplete = false;
}

msg.push({
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: {
delegatorAddress: account.freshAddress,
validatorAddress: validator.address,
amount: {
denom: account.currency.units[1].code,
amount: transaction.amount.toString(),
},
});
},
});
}
break;
Expand Down
26 changes: 11 additions & 15 deletions src/families/cosmos/js-getTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,19 @@ const getDelegateTransactionStatus = async (
errors.validators = new CosmosTooManyValidators();
}

let amount = t.validators.reduce(
(old, current) => old.plus(current.amount),
new BigNumber(0)
);

if (amount.eq(0)) {
errors.amount = new AmountRequired();
}

const estimatedFees = t.fees || new BigNumber(0);

if (!t.fees) {
if (!t.fees || !t.fees.gt(0)) {
errors.fees = new FeeNotLoaded();
}

let totalSpent = amount.plus(estimatedFees);
const amount = t.useAllAmount
? getMaxEstimatedBalance(a, estimatedFees)
: t.amount;
const totalSpent = amount.plus(estimatedFees);

if (totalSpent.eq(a.spendableBalance)) {
warnings.delegate = new CosmosDelegateAllFundsWarning();
if (amount.eq(0)) {
errors.amount = new AmountRequired();
}

if (
Expand All @@ -173,8 +167,10 @@ const getDelegateTransactionStatus = async (
(amount.lt(0) || totalSpent.gt(a.spendableBalance))
) {
errors.amount = new NotEnoughBalance();
amount = new BigNumber(0);
totalSpent = new BigNumber(0);
}

if (!errors.amount && t.useAllAmount) {
warnings.amount = new CosmosDelegateAllFundsWarning();
}

return Promise.resolve({
Expand Down
19 changes: 12 additions & 7 deletions src/families/cosmos/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
CosmosRedelegation,
CosmosMappedRedelegation,
} from "./types";
import type { Unit, Account } from "../../types";
import type { Unit, Account, Transaction } from "../../types";
import { calculateFees } from "./js-prepareTransaction";

export const COSMOS_MAX_REDELEGATIONS = 7;
Expand Down Expand Up @@ -99,16 +99,21 @@ export function mapRedelegations(
export const mapDelegationInfo = (
delegations: CosmosDelegationInfo[],
validators: CosmosValidatorItem[],
unit: Unit
unit: Unit,
transaction?: Transaction
): CosmosMappedDelegationInfo[] => {
return delegations.map((d) => ({
...d,
validator: validators.find((v) => v.validatorAddress === d.address),
formattedAmount: formatCurrencyUnit(unit, d.amount, {
disableRounding: true,
alwaysShowSign: false,
showCode: true,
}),
formattedAmount: formatCurrencyUnit(
unit,
transaction ? transaction.amount : d.amount,
{
disableRounding: true,
alwaysShowSign: false,
showCode: true,
}
),
}));
};
export const formatValue = (value: BigNumber, unit: Unit): number =>
Expand Down
Loading