Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2025-02-18-update-field-definiti…
Browse files Browse the repository at this point in the history
…ons-on-token-change' into 02/19/25-Remove-null-gui-from-DeploymentSteps
  • Loading branch information
hardingjam committed Feb 19, 2025
2 parents 45119d2 + 23308f2 commit 1ef1ef5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
14 changes: 14 additions & 0 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub struct TokenInfo {
}
impl_all_wasm_traits!(TokenInfo);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Tsify)]
pub struct AllTokenInfos(Vec<TokenInfo>);
impl_all_wasm_traits!(AllTokenInfos);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Tsify)]
pub struct DeploymentDetails(BTreeMap<String, NameAndDescription>);
impl_all_wasm_traits!(DeploymentDetails);
Expand Down Expand Up @@ -147,6 +151,16 @@ impl DotrainOrderGui {
Ok(token_info)
}

#[wasm_bindgen(js_name = "getAllTokenInfos")]
pub async fn get_all_token_infos(&self) -> Result<AllTokenInfos, GuiError> {
let token_infos = self.dotrain_order.orderbook_yaml().get_token_keys()?;
let mut result = Vec::new();
for key in token_infos.iter() {
result.push(self.get_token_info(key.clone()).await?);
}
Ok(AllTokenInfos(result))
}

#[wasm_bindgen(js_name = "getStrategyDetails")]
pub async fn get_strategy_details(dotrain: String) -> Result<NameAndDescription, GuiError> {
let dotrain_order = DotrainOrder::new(dotrain, None).await?;
Expand Down
35 changes: 35 additions & 0 deletions packages/orderbook/test/js_api/gui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AddOrderCalldataResult,
AllFieldValuesResult,
AllowancesResult,
AllTokenInfos,
DeploymentDetails,
DeploymentKeys,
DeploymentTransactionArgs,
Expand Down Expand Up @@ -433,6 +434,40 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function ()
assert.equal(token2TokenInfo.symbol, 'T2');
});

it('should get token infos', async () => {
mockServer
.forPost('/rpc-url')
.once()
.withBodyIncluding('0x82ad56cb')
.thenSendJsonRpcResult(
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000007546f6b656e203100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000025431000000000000000000000000000000000000000000000000000000000000'
);
mockServer
.forPost('/rpc-url')
.once()
.withBodyIncluding('0x82ad56cb')
.thenSendJsonRpcResult(
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000007546f6b656e203200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000025432000000000000000000000000000000000000000000000000000000000000'
);
const dotrainWithGui = `
${guiConfig2}
${dotrain}
`;
const gui = await DotrainOrderGui.chooseDeployment(dotrainWithGui, 'other-deployment');

let allTokenInfos: AllTokenInfos = await gui.getAllTokenInfos();
assert.equal(allTokenInfos.length, 2);
assert.equal(allTokenInfos[0].address, '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063');
assert.equal(allTokenInfos[0].decimals, 18);
assert.equal(allTokenInfos[0].name, 'Token 2');
assert.equal(allTokenInfos[0].symbol, 'T2');
assert.equal(allTokenInfos[1].address, '0xc2132d05d31c914a87c6611c10748aeb04b58e8f');
assert.equal(allTokenInfos[1].decimals, 6);
assert.equal(allTokenInfos[1].name, 'Token 1');
assert.equal(allTokenInfos[1].symbol, 'T1');
});

describe('deposit tests', async () => {
let gui: DotrainOrderGui;
beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
type GuiDeployment,
type OrderIO,
type SelectTokens,
type NameAndDescription
type NameAndDescription,
type AllTokenInfos
} from '@rainlanguage/orderbook/js_api';
import { fade } from 'svelte/transition';
import { Button, Toggle, Spinner } from 'flowbite-svelte';
Expand Down Expand Up @@ -65,6 +66,7 @@
let errorDetails: string | null = null;
let networkKey: string | null = null;
let subgraphUrl: string = '';
let allTokenInfos: AllTokenInfos = [];
export let wagmiConfig: Writable<Config | undefined>;
export let wagmiConnected: Writable<boolean>;
Expand Down Expand Up @@ -186,6 +188,15 @@
async function _handleUpdateGuiState(gui: DotrainOrderGui) {
await areAllTokensSelected();
if (allTokensSelected) {
let newAllTokenInfos = await gui.getAllTokenInfos();
if (newAllTokenInfos !== allTokenInfos) {
allTokenInfos = newAllTokenInfos;
updateFields();
}
}
handleUpdateGuiState(gui);
}
Expand Down Expand Up @@ -253,6 +264,8 @@
allTokensSelected = gui.areAllTokensSelected();
if (!allTokensSelected) return;
allTokenInfos = await gui.getAllTokenInfos();
// if we have deposits or vault ids set, show advanced options
const hasDeposits = gui.hasAnyDeposit();
const hasVaultIds = gui.hasAnyVaultId();
Expand Down

0 comments on commit 1ef1ef5

Please sign in to comment.