|
1 | 1 | use crate::error::WasmSdkError; |
2 | 2 | use crate::queries::utils::{deserialize_required_query, identifier_from_js}; |
3 | | -use crate::queries::{ProofInfoWasm, ProofMetadataResponseWasm, ResponseMetadataWasm}; |
| 3 | +use crate::queries::ProofMetadataResponseWasm; |
4 | 4 | use crate::sdk::WasmSdk; |
5 | 5 | use dash_sdk::dpp::document::{Document, DocumentV0Getters}; |
6 | 6 | use dash_sdk::dpp::identity::accessors::IdentityGettersV0; |
@@ -119,27 +119,6 @@ fn parse_dpns_usernames_query( |
119 | 119 | }) |
120 | 120 | } |
121 | 121 |
|
122 | | -#[wasm_bindgen(js_name = "DpnsUsernamesProofResponse")] |
123 | | -#[derive(Clone)] |
124 | | -pub struct DpnsUsernamesProofResponseWasm { |
125 | | - #[wasm_bindgen(getter_with_clone)] |
126 | | - pub usernames: Array, |
127 | | - #[wasm_bindgen(getter_with_clone)] |
128 | | - pub metadata: ResponseMetadataWasm, |
129 | | - #[wasm_bindgen(getter_with_clone)] |
130 | | - pub proof: ProofInfoWasm, |
131 | | -} |
132 | | - |
133 | | -#[wasm_bindgen(js_name = "DpnsUsernameProofResponse")] |
134 | | -#[derive(Clone)] |
135 | | -pub struct DpnsUsernameProofResponseWasm { |
136 | | - #[wasm_bindgen(getter_with_clone)] |
137 | | - pub username: JsValue, |
138 | | - #[wasm_bindgen(getter_with_clone)] |
139 | | - pub metadata: ResponseMetadataWasm, |
140 | | - #[wasm_bindgen(getter_with_clone)] |
141 | | - pub proof: ProofInfoWasm, |
142 | | -} |
143 | 122 | impl WasmSdk { |
144 | 123 | async fn prepare_dpns_usernames_query( |
145 | 124 | &self, |
@@ -189,19 +168,19 @@ impl WasmSdk { |
189 | 168 | &self, |
190 | 169 | identity_id: Identifier, |
191 | 170 | limit: Option<u32>, |
192 | | - ) -> Result<DpnsUsernamesProofResponseWasm, WasmSdkError> { |
| 171 | + ) -> Result<ProofMetadataResponseWasm, WasmSdkError> { |
193 | 172 | let query = self |
194 | 173 | .prepare_dpns_usernames_query(identity_id, limit) |
195 | 174 | .await?; |
196 | 175 | let (documents_result, metadata, proof) = |
197 | 176 | Document::fetch_many_with_metadata_and_proof(self.as_ref(), query, None).await?; |
198 | 177 | let usernames_array = usernames_from_documents(documents_result); |
199 | 178 |
|
200 | | - Ok(DpnsUsernamesProofResponseWasm { |
201 | | - usernames: usernames_array, |
202 | | - metadata: metadata.into(), |
203 | | - proof: proof.into(), |
204 | | - }) |
| 179 | + Ok(ProofMetadataResponseWasm::from_parts( |
| 180 | + usernames_array.into(), |
| 181 | + metadata.into(), |
| 182 | + proof.into(), |
| 183 | + )) |
205 | 184 | } |
206 | 185 | } |
207 | 186 |
|
@@ -480,43 +459,44 @@ impl WasmSdk { |
480 | 459 | .map(Some) |
481 | 460 | .ok_or_else(|| WasmSdkError::generic("DPNS username is not a string")) |
482 | 461 | } |
483 | | - #[wasm_bindgen(js_name = "getDpnsUsernamesWithProofInfo")] |
| 462 | + #[wasm_bindgen( |
| 463 | + js_name = "getDpnsUsernamesWithProofInfo", |
| 464 | + unchecked_return_type = "ProofMetadataResponseTyped<Array<string>>" |
| 465 | + )] |
484 | 466 | pub async fn get_dpns_usernames_with_proof_info( |
485 | 467 | &self, |
486 | 468 | query: DpnsUsernamesQueryJs, |
487 | | - ) -> Result<DpnsUsernamesProofResponseWasm, WasmSdkError> { |
| 469 | + ) -> Result<ProofMetadataResponseWasm, WasmSdkError> { |
488 | 470 | let params = parse_dpns_usernames_query(query)?; |
489 | 471 | self.fetch_dpns_usernames_with_proof(params.identity_id, params.limit) |
490 | 472 | .await |
491 | 473 | } |
492 | 474 |
|
493 | | - #[wasm_bindgen(js_name = "getDpnsUsernameWithProofInfo")] |
| 475 | + #[wasm_bindgen( |
| 476 | + js_name = "getDpnsUsernameWithProofInfo", |
| 477 | + unchecked_return_type = "ProofMetadataResponseTyped<string | null>" |
| 478 | + )] |
494 | 479 | pub async fn get_dpns_username_with_proof_info( |
495 | 480 | &self, |
496 | 481 | #[wasm_bindgen(js_name = "identityId")] |
497 | 482 | #[wasm_bindgen(unchecked_param_type = "IdentifierLike")] |
498 | 483 | identity_id: JsValue, |
499 | | - ) -> Result<DpnsUsernameProofResponseWasm, WasmSdkError> { |
| 484 | + ) -> Result<ProofMetadataResponseWasm, WasmSdkError> { |
500 | 485 | let identity_id_parsed = identifier_from_js(&identity_id, "identity ID")?; |
501 | 486 |
|
502 | | - let DpnsUsernamesProofResponseWasm { |
503 | | - usernames, |
504 | | - metadata, |
505 | | - proof, |
506 | | - } = self |
| 487 | + let mut response = self |
507 | 488 | .fetch_dpns_usernames_with_proof(identity_id_parsed, Some(1)) |
508 | 489 | .await?; |
509 | 490 |
|
| 491 | + let usernames = js_sys::Array::from(&response.data()); |
510 | 492 | let username = if usernames.length() > 0 { |
511 | 493 | usernames.get(0) |
512 | 494 | } else { |
513 | 495 | JsValue::NULL |
514 | 496 | }; |
515 | 497 |
|
516 | | - Ok(DpnsUsernameProofResponseWasm { |
517 | | - username, |
518 | | - metadata, |
519 | | - proof, |
520 | | - }) |
| 498 | + response.set_data(username); |
| 499 | + |
| 500 | + Ok(response) |
521 | 501 | } |
522 | 502 | } |
0 commit comments