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

ObscuroScan: load eth price on init #1626

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion tools/obscuroscan_v2/backend/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func parseCLIArgs() *config.Config {
defaultConfig := &config.Config{
NodeHostAddress: "http://erpc.dev-testnet.obscu.ro:80",
ServerAddress: "0.0.0.0:80",
ServerAddress: "0.0.0.0:43910",
LogPath: "obscuroscan_logs.txt",
}

Expand Down
2 changes: 1 addition & 1 deletion tools/obscuroscan_v2/frontend/src/lib/config.dev.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Config {
static backendServerAddress = "http://127.0.0.1:43910"
static pollingInterval = 1000
static pricePollingInterval = 10000*10000
static pricePollingInterval = 60*1000 // 1 minute
static version = "dev"
}

Expand Down
2 changes: 1 addition & 1 deletion tools/obscuroscan_v2/frontend/src/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Config {
static backendServerAddress = "http://127.0.0.1:43910"
static pollingInterval = 1000
static pricePollingInterval = 10000*10000
static pricePollingInterval = 60*1000 // 1 minute
static version = "dev"
}

Expand Down
2 changes: 1 addition & 1 deletion tools/obscuroscan_v2/frontend/src/lib/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Config {
// VITE_APIHOSTADDRESS should be used as an env var at the prod server
static backendServerAddress = import.meta.env.VITE_APIHOSTADDRESS
static pollingInterval = 1000
static pricePollingInterval = 10*this.pollingInterval
static pricePollingInterval = 60*1000 // 1 minute
static version = import.meta.env.VITE_FE_VERSION
}

Expand Down
2 changes: 2 additions & 0 deletions tools/obscuroscan_v2/frontend/src/lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class Poller {
this.timer = null;
}

// Start polling - executes the fetchCallback immediately and every interval thereafter
start() {
this.stop(); // Ensure previous intervals are cleared
this.fetchCallback();
this.timer = setInterval(async () => {
await this.fetchCallback();
}, this.interval);
Expand Down
6 changes: 3 additions & 3 deletions tools/obscuroscan_v2/frontend/src/stores/priceStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const usePriceStore = defineStore({
poller: new Poller(() => {
const store = usePriceStore();
store.fetch();
}, 60*Config.pollingInterval)
}, Config.pricePollingInterval)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to have the price updated at the second ? Also, I think it happened to me getting limit rated for polling too fast, might want to avoid the client limit rated for polling too fast too.

}),
actions: {
async fetch() {
Expand All @@ -18,13 +18,13 @@ export const usePriceStore = defineStore({
const data = await response.json();
this.ethPriceUSD = data.ethereum.usd;

console.log("Fetched "+this.ethPriceUSD);
console.log("Fetched " + this.ethPriceUSD);
} catch (error) {
console.error("Failed to fetch count:", error);
}
},

startPolling() {
async startPolling() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The startPolling function has been made asynchronous, but there are no await expressions inside it. If you plan to add asynchronous operations inside this function in the future, this change is fine. Otherwise, it's unnecessary to declare it as async.

this.poller.start();
},

Expand Down