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

Cosmos JS #1791

Merged
3 commits merged into from Mar 9, 2022
Merged
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
35 changes: 16 additions & 19 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const signOperation = ({
const hash = ""; // resolved at broadcast time
const accountId = account.id;
const fee = transaction.fees || new BigNumber(0);
const extra = {};

const type: OperationType =
transaction.mode === "undelegate"
Expand All @@ -117,8 +118,20 @@ const signOperation = ({
? "REWARD"
: "OUT";

const senders: string[] = [];
const recipients: string[] = [];
const senders: string[] = [account.freshAddress];
const recipients: string[] = [transaction.recipient];

if (transaction.mode === "redelegate") {
Object.assign(extra, {
cosmosSourceValidator: transaction.cosmosSourceValidator,
});
}

if (transaction.mode !== "send") {
Object.assign(extra, {
validators: transaction.validators,
});
}

// build optimistic operation
const operation: Operation = {
Expand All @@ -129,7 +142,7 @@ const signOperation = ({
? account.spendableBalance
: transaction.amount.plus(fee),
fee,
extra: {},
extra,
blockHash: null,
blockHeight: null,
senders,
Expand All @@ -138,22 +151,6 @@ const signOperation = ({
date: new Date(),
};

switch (type) {
case "OUT":
operation.senders.push(account.freshAddress);
operation.recipients.push(transaction.recipient);
break;

case "REWARD":
case "DELEGATE":
case "UNDELEGATE":
operation.value = new BigNumber(fee);
operation.extra.validators = transaction.validators;
operation.extra.cosmosSourceValidator =
transaction.cosmosSourceValidator;
break;
}

o.next({
type: "signed",
signedOperation: {
Expand Down