use gloo_storage::LocalStorage;
use super::StorageAdapter;
pub const STORAGE_ID: &str = "Wasm";
#[derive(Debug)]
pub struct WasmAdapter(LocalStorage);
impl WasmAdapter {
pub fn new() -> crate::wallet::Result<Self> {
Ok(Self(LocalStorage::new()))
}
}
#[async_trait::async_trait]
impl StorageAdapter for WasmAdapter {
async fn get(&self, key: &str) -> crate::wallet::Result<String> {
self.0.get(key)
}
async fn set(&mut self, key: &str, record: String) -> crate::wallet::Result<()> {
self.0.set(key, record)
}
async fn batch_set(&mut self, records: HashMap<String, String>) -> crate::wallet::Result<()> {
records.into_iter().map(|s| self.set(s.0, s.1));
Ok(())
}
async fn remove(&mut self, key: &str) -> crate::wallet::Result<()> {
self.0.delete(key)
}
}