Skip to content

Commit

Permalink
Merge branch 'main' into 2025-02-18-get-transaction-args
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam authored Feb 19, 2025
2 parents 36fb2bc + 4d75471 commit ce234d6
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 399 deletions.
5 changes: 5 additions & 0 deletions crates/js_api/src/gui/deposits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,9 @@ impl DotrainOrderGui {
}
Ok(missing_deposits)
}

#[wasm_bindgen(js_name = "hasAnyDeposit")]
pub fn has_any_deposit(&self) -> bool {
!self.deposits.is_empty()
}
}
6 changes: 6 additions & 0 deletions crates/js_api/src/gui/order_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ impl DotrainOrderGui {
Ok(IOVaultIds(map))
}

#[wasm_bindgen(js_name = "hasAnyVaultId")]
pub fn has_any_vault_id(&self) -> Result<bool, GuiError> {
let map = self.get_vault_ids()?;
Ok(map.0.values().any(|ids| ids.iter().any(|id| id.is_some())))
}

#[wasm_bindgen(js_name = "updateScenarioBindings")]
pub fn update_scenario_bindings(&mut self) -> Result<(), GuiError> {
let deployment = self.get_current_deployment()?;
Expand Down
8 changes: 8 additions & 0 deletions packages/orderbook/test/js_api/gui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,13 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function ()
});

it('should add deposit', async () => {
assert.equal(gui.hasAnyDeposit(), false);

gui.saveDeposit('token1', '50.6');
const deposits: TokenDeposit[] = gui.getDeposits();
assert.equal(deposits.length, 1);

assert.equal(gui.hasAnyDeposit(), true);
});

it('should update deposit', async () => {
Expand Down Expand Up @@ -1177,8 +1181,12 @@ ${dotrainWithoutVaultIds}`;
assert.equal(currentDeployment.deployment.order.inputs[0].vaultId, undefined);
assert.equal(currentDeployment.deployment.order.outputs[0].vaultId, undefined);

assert.equal(gui.hasAnyVaultId(), false);

gui.setVaultId(true, 0, '0x123');

assert.equal(gui.hasAnyVaultId(), true);

assert.equal(gui.getVaultIds().get('input')?.[0], '0x123');
assert.equal(gui.getVaultIds().get('output')?.[0], undefined);

Expand Down
192 changes: 57 additions & 135 deletions packages/ui-components/src/__tests__/DeploymentSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import type { ComponentProps } from 'svelte';
import { writable } from 'svelte/store';
import type { AppKit } from '@reown/appkit';
import type { ConfigSource } from '../lib/typeshare/config';
import type { DeploymentArgs } from '$lib/types/transaction';
import type { DisclaimerModal } from '$lib';
import type { DeployModalProps, DisclaimerModalProps } from '../lib/types/modal';

const { mockWagmiConfigStore, mockConnectedStore } = await vi.hoisted(
() => import('../lib/__mocks__/stores')
Expand Down Expand Up @@ -572,22 +571,31 @@ min-trade-amount: mul(min-amount 0.9),
"Min trade amount."),
:call<'set-cost-basis-io-ratio>();`;

describe('DeploymentSteps', () => {
const mockDeployment = {
const mockDeployment = {
key: 'flare-sflr-wflr',
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
deposits: [],
fields: [],
select_tokens: [],
deployment: {
key: 'flare-sflr-wflr',
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
deposits: [],
fields: [],
select_tokens: [],
deployment: {
scenario: {
key: 'flare',
bindings: {}
} as Scenario,
order: {
key: 'flare-sflr-wflr',
scenario: {
network: {
key: 'flare',
'chain-id': 14,
'network-id': 14,
rpc: 'https://rpc.ankr.com/flare',
label: 'Flare',
currency: 'FLR'
},
deployer: {
key: 'flare',
bindings: {}
} as Scenario,
order: {
key: 'flare-sflr-wflr',
network: {
key: 'flare',
'chain-id': 14,
Expand All @@ -596,28 +604,36 @@ describe('DeploymentSteps', () => {
label: 'Flare',
currency: 'FLR'
},
deployer: {
key: 'flare',
network: {
key: 'flare',
'chain-id': 14,
'network-id': 14,
rpc: 'https://rpc.ankr.com/flare',
label: 'Flare',
currency: 'FLR'
},
address: '0x0'
},
orderbook: {
id: 'flare',
address: '0x0'
},
inputs: [],
outputs: []
}
address: '0x0'
},
orderbook: {
id: 'flare',
address: '0x0'
},
inputs: [],
outputs: []
}
};
}
};

const defaultProps: DeploymentStepsProps = {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeployModalProps) => void,
handleDisclaimerModal: vi.fn() as unknown as (args: DisclaimerModalProps) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
};

describe('DeploymentSteps', () => {
beforeEach(() => {
vi.clearAllMocks();
});
Expand All @@ -629,26 +645,7 @@ describe('DeploymentSteps', () => {
getNetworkKey: vi.fn()
});

render(DeploymentSteps, {
props: {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeploymentArgs) => void,
handleDisclaimerModal: vi.fn() as unknown as (
args: ComponentProps<DisclaimerModal>
) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
}
});
render(DeploymentSteps, { props: defaultProps });

await waitFor(() => {
expect(screen.getByText('SFLR<>WFLR on Flare')).toBeInTheDocument();
Expand All @@ -663,26 +660,7 @@ describe('DeploymentSteps', () => {
getNetworkKey: vi.fn()
});

render(DeploymentSteps, {
props: {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeploymentArgs) => void,
handleDisclaimerModal: vi.fn() as unknown as (
args: ComponentProps<DisclaimerModal>
) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
}
});
render(DeploymentSteps, { props: defaultProps });

await waitFor(() => {
expect(screen.getByText('Select Tokens')).toBeInTheDocument();
Expand All @@ -697,26 +675,7 @@ describe('DeploymentSteps', () => {
new Error('Failed to initialize GUI')
);

render(DeploymentSteps, {
props: {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeploymentArgs) => void,
handleDisclaimerModal: vi.fn() as unknown as (
args: ComponentProps<DisclaimerModal>
) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
}
});
render(DeploymentSteps, { props: defaultProps });

await waitFor(() => {
expect(screen.getByText('Error loading GUI')).toBeInTheDocument();
Expand All @@ -742,31 +701,13 @@ describe('DeploymentSteps', () => {
getNetworkKey: vi.fn()
});

render(DeploymentSteps, {
props: {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeploymentArgs) => void,
handleDisclaimerModal: vi.fn() as unknown as (
args: ComponentProps<DisclaimerModal>
) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
}
});
render(DeploymentSteps, { props: defaultProps });

await waitFor(() => {
expect(screen.getByText('Deploy Strategy')).toBeInTheDocument();
});
});

it('shows connect wallet button when not connected', async () => {
mockConnectedStore.mockSetSubscribeValue(false);
(DotrainOrderGui.chooseDeployment as Mock).mockResolvedValue({
Expand All @@ -785,26 +726,7 @@ describe('DeploymentSteps', () => {
getNetworkKey: vi.fn()
});

render(DeploymentSteps, {
props: {
dotrain,
strategyDetail: {
name: 'SFLR<>WFLR on Flare',
description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.',
short_description: 'Rotate sFLR (Sceptre staked FLR) and WFLR on Flare.'
},
deployment: mockDeployment,
wagmiConfig: mockWagmiConfigStore,
wagmiConnected: mockConnectedStore,
appKitModal: writable({} as AppKit),
handleDeployModal: vi.fn() as unknown as (args: DeploymentArgs) => void,
handleDisclaimerModal: vi.fn() as unknown as (
args: ComponentProps<DisclaimerModal>
) => void,
settings: writable({} as ConfigSource),
handleUpdateGuiState: vi.fn()
}
});
render(DeploymentSteps, { props: defaultProps });

await waitFor(() => {
expect(screen.getByText('Connect Wallet')).toBeInTheDocument();
Expand Down
22 changes: 17 additions & 5 deletions packages/ui-components/src/__tests__/OrderDetail.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import CardProperty from '../lib/components/CardProperty.svelte';
import ButtonVaultLink from '../lib/components/ButtonVaultLink.svelte';
import { createQuery } from '@tanstack/svelte-query';
import type { OrderSubgraph, OrderWithSortedVaults } from '@rainlanguage/orderbook/js_api';
import type { OrderWithSortedVaults } from '@rainlanguage/orderbook/js_api';
import { getOrder } from '@rainlanguage/orderbook/js_api';
import { QKEY_ORDER } from '../lib/queries/keys';
import type { Readable } from 'svelte/store';
import { Button } from 'flowbite-svelte';
import DepositOrWithdrawButtons from '../lib/components/detail/DepositOrWithdrawButtons.svelte';
import type { OrderRemoveModalProps } from '../lib/types/modal';
import type { Hex } from 'viem';
export let walletAddressMatchesOrBlank: Readable<(address: string) => boolean> | undefined =
undefined;
export let handleOrderRemoveModal:
| ((order: OrderSubgraph, refetch: () => void) => void)
| undefined = undefined;
export let handleOrderRemoveModal: ((props: OrderRemoveModalProps) => void) | undefined =
undefined;
export let id: string;
export let subgraphUrl: string;
export let chainId: number;
export let orderbookAddress: Hex;
$: orderDetailQuery = createQuery<OrderWithSortedVaults>({
queryKey: [id, QKEY_ORDER + id],
Expand All @@ -32,7 +35,16 @@
<Button
data-testid="remove-button"
color="dark"
on:click={() => handleOrderRemoveModal(data.order, $orderDetailQuery.refetch)}
on:click={() =>
handleOrderRemoveModal({
open: true,
args: {
order: data.order,
onRemove: $orderDetailQuery.refetch,
chainId,
orderbookAddress
}
})}
disabled={!handleOrderRemoveModal}
>
Remove
Expand Down
Loading

0 comments on commit ce234d6

Please sign in to comment.