Commit c28cfe30 authored by Max's avatar Max

Storage: move history/pending to local storage

parent 4b9d4a87
......@@ -29,7 +29,6 @@ open Js_types
open Metal_message_types
open Metal_types
open Storage_types
open Current_version
open Local
open Chrome
......
......@@ -36,7 +36,9 @@ let get_network f =
let get_selected f =
Chrome.Storage.get Chrome.sync (fun (o:selected_entry t) -> f (selected o))
let get_accounts f =
Chrome.Storage.get Chrome.sync (fun (o:accounts_entry t) -> f (accounts o))
Chrome.Storage.get Chrome.sync (fun (o:accounts_entry t) ->
Chrome.Storage.get Chrome.Storage.local (fun (h:accounts_history_entry t) ->
f @@ accounts_history (accounts o) h))
let get_notifs f =
Chrome.Storage.get Chrome.Storage.local (fun (n : notif_entry t) -> f (notifs n))
......
......@@ -32,6 +32,11 @@ class type version_entry = object
method version : int optdef prop
end
class type ['a] network_assoc_js = object
method content : 'a prop
method network : js_string t prop
end
module V0 = struct
class type transaction_js = object
......@@ -149,11 +154,30 @@ end
module V3 = struct
include V2
class type ['a] network_assoc_js = object
method content : 'a prop
method network : js_string t prop
class type account_js = object
method pkh : js_string t prop
method manager : js_string t prop
method vault : vault_js t prop
method name : js_string t prop
method revealed : js_string t network_assoc_js t js_array t prop
method managerKT : bool t optdef prop
method admin : js_string t network_assoc_js t js_array t prop
end
class type accounts_entry = object
method accounts : account_js t js_array t optdef prop
end
class type config_entry = object
method useDunscan : bool t optdef prop
end
end
let current_version = 3
module Current_version = V3
module Local = struct
class type error_js = object
method kind : js_string t prop
method id : js_string t prop
......@@ -245,31 +269,6 @@ module V3 = struct
method operations : manager_info_js t manager_operation_js t js_array t prop
end
class type account_js = object
method pkh : js_string t prop
method manager : js_string t prop
method vault : vault_js t prop
method name : js_string t prop
method revealed : js_string t network_assoc_js t js_array t prop
method pending : block_operation_js t js_array t network_assoc_js t js_array t prop
method history : block_operation_js t js_array t network_assoc_js t js_array t prop
method managerKT : bool t optdef prop
method admin : js_string t network_assoc_js t js_array t prop
end
class type accounts_entry = object
method accounts : account_js t js_array t optdef prop
end
class type config_entry = object
method useDunscan : bool t optdef prop
end
end
let current_version = 3
module Current_version = V3
module Local = struct
class type notif_manager_info_js = object
method fee : js_string t optdef prop
......@@ -287,7 +286,7 @@ module Local = struct
method origin : js_string t prop
method msg : js_string t optdef prop
(* Operation *)
method op : notif_manager_info_js t Current_version.manager_operation_js t prop
method op : notif_manager_info_js t manager_operation_js t prop
(* Approv *)
method icon : js_string t optdef prop
method name : js_string t prop
......@@ -302,6 +301,16 @@ module Local = struct
class type notif_entry = object
method notifs : notif_acc t js_array t optdef prop
end
class type account_history_js = object
method pkh : js_string t prop
method pending : block_operation_js t js_array t network_assoc_js t js_array t prop
method history : block_operation_js t js_array t network_assoc_js t js_array t prop
end
class type accounts_history_entry = object
method history : account_history_js t js_array t optdef prop
end
end
......@@ -359,8 +368,6 @@ let upgrade_2_to_3 () =
a_new##.manager := a_old##.manager;
a_new##.vault := a_old##.vault;
a_new##.name := a_old##.name;
a_new##.pending := array [||];
a_new##.history := array [||];
a_new##.revealed := array [||];
a_new##.managerKT := undefined ;
a_new##.admin := array [||] ;
......@@ -371,7 +378,9 @@ let upgrade_2_to_3 () =
let config : V3.config_entry t = Unsafe.obj [||] in
config##.useDunscan := def _true;
Chrome.Storage.set Chrome.sync config
)
);
Chrome.Storage.clear Chrome.Storage.local
let downgrade_1_to_0 () =
Chrome.Storage.get Chrome.sync (fun (o:V1.accounts_entry1 t) ->
......
......@@ -217,15 +217,29 @@ module Of_js = struct
let name = to_string o##.name in
let vault = vault o##.vault in
let revealed = network_assoc to_string o##.revealed in
let pending = network_assoc (to_list block_operation) o##.pending in
let history = network_assoc (to_list block_operation) o##.history in
let manager_kt = to_optdef to_bool o##.managerKT in
let admin = network_assoc to_string o##.admin in
{pkh ; manager ; name ; vault ; revealed ; pending; history; manager_kt; admin }
{pkh ; manager ; name ; vault ; revealed; manager_kt; admin; pending =[];
history = []}
let accounts (o: accounts_entry t) =
List.map account (Array.to_list (unoptdef [||] to_array o##.accounts))
let account_history account (o: account_history_js t) = {
account with
pending = network_assoc (to_list block_operation) o##.pending;
history = network_assoc (to_list block_operation) o##.history;
}
let accounts_history accounts (o:accounts_history_entry t) =
match to_optdef (to_list (fun x -> x)) o##.history with
| None -> accounts
| Some l ->
List.map (fun a ->
match List.find_opt (fun o -> to_string o##.pkh = a.pkh) l with
| Some o -> account_history a o
| _ -> a) accounts
let network (o: network_entry t) =
Mhelpers.network_of_string (unoptdef "Testnet" to_string o##.network)
......@@ -434,8 +448,6 @@ module To_js = struct
account##.name := string a.name;
account##.vault := vault a.vault;
account##.revealed := network_assoc string a.revealed;
account##.pending := network_assoc (of_list block_operation) a.pending;
account##.history := network_assoc (of_list block_operation) a.history;
account##.managerKT := optdef bool a.manager_kt;
account##.admin := network_assoc string a.admin;
account
......@@ -445,6 +457,13 @@ module To_js = struct
data##.accounts := def (array (Array.of_list (List.map account accounts)));
data
let account_history a =
let account : account_history_js t = Unsafe.obj [||] in
account##.pkh := string a.pkh;
account##.pending := network_assoc (of_list block_operation) a.pending;
account##.history := network_assoc (of_list block_operation) a.history;
account
let network network =
let data : network_entry t = Unsafe.obj [||] in
data##.network := def (string (Mhelpers.network_to_string network));
......
......@@ -270,7 +270,7 @@ let make_op_page wid args =
let open Js_types in
let (data :
Storage_types.Local.notif_manager_info_js Js.t
Storage_types.Current_version.manager_operation_js Js.t) = ans##.res##.result in
Storage_types.Local.manager_operation_js Js.t) = ans##.res##.result in
let tsp = Jsdate.now_tsp () in
let not_op = Storage_utils.Of_js.(
manager_operation notif_manager_info data) in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment