-
Notifications
You must be signed in to change notification settings - Fork 2
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
frontend auto fetch. mixin improvements. disable btns if !userAddress #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,27 +1,73 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
import {mapActions, mapGetters} from "vuex"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
const mxGame = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
data() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
currentTime: new Date().getTime(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
computed: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
...mapGetters(['userAddress']) | ||||||||||||||||||||||||||||||||||||||||||||||||||
...mapGetters(['userAddress', 'gameState']), | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
timeLeftSeconds() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (!this.gameState) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||
const endTime = this.gameState.end_time * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||
const timeDiff = endTime - this.currentTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||
return timeDiff > 0 ? Math.floor(timeDiff / 1000) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
timeLeftHuman() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
const timeDiff = this.timeLeftSeconds * 1000; // Convert back to milliseconds for calculation | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (timeDiff <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
return "0h 0m 0s"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
const hours = Math.floor((timeDiff / (1000 * 60 * 60)) % 24); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const minutes = Math.floor((timeDiff / (1000 * 60)) % 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const seconds = Math.floor((timeDiff / 1000) % 60); | ||||||||||||||||||||||||||||||||||||||||||||||||||
return `${hours}h ${minutes}m ${seconds}s`; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
...mapActions(['initUser', 'fetchGameConfig', 'fetchGameState', 'fetchPots', 'fetchWinningPots', 'fetchBidRange', 'fetchReallocationFeePool', 'fetchPlayerAllocations']), | ||||||||||||||||||||||||||||||||||||||||||||||||||
...mapActions([ | ||||||||||||||||||||||||||||||||||||||||||||||||||
'initUser', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchGameConfig', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchGameState', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchPots', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchWinningPots', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchBidRange', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchReallocationFeePool', | ||||||||||||||||||||||||||||||||||||||||||||||||||
'fetchPlayerAllocations', | ||||||||||||||||||||||||||||||||||||||||||||||||||
]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
async fetchOnce() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.initUser(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (this.userAddress) await this.fetchPlayerAllocations() | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchGameConfig() | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (this.userAddress) await this.fetchPlayerAllocations(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchGameConfig(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchGameState(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
async fetchInterval(gameEnd = false) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchPots(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchWinningPots(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchBidRange(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchReallocationFeePool(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
if (gameEnd) await this.fetchGameState(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
async fetchInterval() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchGameState() | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchPots() | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchWinningPots() | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchBidRange() | ||||||||||||||||||||||||||||||||||||||||||||||||||
await this.fetchReallocationFeePool() | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export default mxGame | ||||||||||||||||||||||||||||||||||||||||||||||||||
updateCurrentTime() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
this.currentTime = new Date().getTime(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
created() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
this.intervalId = setInterval(this.updateCurrentTime, 1000); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
unmounted() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
clearInterval(this.intervalId); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+59
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - unmounted() {
+ beforeUnmount() { Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export default mxGame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup of the auto-fetch interval in the
unmounted
lifecycle hook is correctly implemented, preventing potential memory leaks. However, the lifecycle hook should bebeforeUnmount
instead ofunmounted
to ensure the cleanup happens as the component is being removed, not after it has been removed.Committable suggestion