From 9539a64a570c90bf5117a3cbb0288f9e66de0af1 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Tue, 10 Nov 2020 14:52:33 +0700 Subject: [PATCH 01/10] add reinvest --- .../components/modal/ValidatorStakingInfo.re | 26 ++++++- .../components/modal/submitTx/ReinvestMsg.re | 73 +++++++++++++++++++ .../modal/submitTx/SubmitTxModal.re | 1 + scan/src/utils/SubmitMsg.re | 5 +- 4 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 scan/src/components/modal/submitTx/ReinvestMsg.re diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index 5872f4bd10..29f5b9df19 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -143,6 +143,20 @@ module StakingInfo = { let withdrawReward = () => dispatchModal(OpenModal(SubmitTx(SubmitMsg.WithdrawReward(validatorAddress)))); + let reinvest = () => + dispatchModal( + OpenModal( + SubmitTx( + SubmitMsg.Reinvest( + validatorAddress, + switch (balanceAtStakeSub) { + | Data({reward: {amount}}) => amount + | _ => 0. + }, + ), + ), + ), + ); <> @@ -199,9 +213,15 @@ module StakingInfo = { | _ => }} - +
+ + + +
diff --git a/scan/src/components/modal/submitTx/ReinvestMsg.re b/scan/src/components/modal/submitTx/ReinvestMsg.re new file mode 100644 index 0000000000..e84acebe67 --- /dev/null +++ b/scan/src/components/modal/submitTx/ReinvestMsg.re @@ -0,0 +1,73 @@ +module Styles = { + open Css; + + let container = style([paddingBottom(`px(24))]); +}; + +[@react.component] +let make = (~validator, ~amount, ~setMsgsOpt) => { + let validatorInfoSub = ValidatorSub.get(validator); + + React.useEffect0(_ => { + let msgsOpt = { + let%Opt amountValue = Some(amount); + Some([| + TxCreator.WithdrawReward(validator), + TxCreator.Delegate( + validator, + {amount: amountValue |> Js.Float.toFixedWithPrecision(~digits=0), denom: "uband"}, + ), + |]); + }; + setMsgsOpt(_ => msgsOpt); + None; + }); + + <> +
+ + {switch (validatorInfoSub) { + | Data({moniker}) => +
+ + Address.toOperatorBech32 ++ ")"} + size=Text.Md + color=Colors.gray6 + code=true + block=true + /> +
+ | _ => + }} +
+
+ +
+ Coin.newUBANDFromAmount + |> Coin.getBandAmountFromCoin + |> Format.fPretty(~digits=6) + } + code=true + size=Text.Lg + /> + +
+
+ ; +}; diff --git a/scan/src/components/modal/submitTx/SubmitTxModal.re b/scan/src/components/modal/submitTx/SubmitTxModal.re index 5f55e6de68..22400c8857 100644 --- a/scan/src/components/modal/submitTx/SubmitTxModal.re +++ b/scan/src/components/modal/submitTx/SubmitTxModal.re @@ -94,6 +94,7 @@ module SubmitTxStep = { | Redelegate(validator) => | WithdrawReward(validator) => + | Reinvest(validator, amount) => | Vote(proposalID, proposalName) => }} "Undelegate" | Redelegate(_) => "Redelegate" | WithdrawReward(_) => "Withdraw Reward" + | Reinvest(_) => "Reinvest" | Vote(_) => "Vote"; let gasLimit = @@ -21,5 +23,6 @@ let gasLimit = | Delegate(_) | Undelegate(_) | Vote(_) - | WithdrawReward(_) => 200000 + | WithdrawReward(_) + | Reinvest(_) => 200000 | Redelegate(_) => 300000; From 21a60de9cf6838fc708802d6073b6394755f1e6a Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Tue, 10 Nov 2020 14:57:32 +0700 Subject: [PATCH 02/10] update changelog --- CHANGELOG_UNRELEASED.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG_UNRELEASED.md b/CHANGELOG_UNRELEASED.md index 76a827ce39..2f38c65a66 100644 --- a/CHANGELOG_UNRELEASED.md +++ b/CHANGELOG_UNRELEASED.md @@ -32,6 +32,7 @@ ### Scan +- (impv) [\#2854](https://github.com/bandprotocol/bandchain/pull/2854) Implement reinvest - (impv) [\#2798](https://github.com/bandprotocol/bandchain/pull/2798) Added the warning msg to max button on send/delegate msg - (impv) [\#2766](https://github.com/bandprotocol/bandchain/pull/2766) Revamp undelegate, redelegate, withdraw reward and vote modal - (chore) [\#2767](https://github.com/bandprotocol/bandchain/pull/2767) Revamp send token modal From 38ebdb293596f8ef1f31305d45469044662f92de Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Tue, 10 Nov 2020 15:36:03 +0700 Subject: [PATCH 03/10] fix cypress --- scan/cypress/integration/send_action.spec.js | 2 +- scan/src/components/modal/ValidatorStakingInfo.re | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scan/cypress/integration/send_action.spec.js b/scan/cypress/integration/send_action.spec.js index c2ffa7fb2f..e95c029332 100644 --- a/scan/cypress/integration/send_action.spec.js +++ b/scan/cypress/integration/send_action.spec.js @@ -96,7 +96,7 @@ describe("Delegation", () => { }); it("Should be able to withdraw reward with Carol", () => { - cy.get('[id="withdrawRewardContainer"] > button').click().wait(1000); + cy.get('[id="withdrawRewardContainer"] > button:nth-of-type(1)').click().wait(1000); cy.get('[id="memoInput"]').type("cypress"); cy.get('[id="nextButtonContainer"] > button').click().wait(1000); cy.get('[id="broadcastButtonContainer"] > button').click().wait(1000); diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index 29f5b9df19..fc1a337388 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -201,9 +201,7 @@ module StakingInfo = { -
+
@@ -213,7 +211,7 @@ module StakingInfo = { | _ => }}
-
+
From 16310ddd81d89627d282216470a6b42ab7cfcf82 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Thu, 12 Nov 2020 15:34:14 +0700 Subject: [PATCH 04/10] change code format --- .../components/modal/ValidatorStakingInfo.re | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index fc1a337388..2b8cdbdde2 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -144,19 +144,17 @@ module StakingInfo = { dispatchModal(OpenModal(SubmitTx(SubmitMsg.WithdrawReward(validatorAddress)))); let reinvest = () => - dispatchModal( - OpenModal( - SubmitTx( - SubmitMsg.Reinvest( - validatorAddress, - switch (balanceAtStakeSub) { - | Data({reward: {amount}}) => amount - | _ => 0. - }, - ), - ), - ), - ); + ( + validatorAddress, + switch (balanceAtStakeSub) { + | Data({reward: {amount}}) => amount + | _ => 0. + }, + ) + ->SubmitMsg.Reinvest + ->SubmitTx + ->OpenModal + ->dispatchModal; <> From fb94b6350073fa9c5b1f77c5f59d64357d775c46 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 10:51:59 +0700 Subject: [PATCH 05/10] update code format for openModal --- scan/src/components/modal/ValidatorStakingInfo.re | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index 2b8cdbdde2..29d8630711 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -29,12 +29,11 @@ module ButtonSection = { let (_, dispatchModal) = React.useContext(ModalContext.context); let validatorInfoSub = ValidatorSub.get(validatorAddress); - let delegate = () => - dispatchModal(OpenModal(SubmitTx(SubmitMsg.Delegate(validatorAddress)))); + let delegate = () => validatorAddress->SubmitMsg.Delegate->SubmitTx->OpenModal->dispatchModal; let undelegate = () => - dispatchModal(OpenModal(SubmitTx(SubmitMsg.Undelegate(validatorAddress)))); + validatorAddress->SubmitMsg.Undelegate->SubmitTx->OpenModal->dispatchModal; let redelegate = () => - dispatchModal(OpenModal(SubmitTx(SubmitMsg.Redelegate(validatorAddress)))); + validatorAddress->SubmitMsg.Redelegate->SubmitTx->OpenModal->dispatchModal; switch (validatorInfoSub) { | Data(validatorInfo) => @@ -140,8 +139,9 @@ module StakingInfo = { let allSub = Sub.all3(infoSub, balanceAtStakeSub, unbondingSub); - let withdrawReward = () => - dispatchModal(OpenModal(SubmitTx(SubmitMsg.WithdrawReward(validatorAddress)))); + let withdrawReward = () => { + validatorAddress->SubmitMsg.WithdrawReward->SubmitTx->OpenModal->dispatchModal; + }; let reinvest = () => ( From c66bd9eb0c38385f9d2bcca9baa063af5077779b Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 11:03:59 +0700 Subject: [PATCH 06/10] add reinvest cypress test --- scan/cypress/integration/send_action.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scan/cypress/integration/send_action.spec.js b/scan/cypress/integration/send_action.spec.js index 96fe468fac..b623e51cbe 100644 --- a/scan/cypress/integration/send_action.spec.js +++ b/scan/cypress/integration/send_action.spec.js @@ -106,4 +106,16 @@ describe("Delegation", () => { ); cy.get('[id="closeModal"]').click(); }); + + it("Should be able to reinvest with Carol", () => { + cy.get('[id="withdrawRewardContainer"] > button:nth-of-type(2)').click().wait(1000); + cy.get('[id="memoInput"]').type("cypress"); + cy.get('[id="nextButtonContainer"] > button').click().wait(1000); + cy.get('[id="broadcastButtonContainer"] > button').click().wait(1000); + cy.get('[id="successMsgContainer"] > span').should( + "contain", + "Broadcast transaction success" + ); + cy.get('[id="closeModal"]').click(); + }) }); From 66c0261f8220a8701a9a62763bc0fb7d253e1f14 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 11:40:25 +0700 Subject: [PATCH 07/10] Add disabled on reinvest button --- .../components/modal/ValidatorStakingInfo.re | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index 84f1c405d7..409fdb3683 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -210,9 +210,9 @@ module StakingInfo = { }}
- -
From 0c8eb17fcf70ae8ff21b5168ba9e05e1721d6529 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 19:44:31 +0700 Subject: [PATCH 08/10] change changelog from impv to feat --- CHANGELOG_UNRELEASED.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG_UNRELEASED.md b/CHANGELOG_UNRELEASED.md index f074c558bc..0f65af090a 100644 --- a/CHANGELOG_UNRELEASED.md +++ b/CHANGELOG_UNRELEASED.md @@ -32,7 +32,7 @@ ### Scan -- (impv) [\#2854](https://github.com/bandprotocol/bandchain/pull/2854) Implement reinvest +- (feat) [\#2854](https://github.com/bandprotocol/bandchain/pull/2854) Implement reinvest - (bugs) [\#2868](https://github.com/bandprotocol/bandchain/pull/2868) Fixed click outside icon bug - (impv) [\#2851](https://github.com/bandprotocol/bandchain/pull/2851) Add ESC key event listener - (impv) [\#2850](https://github.com/bandprotocol/bandchain/pull/2850) Disable withdraw rewards if reward is zero From 575913370ea4e99f277e5ab5bf5e93c206fcfe60 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 20:00:44 +0700 Subject: [PATCH 09/10] move button inside allsub to get disable and reward value --- .../components/modal/ValidatorStakingInfo.re | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/scan/src/components/modal/ValidatorStakingInfo.re b/scan/src/components/modal/ValidatorStakingInfo.re index 409fdb3683..3d34c496f7 100644 --- a/scan/src/components/modal/ValidatorStakingInfo.re +++ b/scan/src/components/modal/ValidatorStakingInfo.re @@ -143,18 +143,8 @@ module StakingInfo = { validatorAddress->SubmitMsg.WithdrawReward->SubmitTx->OpenModal->dispatchModal; }; - let reinvest = () => - ( - validatorAddress, - switch (balanceAtStakeSub) { - | Data({reward: {amount}}) => amount - | _ => 0. - }, - ) - ->SubmitMsg.Reinvest - ->SubmitTx - ->OpenModal - ->dispatchModal; + let reinvest = reward => + (validatorAddress, reward)->SubmitMsg.Reinvest->SubmitTx->OpenModal->dispatchModal; <> @@ -210,31 +200,24 @@ module StakingInfo = { }}
- - - + {let (disable, reward) = + switch (allSub) { + | Data((_, balanceAtStake, _)) => ( + balanceAtStake.reward.amount <= 0., + balanceAtStake.reward.amount, + ) + | _ => (true, 0.) + }; + + <> + + + + }
From 55e68fa2de420f06b69b791895d5d712f9aab268 Mon Sep 17 00:00:00 2001 From: Pitchanai Thitipakorn Date: Fri, 13 Nov 2020 20:02:33 +0700 Subject: [PATCH 10/10] use Math.floor_float instead of float.toSting() --- scan/src/components/modal/submitTx/ReinvestMsg.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scan/src/components/modal/submitTx/ReinvestMsg.re b/scan/src/components/modal/submitTx/ReinvestMsg.re index e84acebe67..c87bb4663e 100644 --- a/scan/src/components/modal/submitTx/ReinvestMsg.re +++ b/scan/src/components/modal/submitTx/ReinvestMsg.re @@ -15,7 +15,7 @@ let make = (~validator, ~amount, ~setMsgsOpt) => { TxCreator.WithdrawReward(validator), TxCreator.Delegate( validator, - {amount: amountValue |> Js.Float.toFixedWithPrecision(~digits=0), denom: "uband"}, + {amount: amountValue->Js.Math.floor_float->Js.Float.toString, denom: "uband"}, ), |]); };