Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(indexeddb): window usage in worker env #2131

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mm2src/mm2_db/src/indexed_db/indexed_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! try_serialize_index_value {
return MmError::err(DbTransactionError::ErrorSerializingIndex {
index: $index.to_owned(),
description: ser_err.to_string(),
})
});
},
}
}};
Expand Down Expand Up @@ -326,6 +326,7 @@ impl AddOrIgnoreResult {
}
}
}

impl<'transaction, Table: TableSignature> DbTable<'transaction, Table> {
/// Adds the given item to the table.
/// https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/add
Expand Down Expand Up @@ -830,7 +831,10 @@ fn open_cursor(
/// Detects the current execution environment (window or worker) and follows the appropriate way
/// of getting `web_sys::IdbFactory` instance.
pub(crate) fn get_idb_factory() -> Result<web_sys::IdbFactory, InitDbError> {
let global = js_sys::global();
// try getting global with type safety and explicit type conversion.
let global = js_sys::global()
.dyn_into::<js_sys::Object>()
.map_err(|err| InitDbError::NotSupported(format!("{err:?}")))?;

let idb_factory = if let Some(window) = global.dyn_ref::<Window>() {
window.indexed_db()
Expand Down Expand Up @@ -1216,7 +1220,7 @@ mod tests {
.expect("Couldn't get items by the index 'ticker=RICK'");
assert_eq!(actual_rick_txs, vec![
(rick_tx_1_id, rick_tx_1_updated),
(rick_tx_2_id, rick_tx_2)
(rick_tx_2_id, rick_tx_2),
]);
}

Expand Down
1 change: 0 additions & 1 deletion mm2src/mm2_test_helpers/src/for_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,6 @@ pub async fn enable_eth_coin(
json::from_str(&enable.1).unwrap()
}


pub async fn enable_spl(mm: &MarketMakerIt, coin: &str) -> Json {
let req = json!({
"userpass": mm.userpass,
Expand Down
Loading