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

Add function to get a single deployment detail #1297

Merged
merged 4 commits into from
Feb 15, 2025
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
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 };
};