Skip to content

Commit 1cc5221

Browse files
committed
fix the logic for current cycle
1 parent 1c84b41 commit 1cc5221

File tree

4 files changed

+61
-67
lines changed

4 files changed

+61
-67
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@material-ui/core": "^4.11.3",
2828
"@material-ui/icons": "^4.9.1",
2929
"@material-ui/lab": "^4.0.0-alpha.57",
30-
"@microsoft/signalr": "^5.0.9",
30+
"@microsoft/signalr": "9.0.6",
3131
"@mui/icons-material": "^5.14.14",
3232
"@mui/material": "^5.14.14",
3333
"@mui/x-date-pickers": "^5.0.2",
@@ -47,7 +47,6 @@
4747
"assert-never": "^1.3.0",
4848
"bignumber.js": "^9.0.1",
4949
"blockies-ts": "^1.0.0",
50-
"caniuse-lite": "",
5150
"connectkit": "^1.8.2",
5251
"crypto-browserify": "^3.12.0",
5352
"dayjs": "^1.11.11",

src/services/bakingBad/context/TZKTSubscriptions.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,24 @@ const TZKTSubscriptionsProvider: React.FC = ({ children }) => {
3131
useEffect(() => {
3232
if (network.startsWith("etherlink")) return
3333
;(async () => {
34-
socketRef.current = new HubConnectionBuilder().withUrl(getUrl(network)).build()
34+
socketRef.current = new HubConnectionBuilder().withUrl(getUrl(network)).withAutomaticReconnect().build()
3535

36-
await socketRef.current.start()
36+
try {
37+
await socketRef.current.start()
38+
} catch (e) {
39+
console.warn("TZKT SignalR start failed", e)
40+
return
41+
}
3742

38-
// listen for incoming message
3943
socketRef.current.on("blocks", (blockMessage: BlockMessage) => {
4044
setBlock(blockMessage.state)
4145
})
4246

43-
await socketRef.current.invoke("SubscribeToBlocks")
47+
try {
48+
await socketRef.current.invoke("SubscribeToBlocks")
49+
} catch (e) {
50+
console.warn("TZKT SignalR subscribe failed", e)
51+
}
4452
})()
4553

4654
return () => {

src/services/services/dao/hooks/useDAO.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,34 @@ export const useDAO = (address: string) => {
142142
} catch {}
143143

144144
const period = Number(data.data.period)
145+
// Include flush delay in the total cycle length
146+
const proposalFlushLevel = Number(data.data.proposal_flush_level)
147+
const proposalExpiredLevel = Number(data.data.proposal_expired_level)
148+
const flushDelayBlocks = Math.max(proposalFlushLevel - 2 * period, 0)
149+
const proposalBlocksToExpire = Math.max(proposalExpiredLevel - proposalFlushLevel, 0)
150+
const totalCycleBlocks = period + flushDelayBlocks + proposalBlocksToExpire
151+
// Debug logs for cycle calculation inputs
152+
console.log("useDAO.ts cycle inputs", {
153+
CurrentBlock: effectiveBlock,
154+
BlockAtWhichDaoMinted: data.data.start_level,
155+
TotalDaoLifeCycleBlocks: totalCycleBlocks
156+
})
145157
const blocksFromStart = effectiveBlock - data.data.start_level
146158
if (blocksFromStart < 0) return
147-
const periodsFromStart = Math.floor(blocksFromStart / period)
148-
const type = periodsFromStart % 2 === 0 ? "voting" : "proposing"
159+
if (totalCycleBlocks <= 0) return
160+
// Use full cycle (voting period + flush delay) for cycle count
161+
const cyclesFromStart = Math.floor(blocksFromStart / totalCycleBlocks)
162+
// Keep UI period type based on the current voting/proposing period only
163+
const periodsFromStartForType = Math.floor(blocksFromStart / period)
164+
const type = periodsFromStartForType % 2 === 0 ? "voting" : "proposing"
165+
// Blocks left in the current voting/proposal period
149166
const blocksLeft = period - (blocksFromStart % period)
150167

151168
setCycleInfo({
152169
blocksLeft,
153170
type,
154171
timeEstimateForNextBlock: blockTimeAverage,
155-
currentCycle: periodsFromStart,
172+
currentCycle: cyclesFromStart,
156173
currentLevel: effectiveBlock
157174
})
158175
})()

yarn.lock

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,16 +3235,16 @@
32353235
semver "^7.5.4"
32363236
uuid "^9.0.1"
32373237

3238-
"@microsoft/signalr@^5.0.9":
3239-
version "5.0.17"
3240-
resolved "https://registry.yarnpkg.com/@microsoft/signalr/-/signalr-5.0.17.tgz#c6d3038538b8e21b95a012a7eaa22f44d5cc72f4"
3241-
integrity sha512-zTjFxjh67WWCe35ZipsqkktM5mM+MsckyyI2ZvFmYWR7ibpUoAyZI1DFdYfwXfsyBdlykDaW84o9lrB+9tDpaA==
3238+
"@microsoft/signalr@9.0.6":
3239+
version "9.0.6"
3240+
resolved "https://registry.yarnpkg.com/@microsoft/signalr/-/signalr-9.0.6.tgz#67dd074941c2ec2b857f607504c920a0c6274e27"
3241+
integrity sha512-DrhgzFWI9JE4RPTsHYRxh4yr+OhnwKz8bnJe7eIi7mLLjqhJpEb62CiUy/YbFvLqLzcGzlzz1QWgVAW0zyipMQ==
32423242
dependencies:
32433243
abort-controller "^3.0.0"
3244-
eventsource "^1.0.7"
3245-
fetch-cookie "^0.7.3"
3244+
eventsource "^2.0.2"
3245+
fetch-cookie "^2.0.3"
32463246
node-fetch "^2.6.7"
3247-
ws "^6.0.0"
3247+
ws "^7.5.10"
32483248

32493249
"@motionone/animation@^10.12.0", "@motionone/animation@^10.15.1", "@motionone/animation@^10.18.0":
32503250
version "10.18.0"
@@ -5967,11 +5967,6 @@ astral-regex@^2.0.0:
59675967
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
59685968
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==
59695969

5970-
async-limiter@~1.0.0:
5971-
version "1.0.1"
5972-
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
5973-
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
5974-
59755970
async-mutex@^0.2.6:
59765971
version "0.2.6"
59775972
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.2.6.tgz#0d7a3deb978bc2b984d5908a2038e1ae2e54ff40"
@@ -6655,20 +6650,10 @@ caniuse-api@^3.0.0:
66556650
lodash.memoize "^4.1.2"
66566651
lodash.uniq "^4.5.0"
66576652

6658-
caniuse-lite@:
6659-
version "1.0.30001651"
6660-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz#52de59529e8b02b1aedcaaf5c05d9e23c0c28138"
6661-
integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg==
6662-
6663-
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001587, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001663:
6664-
version "1.0.30001668"
6665-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001668.tgz#98e214455329f54bf7a4d70b49c9794f0fbedbed"
6666-
integrity sha512-nWLrdxqCdblixUO+27JtGJJE/txpJlyUy5YN1u53wLZkP0emYCo5zgS6QYft7VUYR42LGgi/S5hdLZTrnyIddw==
6667-
6668-
caniuse-lite@^1.0.30001599:
6669-
version "1.0.30001600"
6670-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz#93a3ee17a35aa6a9f0c6ef1b2ab49507d1ab9079"
6671-
integrity sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ==
6653+
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001587, caniuse-lite@^1.0.30001599, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001663:
6654+
version "1.0.30001741"
6655+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001741.tgz"
6656+
integrity sha512-QGUGitqsc8ARjLdgAfxETDhRbJ0REsP6O3I96TAth/mVjh2cYzN2u+3AzPP3aVSm2FehEItaJw1xd+IGBXWeSw==
66726657

66736658
case-sensitive-paths-webpack-plugin@^2.4.0:
66746659
version "2.4.0"
@@ -8305,11 +8290,6 @@ es-to-primitive@^1.2.1:
83058290
is-date-object "^1.0.1"
83068291
is-symbol "^1.0.2"
83078292

8308-
es6-denodeify@^0.1.1:
8309-
version "0.1.5"
8310-
resolved "https://registry.yarnpkg.com/es6-denodeify/-/es6-denodeify-0.1.5.tgz#31d4d5fe9c5503e125460439310e16a2a3f39c1f"
8311-
integrity sha512-731Rf4NqlPvhkT1pIF7r8vZxESJlWocNpXLuyPlVnfEGXlwuJaMvU5WpyyDjpudDC2cgXVX849xljzvQqBg1QQ==
8312-
83138293
escalade@^3.1.1, escalade@^3.2.0:
83148294
version "3.2.0"
83158295
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5"
@@ -8829,10 +8809,10 @@ events@3.3.0, events@^3.2.0, events@^3.3.0:
88298809
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
88308810
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
88318811

8832-
eventsource@^1.0.7:
8833-
version "1.1.2"
8834-
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.2.tgz#bc75ae1c60209e7cb1541231980460343eaea7c2"
8835-
integrity sha512-xAH3zWhgO2/3KIniEKYPr8plNSzlGINOUqYj0m0u7AB81iRw8b/3E73W6AuU+6klLbaSFmZnaETQ2lXPfAydrA==
8812+
eventsource@^2.0.2:
8813+
version "2.0.2"
8814+
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-2.0.2.tgz#76dfcc02930fb2ff339520b6d290da573a9e8508"
8815+
integrity sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==
88368816

88378817
evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3:
88388818
version "1.0.3"
@@ -9063,13 +9043,13 @@ fb-watchman@^2.0.0:
90639043
dependencies:
90649044
bser "2.1.1"
90659045

9066-
fetch-cookie@^0.7.3:
9067-
version "0.7.3"
9068-
resolved "https://registry.yarnpkg.com/fetch-cookie/-/fetch-cookie-0.7.3.tgz#b8d023f421dd2b2f4a0eca9cd7318a967ed4eed8"
9069-
integrity sha512-rZPkLnI8x5V+zYAiz8QonAHsTb4BY+iFowFBI1RFn0zrO343AVp9X7/yUj/9wL6Ef/8fLls8b/vGtzUvmyAUGA==
9046+
fetch-cookie@^2.0.3:
9047+
version "2.2.0"
9048+
resolved "https://registry.yarnpkg.com/fetch-cookie/-/fetch-cookie-2.2.0.tgz#01086b6b5b1c3e08f15ffd8647b02ca100377365"
9049+
integrity sha512-h9AgfjURuCgA2+2ISl8GbavpUdR+WGAM2McW/ovn4tVccegp8ZqCKWSBR8uRdM8dDNlx5WdKRWxBYUwteLDCNQ==
90709050
dependencies:
9071-
es6-denodeify "^0.1.1"
9072-
tough-cookie "^2.3.3"
9051+
set-cookie-parser "^2.4.8"
9052+
tough-cookie "^4.0.0"
90739053

90749054
fflate@^0.4.8:
90759055
version "0.4.8"
@@ -14319,7 +14299,7 @@ pseudomap@^1.0.2:
1431914299
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
1432014300
integrity sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==
1432114301

14322-
psl@^1.1.28, psl@^1.1.33:
14302+
psl@^1.1.33:
1432314303
version "1.9.0"
1432414304
resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7"
1432514305
integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==
@@ -15458,6 +15438,11 @@ set-blocking@^2.0.0:
1545815438
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
1545915439
integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==
1546015440

15441+
set-cookie-parser@^2.4.8:
15442+
version "2.7.1"
15443+
resolved "https://registry.yarnpkg.com/set-cookie-parser/-/set-cookie-parser-2.7.1.tgz#3016f150072202dfbe90fadee053573cc89d2943"
15444+
integrity sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==
15445+
1546115446
set-function-length@^1.2.1:
1546215447
version "1.2.2"
1546315448
resolved "https://registry.yarnpkg.com/set-function-length/-/set-function-length-1.2.2.tgz#aac72314198eaed975cf77b2c3b6b880695e5449"
@@ -16431,14 +16416,6 @@ toposort@^2.0.2:
1643116416
resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330"
1643216417
integrity sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==
1643316418

16434-
tough-cookie@^2.3.3:
16435-
version "2.5.0"
16436-
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"
16437-
integrity sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==
16438-
dependencies:
16439-
psl "^1.1.28"
16440-
punycode "^2.1.1"
16441-
1644216419
tough-cookie@^4.0.0:
1644316420
version "4.1.4"
1644416421
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.4.tgz#945f1461b45b5a8c76821c33ea49c3ac192c1b36"
@@ -17695,14 +17672,7 @@ ws@8.17.1, ws@~8.17.1:
1769517672
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b"
1769617673
integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==
1769717674

17698-
ws@^6.0.0:
17699-
version "6.2.2"
17700-
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e"
17701-
integrity sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==
17702-
dependencies:
17703-
async-limiter "~1.0.0"
17704-
17705-
ws@^7.4.6:
17675+
ws@^7.4.6, ws@^7.5.10:
1770617676
version "7.5.10"
1770717677
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9"
1770817678
integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==

0 commit comments

Comments
 (0)