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

Commit

Permalink
Merge pull request #2313 from bandprotocol/accumulate-commission
Browse files Browse the repository at this point in the history
Scan: add commission on account index page
  • Loading branch information
prin-r authored Jul 26, 2020
2 parents cdee312 + da1dcf8 commit 9ce4c4d
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
### Scan
- (impv) [\#2310](https://github.com/bandprotocol/bandchain/pull/2310) Implemented the TxIndexpage layout for mobile view
- (impv) [\#2305](https://github.com/bandprotocol/bandchain/pull/2305) Implement the TxHomepage layout for mobile view and adjusted the pagination on mobile view.
- (impv) [\#2313](https://github.com/bandprotocol/bandchain/pull/2313) Added commision amount on Account Index Page
- (feat) [\#2294](https://github.com/bandprotocol/bandchain/pull/2294) Implemented top part of `ValidatorIndexPage` for mobile
- (impv) [\#2299](https://github.com/bandprotocol/bandchain/pull/2299) Update the latest transactions table for mobile version.
- (bugs) [\#2290](https://github.com/bandprotocol/bandchain/pull/2290) Fix average block time calculation on `ValidatorHomePage` when using new cacher
Expand Down
112 changes: 112 additions & 0 deletions scan/graphql_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61818,6 +61818,22 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "accumulated_commission",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"description": null
},
{
"args": [
{
Expand Down Expand Up @@ -64113,6 +64129,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "String_comparison_exp",
"ofType": null
},
"description": null
},
{
"name": "blocks",
"defaultValue": null,
Expand Down Expand Up @@ -64480,6 +64506,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"name": "blocks",
"defaultValue": null,
Expand Down Expand Up @@ -64780,6 +64816,18 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "accumulated_commission",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"args": [],
"isDeprecated": false,
Expand Down Expand Up @@ -64986,6 +65034,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "commission_max_change",
"defaultValue": null,
Expand Down Expand Up @@ -65176,6 +65234,18 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "accumulated_commission",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"args": [],
"isDeprecated": false,
Expand Down Expand Up @@ -65382,6 +65452,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "commission_max_change",
"defaultValue": null,
Expand Down Expand Up @@ -65716,6 +65796,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "blocks_aggregate",
"defaultValue": null,
Expand Down Expand Up @@ -66008,6 +66098,12 @@
"name": "account_id",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
"name": "accumulated_commission",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
Expand Down Expand Up @@ -66138,6 +66234,16 @@
},
"description": null
},
{
"name": "accumulated_commission",
"defaultValue": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"name": "commission_max_change",
"defaultValue": null,
Expand Down Expand Up @@ -66966,6 +67072,12 @@
"name": "account_id",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
"name": "accumulated_commission",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
Expand Down
14 changes: 10 additions & 4 deletions scan/src/components/PieChart.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ let renderSegment = (offset, angle, color) =>
</>;

[@react.component]
let make = (~size, ~availableBalance, ~balanceAtStake, ~reward, ~unbonding) => {
let totalBalance = availableBalance +. balanceAtStake +. unbonding +. reward;
let make = (~size, ~availableBalance, ~balanceAtStake, ~reward, ~unbonding, ~commission) => {
let totalBalance = availableBalance +. balanceAtStake +. unbonding +. reward +. commission;
let balanceAtStakeAngle = totalBalance == 0. ? 0. : 360. *. balanceAtStake /. totalBalance;
let unbondingAngle = totalBalance == 0. ? 0. : 360. *. unbonding /. totalBalance;
let rewardAngle = totalBalance == 0. ? 0. : 360. *. reward /. totalBalance;
let commissionAngle = totalBalance == 0. ? 0. : 360. *. commission /. totalBalance;

<div className={Styles.pie(size, Colors.bandBlue)}>
{renderSegment(0., balanceAtStakeAngle, Colors.chartBalanceAtStake)}
{renderSegment(balanceAtStakeAngle, rewardAngle, Colors.chartReward)}
{renderSegment(balanceAtStakeAngle +. rewardAngle, unbondingAngle, Colors.blue4)}
{renderSegment(balanceAtStakeAngle, unbondingAngle, Colors.blue4)}
{renderSegment(balanceAtStakeAngle +. unbondingAngle, rewardAngle, Colors.chartReward)}
{renderSegment(
balanceAtStakeAngle +. unbondingAngle +. rewardAngle,
commissionAngle,
Colors.gray6,
)}
</div>;
};
28 changes: 26 additions & 2 deletions scan/src/pages/AccountIndexPage.re
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ let make = (~address, ~hashtag: Route.account_tab_t) =>

let availableBalance = account.balance->Coin.getBandAmountFromCoins;
let balanceAtStakeAmount = balanceAtStake.amount->Coin.getBandAmountFromCoin;
let rewardAmount = balanceAtStake.reward->Coin.getBandAmountFromCoin;
let unbondingAmount = unbonding->Coin.getBandAmountFromCoin;
let rewardAmount = balanceAtStake.reward->Coin.getBandAmountFromCoin;
let commissionAmount = account.commission->Coin.getBandAmountFromCoins;

let totalBalance =
availableBalance
+. balanceAtStakeAmount
+. rewardAmount
+. unbondingAmount
+. commissionAmount;

let totalBalance = availableBalance +. balanceAtStakeAmount +. rewardAmount +. unbondingAmount;
let send = () => {
switch (accountOpt) {
| Some({address: sender}) =>
Expand Down Expand Up @@ -223,6 +230,7 @@ let make = (~address, ~hashtag: Route.account_tab_t) =>
balanceAtStake=balanceAtStakeAmount
reward=rewardAmount
unbonding=unbondingAmount
commission=commissionAmount
/>
</Col>
<Col size=1.>
Expand Down Expand Up @@ -266,6 +274,22 @@ let make = (~address, ~hashtag: Route.account_tab_t) =>
~isCountup=true,
(),
)}
{commissionAmount == 0.
? React.null
: <>
<VSpacing size=Spacing.lg />
<VSpacing size=Spacing.md />
{balanceDetail(
~title="COMMISSION",
~description="Reward commission from delegator's reward",
~amount=commissionAmount,
~usdPrice,
~color=Colors.gray6,
~isCountup=true,
(),
)}
<VSpacing size=Spacing.lg />
</>}
</Col>
<div className=Styles.separatorLine />
<Col size=1. alignSelf=Col.Start>
Expand Down
32 changes: 30 additions & 2 deletions scan/src/subscriptions/AccountSub.re
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
type t = {balance: list(Coin.t)};
type t = {
balance: list(Coin.t),
commission: list(Coin.t),
};

type validator_t = {commission: list(Coin.t)};

type internal_t = {
balance: list(Coin.t),
validator: option(validator_t),
};

let toExternal = ({balance, validator}) => {
{
balance,
commission:
switch (validator) {
| Some(validator') => validator'.commission
| None => []
},
};
};

module SingleConfig = [%graphql
{|
subscription Account($address: String!) {
accounts_by_pk(address: $address) @bsRecord {
balance @bsDecoder(fn: "GraphQLParser.coins")
validator @bsRecord {
commission: accumulated_commission @bsDecoder(fn: "GraphQLParser.coins")
}
}
}
|}
Expand All @@ -16,5 +40,9 @@ let get = address => {
SingleConfig.definition,
~variables=SingleConfig.makeVariables(~address=address |> Address.toBech32, ()),
);
result |> Sub.map(_, x => x##accounts_by_pk |> Belt_Option.getWithDefault(_, {balance: []}));
result
|> Sub.map(_, x =>
x##accounts_by_pk
|> Belt_Option.mapWithDefault(_, {balance: [], commission: []}, toExternal)
);
};

0 comments on commit 9ce4c4d

Please sign in to comment.