From 532d535bce52e985f24132c1470ccd6f8e809929 Mon Sep 17 00:00:00 2001 From: findolor Date: Fri, 10 Jan 2025 20:49:55 +0100 Subject: [PATCH] add method for getting gui details --- crates/js_api/src/gui/mod.rs | 16 ++++++++++++++++ packages/orderbook/test/js_api/gui.test.ts | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/crates/js_api/src/gui/mod.rs b/crates/js_api/src/gui/mod.rs index 8bfb86cc1..35701359a 100644 --- a/crates/js_api/src/gui/mod.rs +++ b/crates/js_api/src/gui/mod.rs @@ -30,6 +30,13 @@ impl_all_wasm_traits!(AvailableDeployments); pub struct TokenInfos(#[tsify(type = "Map")] BTreeMap); impl_all_wasm_traits!(TokenInfos); +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Tsify)] +pub struct GuiDetails { + name: String, + description: String, +} +impl_all_wasm_traits!(GuiDetails); + #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[wasm_bindgen] pub struct DotrainOrderGui { @@ -148,6 +155,15 @@ impl DotrainOrderGui { pub fn get_token_infos(&self) -> Result { Ok(TokenInfos(self.onchain_token_info.clone())) } + + #[wasm_bindgen(js_name = "getGuiDetails")] + pub fn get_gui_details(&self) -> Result { + let gui = self.get_gui_config()?; + Ok(GuiDetails { + name: gui.name, + description: gui.description, + }) + } } #[derive(Error, Debug)] diff --git a/packages/orderbook/test/js_api/gui.test.ts b/packages/orderbook/test/js_api/gui.test.ts index 880f138c8..51b893852 100644 --- a/packages/orderbook/test/js_api/gui.test.ts +++ b/packages/orderbook/test/js_api/gui.test.ts @@ -11,6 +11,7 @@ import { DepositCalldataResult, Gui, GuiDeployment, + GuiDetails, SelectTokens, TokenDeposit, TokenInfos @@ -313,9 +314,14 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function () ); const gui = await DotrainOrderGui.chooseDeployment(dotrainWithGui, 'some-deployment'); + const guiConfig = gui.getGuiConfig() as Gui; assert.equal(guiConfig.name, 'Fixed limit'); assert.equal(guiConfig.description, 'Fixed limit order strategy'); + + const guiDetails: GuiDetails = gui.getGuiDetails(); + assert.equal(guiDetails.name, 'Fixed limit'); + assert.equal(guiDetails.description, 'Fixed limit order strategy'); }); it('should get token infos', async () => {