Skip to content
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
12 changes: 12 additions & 0 deletions derive_client/_clients/rest/async_http/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
PrivateRegisterScopedSessionKeyResultSchema,
PrivateSessionKeysParamsSchema,
PrivateSessionKeysResultSchema,
PrivateSetCancelOnDisconnectParamsSchema,
PublicBuildRegisterSessionKeyTxResultSchema,
PublicDeregisterSessionKeyResultSchema,
PublicRegisterSessionKeyResultSchema,
Result,
Scope,
)

Expand Down Expand Up @@ -342,5 +344,15 @@ async def get(self) -> PrivateGetAccountResultSchema:
result = await self._private_api.rpc.get_account(params)
return result

async def set_cancel_on_disconnect(self, enabled: bool = True) -> Result:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no session for a async client.
Therefore this endpoint shouldnt be exposed on this endpoint type

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only relevant on websocket sessions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the OpenAPI spec. This is an account-level (LightAccount wallet) operation. It may very well constitute a persistent state change at this level! Something you can toggle on and off.

"""Enables cancel on disconnect for the account."""

params = PrivateSetCancelOnDisconnectParamsSchema(
wallet=self.address,
enabled=enabled,
)
result = await self._private_api.rpc.set_cancel_on_disconnect(params)
return result

def __repr__(self) -> str:
return f"<{self.__class__.__qualname__}({self.address}) object at {hex(id(self))}>"
12 changes: 12 additions & 0 deletions derive_client/_clients/rest/http/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
PrivateRegisterScopedSessionKeyResultSchema,
PrivateSessionKeysParamsSchema,
PrivateSessionKeysResultSchema,
PrivateSetCancelOnDisconnectParamsSchema,
PublicBuildRegisterSessionKeyTxResultSchema,
PublicDeregisterSessionKeyResultSchema,
PublicRegisterSessionKeyResultSchema,
Result,
Scope,
)

Expand Down Expand Up @@ -342,5 +344,15 @@ def get(self) -> PrivateGetAccountResultSchema:
result = self._private_api.rpc.get_account(params)
return result

def set_cancel_on_disconnect(self, enabled: bool = True) -> Result:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

"""Enables cancel on disconnect for the account."""

params = PrivateSetCancelOnDisconnectParamsSchema(
wallet=self.address,
enabled=enabled,
)
result = self._private_api.rpc.set_cancel_on_disconnect(params)
return result

def __repr__(self) -> str:
return f"<{self.__class__.__qualname__}({self.address}) object at {hex(id(self))}>"
2 changes: 1 addition & 1 deletion docs/reference/accounts/lightaccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
show_root_heading: false
heading_level: 2
members_order: source
members: ['__init__', 'address', 'build_register_session_key_tx', 'create_subaccount', 'deregister_session_key', 'edit_session_key', 'from_api', 'get', 'get_all_portfolios', 'get_subaccounts', 'refresh', 'register_scoped_session_key', 'register_session_key', 'session_keys', 'state']
members: ['__init__', 'address', 'build_register_session_key_tx', 'create_subaccount', 'deregister_session_key', 'edit_session_key', 'from_api', 'get', 'get_all_portfolios', 'get_subaccounts', 'refresh', 'register_scoped_session_key', 'register_session_key', 'session_keys', 'set_cancel_on_disconnect', 'state']
show_bases: false
show_source: false
inherited_members: false
Expand Down
7 changes: 7 additions & 0 deletions tests/test_clients/test_rest/test_async_http/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
PrivateGetSubaccountsResultSchema,
PrivateRegisterScopedSessionKeyResultSchema,
PrivateSessionKeysResultSchema,
Result,
Scope,
)

Expand Down Expand Up @@ -68,3 +69,9 @@ async def test_account_get(client_admin_wallet):
async def test_account_create_subaccount(client_admin_wallet):
create_subaccount_result = await client_admin_wallet.account.create_subaccount()
assert isinstance(create_subaccount_result, PrivateCreateSubaccountResultSchema)


@pytest.mark.asyncio
async def test_account_set_cancel_on_disconnect(client_admin_wallet):
result = await client_admin_wallet.account.set_cancel_on_disconnect()
assert isinstance(result, Result)
6 changes: 6 additions & 0 deletions tests/test_clients/test_rest/test_http/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
PrivateGetSubaccountsResultSchema,
PrivateRegisterScopedSessionKeyResultSchema,
PrivateSessionKeysResultSchema,
Result,
Scope,
)

Expand Down Expand Up @@ -61,3 +62,8 @@ def test_account_get(client_admin_wallet):
def test_account_create_subaccount(client_admin_wallet):
create_subaccount_result = client_admin_wallet.account.create_subaccount()
assert isinstance(create_subaccount_result, PrivateCreateSubaccountResultSchema)


def test_account_set_cancel_on_disconnect(client_admin_wallet):
result = client_admin_wallet.account.set_cancel_on_disconnect()
assert isinstance(result, Result)
7 changes: 7 additions & 0 deletions tests/test_clients/test_websocket/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
PrivateGetSubaccountsResultSchema,
PrivateRegisterScopedSessionKeyResultSchema,
PrivateSessionKeysResultSchema,
Result,
Scope,
)

Expand Down Expand Up @@ -68,3 +69,9 @@ async def test_account_get(client_admin_wallet):
async def test_account_create_subaccount(client_admin_wallet):
create_subaccount_result = await client_admin_wallet.account.create_subaccount()
assert isinstance(create_subaccount_result, PrivateCreateSubaccountResultSchema)


@pytest.mark.asyncio
async def test_account_set_cancel_on_disconnect(client_admin_wallet):
result = await client_admin_wallet.account.set_cancel_on_disconnect()
assert isinstance(result, Result)