Skip to content

Commit

Permalink
Merge pull request #1297 from rainlanguage/2025-02-14-deployment-details
Browse files Browse the repository at this point in the history
Add function to get a single deployment detail
  • Loading branch information
hardyjosh authored Feb 15, 2025
2 parents e776932 + 1eb6a20 commit f09f6c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
13 changes: 13 additions & 0 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ impl DotrainOrderGui {
Ok(DeploymentDetails(deployment_details.into_iter().collect()))
}

#[wasm_bindgen(js_name = "getDeploymentDetail")]
pub async fn get_deployment_detail(
dotrain: String,
key: String,
) -> Result<NameAndDescription, GuiError> {
let deployment_details = DotrainOrderGui::get_deployment_details(dotrain).await?;
let deployment_detail = deployment_details
.0
.get(&key)
.ok_or(GuiError::DeploymentNotFound(key))?;
Ok(deployment_detail.clone())
}

#[wasm_bindgen(js_name = "generateDotrainText")]
pub fn generate_dotrain_text(&self) -> Result<String, GuiError> {
let rain_document = RainDocument::create(self.dotrain_order.dotrain(), None, None, None);
Expand Down
9 changes: 9 additions & 0 deletions packages/orderbook/test/js_api/gui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function ()
assert.equal(entries[1][1].description, 'Buy WETH with USDC for fixed price on Base network.');
});

it('should get deployment detail', async () => {
const deploymentDetail: NameAndDescription = await DotrainOrderGui.getDeploymentDetail(
dotrainWithGui,
'other-deployment'
);
assert.equal(deploymentDetail.name, 'Test test');
assert.equal(deploymentDetail.description, 'Test test test');
});

it('should get token infos', async () => {
mockServer
.forPost('/rpc-url')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ export const load: LayoutLoad = async ({ params, parent }) => {
const { deploymentKey } = params;
const { dotrain } = (await parent()) as unknown as LayoutParentData;

// Process deployments for both raw and registry strategies
const deploymentWithDetails = await DotrainOrderGui.getDeploymentDetails(dotrain);
const deployments = Array.from(deploymentWithDetails, ([key, details]) => ({
key,
...details
}));

const deployment = deployments.find(
(deployment: { key: string }) => deployment.key === deploymentKey
const { name, description } = await DotrainOrderGui.getDeploymentDetail(
dotrain,
deploymentKey || ''
);

if (!deployment) {
throw new Error(`Deployment ${deploymentKey} not found`);
}

return { deployment, dotrain };
return { deployment: { key: deploymentKey, name, description }, dotrain };
};

0 comments on commit f09f6c9

Please sign in to comment.