kill utils.js, reduce (set|get)(Local|Session) to just lbry.js
This commit is contained in:
parent
b49318aead
commit
010534cc16
6 changed files with 48 additions and 61 deletions
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { formatCredits, formatFullPrice } from "utils";
|
||||
import { formatCredits, formatFullPrice } from "util/formatCredits";
|
||||
import lbry from "../lbry.js";
|
||||
|
||||
//component/icon.js
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { formatCredits } from "utils";
|
||||
import { formatCredits } from "util/formatCredits";
|
||||
import { connect } from "react-redux";
|
||||
import { selectIsBackDisabled, selectIsForwardDisabled } from "selectors/app";
|
||||
import { selectBalance } from "selectors/wallet";
|
||||
|
|
|
@ -1,8 +1,28 @@
|
|||
import lbryio from "./lbryio.js";
|
||||
import lighthouse from "./lighthouse.js";
|
||||
import jsonrpc from "./jsonrpc.js";
|
||||
import lbryuri from "./lbryuri.js";
|
||||
import { getLocal, getSession, setSession, setLocal } from "./utils.js";
|
||||
|
||||
/**
|
||||
* The 4 get/set functions below used to be in a utils.js library when used more widely.
|
||||
* They've been reduced to just this file and probably ought to be eliminated entirely.
|
||||
*/
|
||||
function getLocal(key, fallback = undefined) {
|
||||
const itemRaw = localStorage.getItem(key);
|
||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
||||
}
|
||||
|
||||
function setLocal(key, value) {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
function getSession(key, fallback = undefined) {
|
||||
const itemRaw = sessionStorage.getItem(key);
|
||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
||||
}
|
||||
|
||||
function setSession(key, value) {
|
||||
sessionStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
const { remote, ipcRenderer } = require("electron");
|
||||
const menu = remote.require("./menu/main-menu");
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import * as types from "constants/action_types";
|
||||
import { getLocal } from "utils";
|
||||
|
||||
const reducers = {};
|
||||
|
||||
|
|
24
ui/js/util/formatCredits.js
Normal file
24
ui/js/util/formatCredits.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
export function formatCredits(amount, precision) {
|
||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, "");
|
||||
}
|
||||
|
||||
export function formatFullPrice(amount, precision) {
|
||||
let formated = "";
|
||||
|
||||
const quantity = amount.toString().split(".");
|
||||
const fraction = quantity[1];
|
||||
|
||||
if (fraction) {
|
||||
// Set precision
|
||||
precision = precision || 1;
|
||||
|
||||
const decimals = fraction.split("");
|
||||
const first = decimals.filter(number => number != "0")[0];
|
||||
const index = decimals.indexOf(first);
|
||||
|
||||
// Set format fraction
|
||||
formated = "." + fraction.substring(0, index + precision);
|
||||
}
|
||||
|
||||
return parseFloat(quantity[0] + formated);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
||||
* is not set yet.
|
||||
*/
|
||||
export function getLocal(key, fallback = undefined) {
|
||||
const itemRaw = localStorage.getItem(key);
|
||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
||||
*/
|
||||
export function setLocal(key, value) {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Thin wrapper around localStorage.getItem(). Parses JSON and returns undefined if the value
|
||||
* is not set yet.
|
||||
*/
|
||||
export function getSession(key, fallback = undefined) {
|
||||
const itemRaw = sessionStorage.getItem(key);
|
||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thin wrapper around localStorage.setItem(). Converts value to JSON.
|
||||
*/
|
||||
export function setSession(key, value) {
|
||||
sessionStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
export function formatCredits(amount, precision) {
|
||||
return amount.toFixed(precision || 1).replace(/\.?0+$/, "");
|
||||
}
|
||||
|
||||
export function formatFullPrice(amount, precision) {
|
||||
let formated = "";
|
||||
|
||||
const quantity = amount.toString().split(".");
|
||||
const fraction = quantity[1];
|
||||
|
||||
if (fraction) {
|
||||
// Set precision
|
||||
precision = precision || 1;
|
||||
|
||||
const decimals = fraction.split("");
|
||||
const first = decimals.filter(number => number != "0")[0];
|
||||
const index = decimals.indexOf(first);
|
||||
|
||||
// Set format fraction
|
||||
formated = "." + fraction.substring(0, index + precision);
|
||||
}
|
||||
|
||||
return parseFloat(quantity[0] + formated);
|
||||
}
|
Loading…
Reference in a new issue