From f563ebf2d9d024dfc475136db549af6fab880063 Mon Sep 17 00:00:00 2001 From: wa-aal <93649819+wa-aal@users.noreply.github.com> Date: Wed, 9 Mar 2022 15:34:48 +0100 Subject: [PATCH] Cosmos JS (#1791) * be more conform between optimistic and final operation * use old code logic Co-authored-by: Alexandre Alouit --- src/families/cosmos/js-signOperation.ts | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index ddf1d8d5cf..0a0fec6449 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -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" @@ -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 = { @@ -129,7 +142,7 @@ const signOperation = ({ ? account.spendableBalance : transaction.amount.plus(fee), fee, - extra: {}, + extra, blockHash: null, blockHeight: null, senders, @@ -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: {