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 #2234 from bandprotocol/patch-received-msg
Browse files Browse the repository at this point in the history
scan: added received msg
  • Loading branch information
Kanisorn Thongprapaisaeng authored Jul 15, 2020
2 parents a546fa3 + 2b55ef2 commit 8236e43
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

### Scan

- (impv) [\#2234](https://github.com/bandprotocol/bandchain/pull/2234) Added support for `received` transaction on scan
- (bugs) [\#2236](https://github.com/bandprotocol/bandchain/pull/2236) Fixed uptime query on ValidatorIndexPage
- (impv) [\#2203](https://github.com/bandprotocol/bandchain/pull/2203/files) Patch request, report subscription for new cacher.
- (impv) [\#2176](https://github.com/bandprotocol/bandchain/pull/2176/files) Fixed delegations/unbonding subs, avg blocktime and validator uptime to work with new cacher.
Expand Down
82 changes: 82 additions & 0 deletions scan/graphql_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12388,6 +12388,18 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "identity",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"args": [],
"isDeprecated": false,
Expand Down Expand Up @@ -12926,6 +12938,16 @@
},
"description": null
},
{
"name": "identity",
"defaultValue": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "String_comparison_exp",
"ofType": null
},
"description": null
},
{
"name": "moniker",
"defaultValue": null,
Expand Down Expand Up @@ -13008,6 +13030,18 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "identity",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"args": [],
"isDeprecated": false,
Expand Down Expand Up @@ -13080,6 +13114,16 @@
},
"description": null
},
{
"name": "identity",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "moniker",
"defaultValue": null,
Expand Down Expand Up @@ -13162,6 +13206,18 @@
},
"description": null
},
{
"args": [],
"isDeprecated": false,
"deprecationReason": null,
"name": "identity",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"description": null
},
{
"args": [],
"isDeprecated": false,
Expand Down Expand Up @@ -13234,6 +13290,16 @@
},
"description": null
},
{
"name": "identity",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "moniker",
"defaultValue": null,
Expand Down Expand Up @@ -13305,6 +13371,16 @@
},
"description": null
},
{
"name": "identity",
"defaultValue": null,
"type": {
"kind": "ENUM",
"name": "order_by",
"ofType": null
},
"description": null
},
{
"name": "moniker",
"defaultValue": null,
Expand Down Expand Up @@ -13373,6 +13449,12 @@
"name": "delegator_address",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
"name": "identity",
"description": "column name"
},
{
"isDeprecated": false,
"deprecationReason": null,
Expand Down
29 changes: 24 additions & 5 deletions scan/src/components/TxsTable.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ module Styles = {
let logo = style([width(`px(20)), marginLeft(`auto), marginRight(`px(15))]);
};

let renderBody = (reserveIndex, txSub: ApolloHooks.Subscription.variant(TxSub.t)) => {
let renderBody =
(
reserveIndex,
txSub: ApolloHooks.Subscription.variant(TxSub.t),
msgTransform: TxSub.Msg.t => TxSub.Msg.t,
) => {
<TBody
key={
switch (txSub) {
Expand Down Expand Up @@ -76,7 +81,15 @@ let renderBody = (reserveIndex, txSub: ApolloHooks.Subscription.variant(TxSub.t)
<Col size=5.>
{switch (txSub) {
| Data({messages, txHash, success, errMsg}) =>
<div> <TxMessages txHash messages success errMsg width=460 /> </div>
<div>
<TxMessages
txHash
messages={messages->Belt_List.map(msgTransform)}
success
errMsg
width=460
/>
</div>
| _ => <> <VSpacing size=Spacing.sm /> <LoadingCensorBar width=450 height=15 /> </>
}}
</Col>
Expand All @@ -86,7 +99,11 @@ let renderBody = (reserveIndex, txSub: ApolloHooks.Subscription.variant(TxSub.t)
};

[@react.component]
let make = (~txsSub: ApolloHooks.Subscription.variant(array(TxSub.t))) => {
let make =
(
~txsSub: ApolloHooks.Subscription.variant(array(TxSub.t)),
~msgTransform: TxSub.Msg.t => TxSub.Msg.t=x => x,
) => {
<>
<THead>
<Row>
Expand Down Expand Up @@ -153,10 +170,12 @@ let make = (~txsSub: ApolloHooks.Subscription.variant(array(TxSub.t))) => {
</THead>
{switch (txsSub) {
| Data(txs) =>
txs->Belt_Array.mapWithIndex((i, e) => renderBody(i, Sub.resolve(e)))->React.array
txs
->Belt_Array.mapWithIndex((i, e) => renderBody(i, Sub.resolve(e), msgTransform))
->React.array
| _ =>
Belt_Array.make(10, ApolloHooks.Subscription.NoData)
->Belt_Array.mapWithIndex((i, noData) => renderBody(i, noData))
->Belt_Array.mapWithIndex((i, noData) => renderBody(i, noData, msgTransform))
->React.array
}}
</>;
Expand Down
10 changes: 9 additions & 1 deletion scan/src/components/account/AccountIndexTransactions.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ module Styles = {
let hFlex = style([display(`flex)]);
};

let transform = (account, msg: TxSub.Msg.t) => {
switch (msg) {
| SendMsg({toAddress, fromAddress, amount}) when toAddress == account =>
TxSub.Msg.ReceiveMsg({toAddress, fromAddress, amount})
| _ => msg
};
};

[@react.component]
let make = (~accountAddress: Address.t) => {
let (page, setPage) = React.useState(_ => 1);
Expand All @@ -31,7 +39,7 @@ let make = (~accountAddress: Address.t) => {
</div>
}}
<VSpacing size=Spacing.lg />
<TxsTable txsSub />
<TxsTable txsSub msgTransform={transform(accountAddress)} />
{switch (txsCountSub) {
| Data(txsCount) =>
let pageCount = Page.getPageCount(txsCount, pageSize);
Expand Down
21 changes: 20 additions & 1 deletion scan/src/components/msgs/Msg.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,28 @@ let make = (~msg: TxSub.Msg.t, ~width: int) => {
</div>
<AmountRender coins=amount />
<HSpacing size=Spacing.sm />
<Text value={j||j} size=Text.Xxl weight=Text.Bold code=true nowrap=true block=true />
<Text value={j| to |j} size=Text.Md code=true nowrap=true block=true />
<HSpacing size=Spacing.sm />
<div className={Styles.withWidth(width - 285)}> <AddressRender address=toAddress /> </div>
</div>
| ReceiveMsg({fromAddress, toAddress, amount}) =>
<div className={Styles.rowWithWidth(width)}>
<div className={Styles.withWidth(130)}> <AddressRender address=toAddress /> </div>
<div className={Styles.withBg(Colors.blue1, 50)}>
<Text
value="RECEIVE"
size=Text.Xs
spacing={Text.Em(0.07)}
weight=Text.Medium
color=Colors.blue7
/>
</div>
<AmountRender coins=amount />
<HSpacing size=Spacing.sm />
<Text value={j| from |j} size=Text.Md code=true nowrap=true block=true />
<HSpacing size=Spacing.sm />
<div className={Styles.withWidth(width - 285)}> <AddressRender address=fromAddress /> </div>
</div>
| CreateDataSourceMsg({id, sender, name}) =>
<div className={Styles.rowWithWidth(width)}>
<div className={Styles.withWidth(130)}> <AddressRender address=sender /> </div>
Expand Down Expand Up @@ -985,6 +1003,7 @@ let make = (~msg: TxSub.Msg.t, ~width: int) => {
<div className={Styles.withWidth(130)}> <AddressRender address=sender /> </div>
{switch (message) {
| SendBadge => makeBadge("SEND", 40, Colors.blue1, Colors.blue7)
| ReceiveBadge => makeBadge("RECEIVE", 50, Colors.blue1, Colors.blue7)
| CreateDataSourceBadge =>
makeBadge("CREATE DATASOURCE", 110, Colors.yellow1, Colors.yellow6)
| EditDataSourceBadge => makeBadge("EDIT DATASOURCE", 100, Colors.yellow1, Colors.yellow6)
Expand Down
61 changes: 42 additions & 19 deletions scan/src/subscriptions/TxSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module RawDataReport = {
module Msg = {
type badge_t =
| SendBadge
| ReceiveBadge
| CreateDataSourceBadge
| EditDataSourceBadge
| CreateOracleScriptBadge
Expand Down Expand Up @@ -59,6 +60,7 @@ module Msg = {
let getBadgeVariantFromString = badge => {
switch (badge) {
| "send" => SendBadge
| "receive" => raise(Not_found)
| "create_data_source" => CreateDataSourceBadge
| "edit_data_source" => EditDataSourceBadge
| "create_oracle_script" => CreateOracleScriptBadge
Expand Down Expand Up @@ -116,6 +118,14 @@ module Msg = {
};
};

module Receive = {
type t = {
fromAddress: Address.t,
toAddress: Address.t,
amount: list(Coin.t),
};
};

module CreateDataSource = {
type t = {
id: ID.DataSource.t,
Expand Down Expand Up @@ -832,6 +842,7 @@ module Msg = {

type t =
| SendMsg(Send.t)
| ReceiveMsg(Receive.t)
| CreateDataSourceMsg(CreateDataSource.t)
| EditDataSourceMsg(EditDataSource.t)
| CreateOracleScriptMsg(CreateOracleScript.t)
Expand Down Expand Up @@ -930,6 +941,7 @@ module Msg = {
let getBadge = badgeVariant => {
switch (badgeVariant) {
| SendBadge => {text: "SEND", textColor: Colors.blue7, bgColor: Colors.blue1}
| ReceiveBadge => {text: "RECEIVE", textColor: Colors.blue7, bgColor: Colors.blue1}
| CreateDataSourceBadge => {
text: "CREATE DATA SOURCE",
textColor: Colors.yellow5,
Expand Down Expand Up @@ -1071,6 +1083,7 @@ module Msg = {
let getBadgeTheme = msg => {
switch (msg) {
| SendMsg(_) => getBadge(SendBadge)
| ReceiveMsg(_) => getBadge(ReceiveBadge)
| CreateDataSourceMsg(_) => getBadge(CreateDataSourceBadge)
| EditDataSourceMsg(_) => getBadge(EditDataSourceBadge)
| CreateOracleScriptMsg(_) => getBadge(CreateOracleScriptBadge)
Expand Down Expand Up @@ -1118,6 +1131,7 @@ module Msg = {
JsonUtils.Decode.(
switch (json |> field("type", string) |> getBadgeVariantFromString) {
| SendBadge => SendMsg(json |> Send.decode)
| ReceiveBadge => raise(Not_found)
| CreateDataSourceBadge => CreateDataSourceMsg(json |> CreateDataSource.decode)
| EditDataSourceBadge => EditDataSourceMsg(json |> EditDataSource.decode)
| CreateOracleScriptBadge => CreateOracleScriptMsg(json |> CreateOracleScript.decode)
Expand Down Expand Up @@ -1197,6 +1211,8 @@ type internal_t = {
errMsg: option(string),
};

type account_transaction_t = {transaction: internal_t};

module Mini = {
type block_t = {timestamp: MomentRe.Moment.t};
type t = {
Expand Down Expand Up @@ -1309,26 +1325,26 @@ module MultiByHeightConfig = [%graphql
module MultiBySenderConfig = [%graphql
{|
subscription TransactionsBySender($sender: String!, $limit: Int!, $offset: Int!) {
transactions(
where: {sender: {_eq: $sender}},
offset: $offset,
limit: $limit,
order_by: {block_height: desc,id: desc},
) @bsRecord {
txHash: hash @bsDecoder(fn: "GraphQLParser.hash")
blockHeight: block_height @bsDecoder(fn: "ID.Block.fromInt")
success
memo
gasFee: gas_fee @bsDecoder(fn: "GraphQLParser.coins")
gasLimit: gas_limit
gasUsed: gas_used
sender @bsDecoder(fn: "Address.fromBech32")
messages
errMsg: err_msg
block @bsRecord {
timestamp @bsDecoder(fn: "GraphQLParser.timestamp")
accounts_by_pk(address: $sender) {
account_transcations(offset: $offset, limit: $limit, order_by: {transaction_id: desc}) @bsRecord{
transaction @bsRecord {
txHash: hash @bsDecoder(fn: "GraphQLParser.hash")
blockHeight: block_height @bsDecoder(fn: "ID.Block.fromInt")
success
memo
gasFee: gas_fee @bsDecoder(fn: "GraphQLParser.coins")
gasLimit: gas_limit
gasUsed: gas_used
sender @bsDecoder(fn: "Address.fromBech32")
messages
errMsg: err_msg
block @bsRecord {
timestamp @bsDecoder(fn: "GraphQLParser.timestamp")
}
}
}
}

}
|}
];
Expand Down Expand Up @@ -1397,7 +1413,14 @@ let getListBySender = (sender, ~page, ~pageSize, ()) => {
(),
),
);
result |> Sub.map(_, x => x##transactions->Belt_Array.map(toExternal));
result
|> Sub.map(_, x => {
switch (x##accounts_by_pk) {
| Some(x') =>
x'##account_transcations->Belt_Array.map(({transaction}) => transaction->toExternal)
| None => [||]
}
});
};

let getListByBlockHeight = (height, ~page, ~pageSize, ()) => {
Expand Down

0 comments on commit 8236e43

Please sign in to comment.