Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]/[FEATURE] for ticket 77 #85

Merged
merged 27 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"utils",
"styles",
"store",
"routes"
"routes",
"hooks",
"api"
]
},
"package-specs": [
Expand All @@ -23,12 +25,14 @@
"namespace": true,
"bs-dependencies": [
"bs-conseiljs",
"@glennsl/bs-json",
"reason-react",
"reason-future",
"bs-css",
"bs-css-emotion",
"bs-react-intl",
"bs-moment",
"bs-moment-timezone",
"reductive"
],
"refmt": 3
Expand Down
779 changes: 461 additions & 318 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
"ReasonML"
],
"dependencies": {
"@glennsl/bs-json": "^5.0.2",
"bs-conseiljs": "git+https://github.com/Cryptonomic/ConseilJS-ReasonML-Bindings.git#272b594ec0f8ea47d784aec86a1e4a6bd3d2ec5d",
"bs-css-emotion": "^1.1.0",
"bs-moment": "^0.4.5",
"bs-moment-timezone": "^0.6.0",
"bs-react-intl": "1.0.0",
"conseiljs": "0.4.0-alpha.2",
"moment": "^2.24.0",
"react": "16.8.1",
"react-dom": "16.8.1",
"react-intl": "3.0.0-beta-8",
"reason-future": "^2.5.0",
"reason-react": "0.7.0",
"reason-react": "0.7.1",
"reductive": "^2.0.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Index.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open GlobalStore;

ReactDOMRe.renderToElementWithId(
<AppStore.Provider store=globalStore> <App /> </AppStore.Provider>,
<Store.Provider store=globalStore> <App /> </Store.Provider>,
"root",
);
123 changes: 63 additions & 60 deletions src/MainType.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,67 +33,70 @@ type theme = {
networkShadowCol: string,
};

type transInfo = {
countOriginatedContracts: string,
countAmount: string,
sumAmount: int,
};

type voteInfo = {
yay_rolls: int,
nay_rolls: int,
pass_rolls: int,
proposal_hash: string,
current_expected_quorum: int,
};
type transactionHash = {countedTransactions: int};

type blockInfo = {
blockCount: int,
fundraiserCount: string,
totalFundraiserCount: string,
sum_fee: int,
sum_consumed_gas: int,
num_bakers: string,
bakers_sum_staking_balance: float,
totalTez: float,
type tezosBlock = {
active_proposal: option(string),
baker: option(string),
chain_id: option(string),
consumed_gas: option(int),
context: option(string),
current_expected_quorum: option(int),
expected_commitment: option(bool),
fitness: option(string),
hash: option(string),
level: option(int),
meta_cycle: option(int),
meta_cycle_position: option(int),
meta_level: option(int),
meta_level_position: option(int),
meta_voting_period: option(int),
meta_voting_period_position: option(int),
nonce_hash: option(string),
operations_hash: option(string),
period_kind: option(string),
predecessor: option(string),
priority: option(int),
proto: option(int),
protocol: option(string),
signature: option(string),
timestamp: option(float),
utc_day: option(int),
utc_month: option(int),
utc_time: option(string),
utc_year: option(int),
validation_pass: option(int),
};

type proposalInfo = {
count_operation_group_hash: string,
proposal: string,
let initTezosBlock = {
active_proposal: None,
baker: None,
chain_id: None,
consumed_gas: None,
context: None,
current_expected_quorum: None,
expected_commitment: None,
fitness: None,
hash: None,
level: None,
meta_cycle: None,
meta_cycle_position: None,
meta_level: None,
meta_level_position: None,
meta_voting_period: None,
meta_voting_period_position: None,
nonce_hash: None,
operations_hash: None,
period_kind: None,
predecessor: None,
priority: None,
proto: None,
protocol: None,
signature: None,
timestamp: None,
utc_day: None,
utc_month: None,
utc_time: None,
utc_year: None,
validation_pass: None,
};

type state = {
inited: int,
entity: string,
id: string,
isLoading: bool,
selectedConfig: int,
isOpenNetworkSelector: bool,
isError: bool,
error: string,
block: Js.Dict.t(string),
account: Js.Dict.t(string),
operation: array(Js.Dict.t(string)),
lastBlock: ConseiljsType.tezosBlock,
transinfo: transInfo,
blockinfo: blockInfo,
voteinfo: voteInfo,
proposals: array(proposalInfo),
};

type action =
| Init(int)
| SetId(string)
| SetLoading
| ChangeNetwork(int)
| SetParams(string, string)
| SetError(string)
| RemoveError
| SetBlock(Js.Dict.t(string), string, bool)
| SetAccount(Js.Dict.t(string), string)
| SetOperations(array(Js.Dict.t(string)), string)
| OpenNetwork(bool)
| SetLastBlock(ConseiljsType.tezosBlock, blockInfo, transInfo)
| SetProposals(array(proposalInfo))
| SetVoteInfo(voteInfo);
138 changes: 0 additions & 138 deletions src/utils/ApiCall.re → src/api/ApiCall.re
Original file line number Diff line number Diff line change
Expand Up @@ -153,141 +153,3 @@ let getForQueryApi = (~query, ~field: string, ~config: MainType.config) =>
value[0] |> toOption |> Future.value
| _ => None |> Future.value,
);

let getVoteInfoThunk =
(
~callback,
~hash: string,
~active_proposal: string,
~config: MainType.config,
) =>
Js.Promise.all2((
getForQueryApi(
~query=Queries.getQueryForQuorum(hash),
~field="blocks",
~config,
)
|> FutureJs.toPromise,
getForQueryApi(
~query=Queries.getQueryForVotingStats(hash, active_proposal),
~field="governance",
~config,
)
|> FutureJs.toPromise,
))
->FutureJs.fromPromise(_err => None)
->Future.map(
fun
| Ok((Some(quorumStat), Some(votingStat))) => {
let quorumObj = quorumStat |> Obj.magic;
let votingObj = votingStat |> Obj.magic;
let votinfo: MainType.voteInfo = {
yay_rolls: votingObj##yay_rolls,
nay_rolls: votingObj##nay_rolls,
pass_rolls: votingObj##pass_rolls,
proposal_hash: votingObj##proposal_hash,
current_expected_quorum: quorumObj##current_expected_quorum,
};
Some(votinfo);
}
| _ => None,
)
->Future.get(callback);

let getProposalInfoThunk =
(~callback, ~metaCycle: int, ~config: MainType.config) =>
ConseiljsRe.ConseilDataClient.executeEntityQuery
->applyTuple3(~tuple=Utils.getInfo(config))
->applyField(~field="operations")
->applyQuery(~query=Queries.getQueryForProposalInfo(metaCycle))
->FutureJs.fromPromise(_err => None)
->Future.map(
fun
| Ok(proposalStats) when proposalStats |> Array.length > 0 =>
proposalStats
|> Array.map(proposal => {
let proposalObj = proposal |> Obj.magic;
let newProposal: MainType.proposalInfo = {
count_operation_group_hash:
proposalObj##count_operation_group_hash,
proposal: proposalObj##proposal,
};
newProposal;
})
|> toOption
| Ok(_) => Some([||])
| _err => None,
)
->Future.get(callback);

// TODO List is pretty bad idea of storing elements we'd like to use in specific order. Need to find a better way.
let getBlockInfoThunk =
(~callback, ~metaCycle: int, ~timestamp: float, ~config: MainType.config) =>
Future.all([
getForQueryApi(
~query=Queries.getQueryForNumBlocks(metaCycle, timestamp),
~field="blocks",
~config,
),
getForQueryApi(
~query=Queries.getQueryForTransactionStats(timestamp),
~field="operations",
~config,
),
getForQueryApi(
~query=Queries.getQueryForFundraiserStats(timestamp),
~field="operations",
~config,
),
getForQueryApi(
~query=Queries.getQueryForTotalFundraiserActivated(),
~field="operations",
~config,
),
getForQueryApi(
~query=Queries.getQueryForFeesStats(timestamp),
~field="operations",
~config,
),
getForQueryApi(
~query=Queries.getQueryForBakerStats(),
~field="delegates",
~config,
),
getForQueryApi(
~query=Queries.getQueryForMarketCap(),
~field="accounts",
~config,
),
])
->Future.map(
fun
| [res1, res2, res3, res4, res5, res6, res7] => {
let newTransInfoObj = res2 |> Obj.magic;
let newTranInfo: MainType.transInfo = {
countOriginatedContracts:
newTransInfoObj##count_originated_contracts,
countAmount: newTransInfoObj##count_amount,
sumAmount: newTransInfoObj##sum_amount,
};
let newFundraiser = res3 |> Obj.magic;
let newTotalFundraiser = res4 |> Obj.magic;
let feesObj = res5 |> Obj.magic;
let bakersObj = res6 |> Obj.magic;
let marketObj = res7 |> Obj.magic;

let newBlockInfo: MainType.blockInfo = {
blockCount: (res1 |> Obj.magic)##count_hash,
fundraiserCount: newFundraiser##count_kind,
totalFundraiserCount: newTotalFundraiser##count_kind,
sum_fee: feesObj##sum_fee,
sum_consumed_gas: feesObj##sum_consumed_gas,
num_bakers: bakersObj##count_pkh,
bakers_sum_staking_balance: bakersObj##sum_staking_balance,
totalTez: marketObj##sum_balance,
};
Some((newBlockInfo, newTranInfo));
}
| _ => None,
)
->Future.get(callback);
Loading