From b525abeeeb78b43db2503d2622a4c6c7a9f810f1 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 26 Aug 2019 09:14:11 +0200 Subject: [PATCH] Forks by height (in addition to width & finalized) (#1535) * Forks by height (in addition to width & finalized) * Bump API (SetId) --- package.json | 6 +- packages/app-contracts/package.json | 2 +- packages/app-explorer/src/Forks.tsx | 42 ++++++++++---- packages/react-api/package.json | 2 +- yarn.lock | 90 ++++++++++++++--------------- 5 files changed, 81 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index 4e6cbfd4b6..bd4041bc5e 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.91.0-beta.0", - "@polkadot/api-contract": "^0.91.0-beta.0", + "@polkadot/api": "^0.91.0-beta.1", + "@polkadot/api-contract": "^0.91.0-beta.1", "@polkadot/keyring": "^1.1.1", - "@polkadot/types": "^0.91.0-beta.0", + "@polkadot/types": "^0.91.0-beta.1", "@polkadot/util": "^1.1.1", "@polkadot/util-crypto": "^1.1.1", "@types/styled-components": "4.1.8", diff --git a/packages/app-contracts/package.json b/packages/app-contracts/package.json index d96b01da9a..3811b20dc3 100644 --- a/packages/app-contracts/package.json +++ b/packages/app-contracts/package.json @@ -11,7 +11,7 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.5.5", - "@polkadot/api-contract": "^0.91.0-beta.0", + "@polkadot/api-contract": "^0.91.0-beta.1", "@polkadot/react-components": "^0.35.0-beta.2" } } diff --git a/packages/app-explorer/src/Forks.tsx b/packages/app-explorer/src/Forks.tsx index 56411eebdb..0f93a8a525 100644 --- a/packages/app-explorer/src/Forks.tsx +++ b/packages/app-explorer/src/Forks.tsx @@ -17,6 +17,7 @@ import translate from './translate'; interface LinkHeader { bn: string; hash: string; + height: number; isEmpty: boolean; isFinalized: boolean; parent: string; @@ -106,7 +107,7 @@ class Forks extends React.PureComponent { } // add to the header map - this._headers.set(hash, { bn, hash, isEmpty: false, isFinalized: false, parent, width: 0 }); + this._headers.set(hash, this.createHdr(bn, hash, parent)); // check to see if the children already has a entry if (this._children.has(parent)) { @@ -269,17 +270,33 @@ class Forks extends React.PureComponent { } // adjust the number of columns in a cell based on the children and tree depth - private countCols (children: LinkArray): number { + private calcWidth (children: LinkArray): number { return Math.max(1, children.reduce((total, { hdr: { width } }): number => { return total + width; }, 0)); } + // counts the height of a specific node + private calcHeight (children: LinkArray): number { + return children.reduce((max, { hdr, arr }): number => { + hdr.height = hdr.isEmpty + ? 0 + : 1 + this.calcHeight(arr); + + return Math.max(max, hdr.height); + }, 0); + } + + // fills in a header based on the supplied data + private createHdr (bn: string, hash: string, parent: string, isEmpty: boolean = false): LinkHeader { + return { bn, hash, height: 0, isEmpty, isFinalized: false, parent, width: 0 }; + } + // empty link helper - private emptyLink (): Link { + private createLink (): Link { return { arr: [], - hdr: { bn: '', hash: ' ', isEmpty: true, isFinalized: false, parent: ' ', width: 0 } + hdr: this.createHdr('', ' ', ' ', true) }; } @@ -293,19 +310,21 @@ class Forks extends React.PureComponent { children.push({ arr: this.addChildren(hdr, []), hdr }); }); + // caclulate the max height/width for this entry + base.height = this.calcHeight(children); + base.width = this.calcWidth(children); + // place the active (larger, finalized) columns first for the pyramid display children.sort((a, b): number => { - if (a.hdr.width > b.hdr.width || a.hdr.isFinalized) { + if (a.hdr.width > b.hdr.width || a.hdr.height > b.hdr.height || a.hdr.isFinalized) { return -1; - } else if (a.hdr.width < b.hdr.width || b.hdr.isFinalized) { + } else if (a.hdr.width < b.hdr.width || a.hdr.height < b.hdr.height || b.hdr.isFinalized) { return 1; } return 0; }); - base.width = this.countCols(children); - return children; } @@ -318,7 +337,7 @@ class Forks extends React.PureComponent { // ok, non-empty found - iterate through an add at least an empty cell to all arr .filter(({ arr }): boolean => arr.length === 0) - .forEach(({ arr }): number => arr.push(this.emptyLink())); + .forEach(({ arr }): number => arr.push(this.createLink())); const newArr = arr.reduce((flat: LinkArray, { arr }): LinkArray => flat.concat(...arr), []); @@ -329,7 +348,7 @@ class Forks extends React.PureComponent { // create a tree list from the available headers private generateTree (): Link { - const root = this.emptyLink(); + const root = this.createLink(); // add all the root entries first, we iterate from these // @ts-ignore We add the root entry explicitly, it exists as per init @@ -350,7 +369,8 @@ class Forks extends React.PureComponent { // align the columns with empty spacers - this aids in display this.addColumnSpacers(root.arr); - root.hdr.width = this.countCols(root.arr); + root.hdr.height = this.calcHeight(root.arr); + root.hdr.width = this.calcWidth(root.arr); return root; } diff --git a/packages/react-api/package.json b/packages/react-api/package.json index 6219d09f2b..0cca20bbe5 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -31,7 +31,7 @@ "homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme", "dependencies": { "@babel/runtime": "^7.5.5", - "@polkadot/api": "^0.91.0-beta.0", + "@polkadot/api": "^0.91.0-beta.1", "@polkadot/extension-dapp": "^0.8.1", "rxjs-compat": "^6.4.0" } diff --git a/yarn.lock b/yarn.lock index 21c5483b47..0330971f16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1931,44 +1931,44 @@ universal-user-agent "^3.0.0" url-template "^2.0.8" -"@polkadot/api-contract@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.0.tgz#2b2fbd043e47959b818151311372e507b55536fc" - integrity sha512-O1ZWPrWCesd5l5+J7POIl9+u/kF9zoBSZPhMqcHSR7ai9i+i8fnrrx/e0UP8YvDhJJD8S0ZzUliJ1C+O6rRV6A== +"@polkadot/api-contract@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.1.tgz#ab099a929b26b36bde1f53de700d4263f9310288" + integrity sha512-G4wIJDw2uhY7FzD4sqwdFs4GFvcfdgOeDSwU0pRWdyR4cJ3shFB7Vh3PTpmh+N9lZs1GFcv9Zl8kTpB7hUbv+g== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/types" "^0.91.0-beta.0" + "@polkadot/types" "^0.91.0-beta.1" -"@polkadot/api-derive@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.0.tgz#b3b4cf744215b1a2cabe816861610264031ad680" - integrity sha512-gd/yojIBWePQxU7DK8YYL38RFzIjWmruH43myy8+u4pHj4f6fxcLfo+CSOcXkUbwjlpQO5bPH3rGkIt+9lKpKQ== +"@polkadot/api-derive@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.1.tgz#dc044d09e2a600571d585551ddad1176eab5b444" + integrity sha512-Xjoe6M+nFDslanSBvdWeRMG7ZxylD+HjUgFMVVUklhrfaBGE/n+Bf4AtM96h0Hn76+TZB2/IkMTUM9VAk3EmRQ== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api" "^0.91.0-beta.0" - "@polkadot/types" "^0.91.0-beta.0" + "@polkadot/api" "^0.91.0-beta.1" + "@polkadot/types" "^0.91.0-beta.1" -"@polkadot/api-metadata@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.0.tgz#dc3bc9ca7e6cfbd2812203d8f515cd4dac0537fc" - integrity sha512-HmRkFfYvkmZz7VpDaJ+kLY17+DUhfBTUBimOX/7jslWMogh/ZIFlz5Xs8lyfLiExlGFvrBt8j3EgwVprcPR1Hw== +"@polkadot/api-metadata@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.1.tgz#1986ab48faa456cbdb6e33e702dc1e0b487a82c2" + integrity sha512-k7MApR4FShogP/8tZC1Q00waNQWXXv7KaGexHoFD4tkx0susTKArikRaZYbWodhXL2am/McRJuuJrHoj+drMSA== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/types" "^0.91.0-beta.0" + "@polkadot/types" "^0.91.0-beta.1" "@polkadot/util" "^1.1.1" "@polkadot/util-crypto" "^1.1.1" -"@polkadot/api@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.0.tgz#070e607f9903dfb1194f76f5e378f7e551669a63" - integrity sha512-DrAFOyGwZwIacR3gRdYEEg3uHhK91a6s0pWA0hFJBa1DfSU5H2Qv1lSG8Fh4mY59FdLTlbtYaFsWgEfflp6cCw== +"@polkadot/api@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.1.tgz#25c521a4ab39d7c260867417451a77e356161e96" + integrity sha512-yAn2ylipDaDGdTiVNZB19521lMJ+yiRAuaI96kEYbHfwJScKxempJ0NRm2Afu7ROacmijfUa65vwEBJBqdmgiw== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api-derive" "^0.91.0-beta.0" - "@polkadot/api-metadata" "^0.91.0-beta.0" - "@polkadot/rpc-core" "^0.91.0-beta.0" - "@polkadot/rpc-provider" "^0.91.0-beta.0" - "@polkadot/types" "^0.91.0-beta.0" + "@polkadot/api-derive" "^0.91.0-beta.1" + "@polkadot/api-metadata" "^0.91.0-beta.1" + "@polkadot/rpc-core" "^0.91.0-beta.1" + "@polkadot/rpc-provider" "^0.91.0-beta.1" + "@polkadot/types" "^0.91.0-beta.1" "@polkadot/util-crypto" "^1.1.1" "@polkadot/dev-react@^0.31.0-beta.3": @@ -2071,10 +2071,10 @@ dependencies: "@babel/runtime" "^7.5.5" -"@polkadot/jsonrpc@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.0.tgz#0429f0dd207c59cb37d3c2d98a4d2fc82b736caa" - integrity sha512-2aU5F6wwzxH66Req4/lcu/EmDrGigVY67yQpeDb5DjiB7R/NR5CB+Mzq8jLe28JDnX3OsGZ4rpWfzmcNEtzZHg== +"@polkadot/jsonrpc@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.1.tgz#8b98178a6f13532614f2a0e8436f9606682ca2e8" + integrity sha512-kZDzLOV38bEBrqm7AORlAFdxysh/lJkrhHkqgTWynKZqcXKDgBQXv8xStrAE1vZGEfQkujvzrW3s/wTWChrKBg== dependencies: "@babel/runtime" "^7.5.5" @@ -2102,25 +2102,25 @@ react-copy-to-clipboard "^5.0.1" styled-components "^4.3.1" -"@polkadot/rpc-core@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.0.tgz#a3e752fa78d26cc654cdb981a6f5c45f58aba3c7" - integrity sha512-lg4wzsz4mj64BhAJ9jFRF+BC7lWVeT+ypYy6P/9MRISXUgH+yoQqpruDc59NuEs59st/N3Gtl9vGu6x7NjnrVQ== +"@polkadot/rpc-core@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.1.tgz#264be8675636a27564a9c3f9e02672cbd8701b73" + integrity sha512-ENXme4kzrjwXUJcMwaf4Veg6/bATrquuxlT3DlcsVGdY5MIgKpQTf0giO+et9jtVSsKvG2+Hwk4i+lftxq/gcg== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/jsonrpc" "^0.91.0-beta.0" - "@polkadot/rpc-provider" "^0.91.0-beta.0" - "@polkadot/types" "^0.91.0-beta.0" + "@polkadot/jsonrpc" "^0.91.0-beta.1" + "@polkadot/rpc-provider" "^0.91.0-beta.1" + "@polkadot/types" "^0.91.0-beta.1" "@polkadot/util" "^1.1.1" rxjs "^6.5.2" -"@polkadot/rpc-provider@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.0.tgz#54db4e5536de770c87cbf1f054cbce1207bc2d0b" - integrity sha512-2JgF1hmlTSgTI6+AMR/WNNlDlPs7+Z1+yZPlnwTb+INK4Nb+cyzzjPC/1P6BhWhrKvqzhn2UyR7o44jFkDMxkg== +"@polkadot/rpc-provider@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.1.tgz#b852b13cde7867c171353ca89b65840af70c54d3" + integrity sha512-SJ/xovtfSg5BzfIcyTJZ91j6NHIlACwIlKTccYbqTXUnl82kHZAV8rrRkeycVa1NxxAS5e02kLPn4MbygSKyYA== dependencies: "@babel/runtime" "^7.5.5" - "@polkadot/api-metadata" "^0.91.0-beta.0" + "@polkadot/api-metadata" "^0.91.0-beta.1" "@polkadot/util" "^1.1.1" "@polkadot/util-crypto" "^1.1.1" "@types/nock" "^10.0.3" @@ -2135,10 +2135,10 @@ dependencies: "@types/chrome" "^0.0.86" -"@polkadot/types@^0.91.0-beta.0": - version "0.91.0-beta.0" - resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.0.tgz#1c4418b619bf659dbd6d79cc9dd6b667f1809dfb" - integrity sha512-QCCJBq0knIYTBucoXpc/QgIN2vtmX0x/7tVx3Z8cP1bccYHUZsz0zh2APRKYGlzgFZT8l8Iq2TukMAijJzOWnw== +"@polkadot/types@^0.91.0-beta.1": + version "0.91.0-beta.1" + resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.1.tgz#8d8a0a56233408f2cff499ac29d1b01192a56d33" + integrity sha512-6TAUvqMdwqPT/OuZclit6pe7PUjWBQbWG9r8gFYxGKI26HbInOJgfMxsQAkb/3fO3VbCpTaCEjeUPsAiUtNDPA== dependencies: "@babel/runtime" "^7.5.5" "@polkadot/util" "^1.1.1"