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

refactor price.js #356

Merged
merged 7 commits into from
Apr 30, 2024
Merged

refactor price.js #356

merged 7 commits into from
Apr 30, 2024

Conversation

panleone
Copy link
Member

@panleone panleone commented Apr 24, 2024

Abstract

A bit of refactor for the price class and its relation with settings:

  • the circular dependency between settings.js and price.js has been removed, now the oracle does not know about the settings and viceversa.
  • call the function fillCurrencySelect only once
  • load the oracle on construction.
  • make fLoadedCurrencies private

Testing

Test that price is still working as before

Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for cheery-moxie-4f1121 ready!

Name Link
🔨 Latest commit 8c2a8d7
🔍 Latest deploy log https://app.netlify.com/sites/cheery-moxie-4f1121/deploys/662b4ff616ea9000085e1aeb
😎 Deploy Preview https://deploy-preview-356--cheery-moxie-4f1121.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@panleone panleone self-assigned this Apr 24, 2024
@panleone panleone added the Refactor A PR or suggestion for rewriting existing code. label Apr 24, 2024
@panleone panleone requested review from JSKitty and Duddino April 24, 2024 13:58
Copy link
Member

@JSKitty JSKitty left a comment

Choose a reason for hiding this comment

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

Generally I like the decoupling of modules, and this implementation is good.

I am unsure of what we should do to allow Oracles to be chosen via the Settings though, because this implementation differs from how cNetwork and cNode work, when they're all functionally the same: different endpoints.

await this.getCurrencies();
if (!this.#fLoadedCurrencies) await sleep(5000);
}
getEventEmitter().emit('currency-loaded', this.mapCurrencies);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
getEventEmitter().emit('currency-loaded', this.mapCurrencies);
// Update any listeners for the full currency list (Settings, etc)
getEventEmitter().emit('currency-loaded', this.mapCurrencies);
// Update the balance to render the price instantly
getEventEmitter().emit('balance-update');

Small suggestion: even after load() is successful after multiple failed attempts, it takes another >15s before balance-update is called by global.js, adding a delay to the currency displaying in the Dashboard, we can render both the Balances and Settings here.

* @type {Oracle}
*/
export let cOracle = new Oracle();

Copy link
Member

Choose a reason for hiding this comment

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

If we're removing the Oracle instantiation from here, we should at least add some method or settings variable for us to "change" between instances in real-time via Settings in the future, as this is not intended to be a hardcoded single class, it should function similar to cExplorer or cNode, which are both stored in settings.js.

Copy link
Member Author

Choose a reason for hiding this comment

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

Having a setting to choose where you want to get the price from maybe is a bit too much...
Regardless we can do this change when we will actually implement the feature?

Copy link
Member

Choose a reason for hiding this comment

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

I think users should have full control over their data 🤷‍♂️

And sure, we can save it for when more are hosted.

Copy link
Member

@JSKitty JSKitty left a comment

Choose a reason for hiding this comment

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

tACK 8c2a8d7

@Duddino Duddino merged commit 262e98a into PIVX-Labs:master Apr 30, 2024
7 checks passed
panleone added a commit to panleone/MyPIVXWallet that referenced this pull request May 3, 2024
* refactor: create the event currency-update

* refactor: move cOracle global variable to prices.js

* load Oracle in constructor

* Make fLoadedCurrencies a private member of the class

* load the oracle on start

* apply review

* remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor A PR or suggestion for rewriting existing code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants