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

Scan: Implement reinvest #2854

Merged
merged 18 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

### Scan

- (impv) [\#2854](https://github.com/bandprotocol/bandchain/pull/2854) Implement reinvest
Pitchanai marked this conversation as resolved.
Show resolved Hide resolved
- (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
Expand Down
14 changes: 13 additions & 1 deletion scan/cypress/integration/send_action.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
})
});
67 changes: 46 additions & 21 deletions scan/src/components/modal/ValidatorStakingInfo.re
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -140,9 +139,22 @@ 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 = () =>
Pitchanai marked this conversation as resolved.
Show resolved Hide resolved
(
validatorAddress,
switch (balanceAtStakeSub) {
| Data({reward: {amount}}) => amount
| _ => 0.
},
)
->SubmitMsg.Reinvest
->SubmitTx
->OpenModal
->dispatchModal;
<>
<Row.Grid marginBottom=24>
<Col.Grid>
Expand Down Expand Up @@ -187,9 +199,7 @@ module StakingInfo = {
</Row.Grid>
<Row.Grid style=Styles.rewardContainer alignItems=Row.Center>
<Col.Grid>
<div
className={CssHelper.flexBox(~justify=`spaceBetween, ())}
id="withdrawRewardContainer">
<div className={CssHelper.flexBox(~justify=`spaceBetween, ())}>
<div>
<Heading value="Reward" size=Heading.H5 />
<VSpacing size={`px(8)} />
Expand All @@ -199,18 +209,33 @@ module StakingInfo = {
| _ => <DisplayBalance.Loading />
}}
</div>
<Button
px=20
py=5
onClick={_ => withdrawReward()}
disabled={
switch (allSub) {
| Data((_, balanceAtStake, _)) => balanceAtStake.reward.amount <= 0.
| _ => true
}
}>
<Text value="Withdraw Reward" weight=Text.Medium nowrap=true block=true />
</Button>
<div className={CssHelper.flexBox()} id="withdrawRewardContainer">
<Button
px=20
py=5
onClick={_ => withdrawReward()}
disabled={
switch (allSub) {
| Data((_, balanceAtStake, _)) => balanceAtStake.reward.amount <= 0.
| _ => true
}
}>
<Text value="Withdraw Reward" weight=Text.Medium nowrap=true block=true />
</Button>
<HSpacing size=Spacing.sm />
<Button
px=20
py=5
onClick={_ => reinvest()}
disabled={
switch (allSub) {
| Data((_, balanceAtStake, _)) => balanceAtStake.reward.amount <= 0.
| _ => true
}
}>
<Text value="Reinvest" weight=Text.Medium nowrap=true block=true />
</Button>
Pitchanai marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
</Col.Grid>
</Row.Grid>
Expand Down
73 changes: 73 additions & 0 deletions scan/src/components/modal/submitTx/ReinvestMsg.re
Original file line number Diff line number Diff line change
@@ -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"},
Pitchanai marked this conversation as resolved.
Show resolved Hide resolved
),
|]);
};
setMsgsOpt(_ => msgsOpt);
None;
});

<>
<div className=Styles.container>
<Heading
value="Reinvest to"
size=Heading.H5
marginBottom=8
align=Heading.Left
weight=Heading.Medium
/>
{switch (validatorInfoSub) {
| Data({moniker}) =>
<div>
<Text value=moniker size=Text.Lg ellipsis=true align=Text.Right />
<Text
value={"(" ++ validator->Address.toOperatorBech32 ++ ")"}
size=Text.Md
color=Colors.gray6
code=true
block=true
/>
</div>
| _ => <LoadingCensorBar width=300 height=34 />
}}
</div>
<div className=Styles.container>
<Heading
value="Current Reward"
size=Heading.H5
marginBottom=8
align=Heading.Left
weight=Heading.Medium
/>
<div>
<Text
value={
amount
|> Coin.newUBANDFromAmount
|> Coin.getBandAmountFromCoin
|> Format.fPretty(~digits=6)
}
code=true
size=Text.Lg
/>
<Text value=" BAND" size=Text.Lg code=true />
</div>
</div>
</>;
};
1 change: 1 addition & 0 deletions scan/src/components/modal/submitTx/SubmitTxModal.re
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module SubmitTxStep = {
| Redelegate(validator) => <RedelegateMsg address={account.address} validator setMsgsOpt />
| WithdrawReward(validator) =>
<WithdrawRewardMsg validator setMsgsOpt address={account.address} />
| Reinvest(validator, amount) => <ReinvestMsg validator setMsgsOpt amount />
| Vote(proposalID, proposalName) => <VoteMsg proposalID proposalName setMsgsOpt />
}}
<EnhanceTxInput
Expand Down
5 changes: 4 additions & 1 deletion scan/src/utils/SubmitMsg.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type t =
| Undelegate(Address.t)
| Redelegate(Address.t)
| WithdrawReward(Address.t)
| Reinvest(Address.t, float)
| Vote(ID.Proposal.t, string);

let toString =
Expand All @@ -13,6 +14,7 @@ let toString =
| Undelegate(_) => "Undelegate"
| Redelegate(_) => "Redelegate"
| WithdrawReward(_) => "Withdraw Reward"
| Reinvest(_) => "Reinvest"
| Vote(_) => "Vote";

let gasLimit =
Expand All @@ -21,5 +23,6 @@ let gasLimit =
| Delegate(_)
| Undelegate(_)
| Vote(_)
| WithdrawReward(_) => 200000
| WithdrawReward(_)
| Reinvest(_) => 200000
| Redelegate(_) => 300000;