Skip to content
Snippets Groups Projects
Commit 44428b58 authored by Jono Wenger's avatar Jono Wenger
Browse files

Replace saving NDF to ekv in Javascript with local storage

parent 466ab010
No related branches found
No related tags found
1 merge request!510Release
......@@ -5,6 +5,9 @@
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
// This file is compiled for all architectures except WebAssembly.
//go:build !js || !wasm
package utility
import (
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
package utility
import (
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/ndf"
"os"
"syscall/js"
)
const NdfStorageKeyNamePrefix = "ndfStorageKey/"
var localStorage = js.Global().Get("localStorage")
func LoadNDF(_ *versioned.KV, key string) (*ndf.NetworkDefinition, error) {
keyValue := localStorage.Call("getItem", NdfStorageKeyNamePrefix+key)
if keyValue.IsNull() {
return nil, os.ErrNotExist
}
return ndf.Unmarshal([]byte(keyValue.String()))
}
func SaveNDF(_ *versioned.KV, key string, ndf *ndf.NetworkDefinition) error {
marshaled, err := ndf.Marshal()
if err != nil {
return err
}
localStorage.Call("setItem",
NdfStorageKeyNamePrefix+key, string(marshaled))
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment