coinbin icon indicating copy to clipboard operation
coinbin copied to clipboard

Save Network in a cookie

Open maxbethke opened this issue 4 years ago • 4 comments

Related to issue #220

Issue: Refer to #220

What has been done: Created a class for saving cookies to be able to have the choice the user made for his network beyond page reloads.

What has changed: Store the choosen dropdown option in a cookie. Restore the previously choosen option when the page is loaded.

maxbethke avatar Feb 01 '21 11:02 maxbethke

  1. Why not localStorage?
  2. Are those ESNext private class fields? Those should be avoided, as browser support is still low.

But even if you were to use them, you declare them but never use them, and instead use the public name. You have to keep the # for every get and set of the field. This will throw a parsing error in any browser that doesn't support it. (unlike other unsupported functions where "if you don't touch the affected code you're fine"... this will break the entire file from being parsed so be careful.)

Example:

class Test {
 #name
 constructor(name) {
   this.name = name;
   this.#name = 'PRIVATE ' + name;
 }
 get privateName() {
   return this.#name
 }
}
var x = new Test('bob');
console.log(x.name)
// bob
console.log(x.privateName)
// PRIVATE bob

junderw avatar Feb 01 '21 12:02 junderw

  1. Haven't thought about that. What is the advantage of localStorage, apart from being easier to use?

  2. Woops, those should not be there anymore... I intented to use ESNext fields, but scratched the Idea due to low browser support. Also the whole class would only with with ES6 Support, which is not widely supported too yet, is it?

maxbethke avatar Feb 01 '21 13:02 maxbethke

Did a bit of research on localStorage and came to the conclusion that in this case, it is the better way to do it. Thanks for pointing that out to me! @junderw

maxbethke avatar Feb 01 '21 14:02 maxbethke

@maxbethke Might worth to check out this PR as well https://github.com/OutCast3k/coinbin/pull/250, have added support for electrum servers as well.

ghost avatar May 16 '22 13:05 ghost