Skip to content

Commit

Permalink
add method for getting gui details
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor committed Jan 10, 2025
1 parent b86f340 commit 532d535
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ impl_all_wasm_traits!(AvailableDeployments);
pub struct TokenInfos(#[tsify(type = "Map<string, TokenInfo>")] BTreeMap<Address, TokenInfo>);
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 {
Expand Down Expand Up @@ -148,6 +155,15 @@ impl DotrainOrderGui {
pub fn get_token_infos(&self) -> Result<TokenInfos, GuiError> {
Ok(TokenInfos(self.onchain_token_info.clone()))
}

#[wasm_bindgen(js_name = "getGuiDetails")]
pub fn get_gui_details(&self) -> Result<GuiDetails, GuiError> {
let gui = self.get_gui_config()?;
Ok(GuiDetails {
name: gui.name,
description: gui.description,
})
}
}

#[derive(Error, Debug)]
Expand Down
6 changes: 6 additions & 0 deletions packages/orderbook/test/js_api/gui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DepositCalldataResult,
Gui,
GuiDeployment,
GuiDetails,
SelectTokens,
TokenDeposit,
TokenInfos
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 532d535

Please sign in to comment.