User
Actions
Theme and Mode Preferences
updateMatchesDarkMode
Description: Updates the application's theme to match the user's system preference for dark mode.
Action:
updateMatchesDarkMode(boolean)
updateUserDarkMode
Description: Toggles the user's preference for dark mode within the application.
Action:
updateUserDarkMode(boolean)
updateUserExpertMode
Description: Toggles the expert mode setting, enabling or disabling advanced features for the user.
Action:
updateUserExpertMode(boolean)
User Preferences and Settings
updateUserFavorites
Description: Updates the user's list of favorite pairs.
Action:
updateUserFavorites(string[])
updateUserLeverage
Description: Updates the user's leverage for trades.
Action:
updateUserLeverage(number)
updateUserSlippageTolerance
Description: Updates the user's preferred slippage tolerance, which can be set to "auto" for automatic adjustment based on market conditions.
Action:
updateUserSlippageTolerance(string | "auto")
Account Information
updateAccount
Description: Updates the state's active sub-account.
Action:
updateAccount(object)
updateAccountUpnl
Description: Updates the account's unrealized profit and loss information at a specific timestamp.
Action:
updateAccountUpnl(object)
updateUpnlWebSocketStatus
Description: Updates the connection status of the WebSocket used for real-time Upnl updates.
Action:
updateUpnlWebSocketStatus(string)
updateAccountPartyAStat
Description: Updates statistical information related to partyA (balances, operational limits, cooldowns, etc.).
Action:
updateAccountPartyAStat(object)
Terms and Conditions
updateAcceptTerms
Description: Updates the user's acceptance status of the application's terms and conditions.
Action:
updateAcceptTerms(boolean)
Additional Account Information
updateAllAccountsUpnl
Description: Updates the Upnl information for all subaccounts associated with the user.
Action:
updateAllAccountsUpnl(object[])
Components
AllAccountsUpdater
Overview: Manages real-time updates for all user accounts connected to the application. It utilizes WebSockets to listen for updates related to the unrealized profit and loss (Upnl) information of each account and dispatches actions to update this information in the global state.
Implementation Details:
WebSocket Connection: Establishes a WebSocket connection using a URL provided by the
useHedgerInfo
hook, which contains the endpoint for Upnl updates.Message Handling: Listens for messages from the WebSocket connection, interpreting the received JSON message as AccountUpnl information.
State Updates: Dispatches the
updateAllAccountsUpnl
action to update the global state with the latest Upnl information for each account.Error Handling: Implements basic error handling by dispatching a default Upnl update in case of WebSocket errors or if no message is received.
Hooks
useIsDarkMode
Description: Determines if the user has enabled dark mode.
Returns: Boolean value indicating dark mode status.
useDarkModeManager
Description: Manages the toggling of dark mode.
Returns: A tuple containing the current dark mode status and a function to toggle this setting.
useSetSlippageToleranceCallback
Description: Updates the user's preferred slippage tolerance.
Returns: Function that accepts a slippage tolerance setting.
useSlippageTolerance
Description: Retrieves the user's current slippage tolerance setting.
Returns: Current slippage tolerance.
useSetExpertModeCallback
Description: Toggles the user's expert mode setting.
Returns: Callback to update expert mode.
useExpertMode
Description: Checks if expert mode is enabled for the user.
Returns: Boolean indicating expert mode status.
useUserWhitelist
Description: Determines if the user's account is whitelisted.
Returns: Boolean or null indicating whitelist status.
useLeverage
Description: Fetches the user's selected leverage setting.
Return: Current leverage value.
useSetLeverageCallback
Description: Updates the user's leverage setting.
Returns: Callback to update leverage.
useFavorites
Description: Retrieves the user's favorite symbols.
Returns: Array of favorite symbols.
useToggleUserFavoriteCallback
Description: Toggles a symbol's status as a favorite.
Returns: Function to toggle favorite status for a given symbol.
useActiveAccount
Description: Gets the currently active user account.
Returns: The active account object or null.
useActiveAccountAddress
Description: Retrieves the address of the active account.
Returns: Active account address or null.
useAccountPartyAStat
Description: Returns a structured object containing various statistics about PartyA.
Returns: Object with balances, operational limits, cooldowns, allocated and locked balances, and various counts.
useAccountUpnl
Description: Retrieves the unrealized profit and loss (Upnl) for the active account.
Returns: Upnl data for the account.
useSetUpnlWebSocketStatus
Description: Updates the WebSocket connection status for Upnl updates.
Returns: Function to update WebSocket status.
useGetBalanceHistoryCallback
Description: Fetches balance history for an account.
Returns: Callback to retrieve balance history.
useUpnlWebSocketStatus
Description: Gets the current WebSocket connection status for Upnl updates.
Returns: Current WebSocket status.
useIsWhiteList
Description: Checks if a specific account is whitelisted.
Returns: Function returning a promise that resolves to the whitelist status.
useAddInWhitelist
Description: Attempts to add a sub-account to the whitelist.
Returns: Function returning a promise with the whitelist addition result.
useBalanceHistory
Description: Accesses the balance history state.
Returns: Object containing balance history data and state.
useTotalDepositsAndWithdrawals
Description: Aggregates deposit and withdrawal data.
Returns: Object with aggregated data and its state.
useIsTermsAccepted
Description: Checks if the user has accepted terms and conditions.
Returns: Boolean indicating terms acceptance status.
useCustomAccountUpnl
Description: Fetches the uPnl of a specific user's subaccount.
Returns: Custom Upnl data or undefined.
Thunks
getIsWhiteList
Purpose: Checks if a given account is whitelisted.
Parameters:
baseUrl
: The base URL of the hedger API.account
: The user's account address.multiAccountAddress
: The address of the multi-account.appName
: Name of the application.
Returns: Whitelisted status.
getBalanceHistory
Purpose: Fetches the balance history for a given account.
Parameters:
account
: The user's subaccount address.chainId
: The chain id.skip
: The number of records to skip.first
: The number of records to fetch.
Returns:
Retrieves the balance history using Apollo Client from the GraphQL endpoint.
Returns the balance changes and a flag indicating if more records are available.
getTotalDepositsAndWithdrawals
Purpose: Retrieves total deposits and withdrawals for a given account.
Parameters:
account
: The user's subaccount address.chainId
: The chain id.
Returns:
Fetches data from a GraphQL endpoint using Apollo Client.
Returns the fetched data.
getBalanceInfo
Purpose: Obtains balance information for a given account.
Parameters:
baseUrl
: The base URL of the backend service.account
: The user's subaccount address.multiAccountAddress
: The address of the multi-account.
Returns: The fetched balance information.
Types
matchesDarkMode
: Indicates if the dark mode media query matches.userDarkMode
: User's preference for dark mode or light mode.userExpertMode
: Indicates if the expert mode is enabled.userSlippageTolerance
: User-defined slippage tolerance.timestamp
: Timestamp of the last update.favorites
: List of user's favorite items.leverage
: User's leverage setting.activeAccount
: The currently active account.activeAccountUpnl
: Unrealized P&L of the active account.upnlWebSocketStatus
: Connection status for the UPnL WebSocket.whiteListAccount
: Indicates if the account is whitelisted.accountsPartyAStat
: Statistics for Party A accounts.whiteListAccountState
: State of the whitelist check.allAccountsUpnl
: UPnL for all accounts.balanceHistory
: History of balance changes.balanceHistoryState
: State of fetching the balance history.hasMoreHistory
: Indicates if more history records are available.depositWithdrawalsData
: Data for deposits and withdrawals.depositWithdrawalsState
: ApiState of fetching deposit and withdrawal data.isTermsAccepted
: Status of terms acceptance.
BalanceHistoryType
Description: Enum for balance history types.
Values:
DEPOSIT_PARTY_A
: Represents a deposit to Party A.ALLOCATE_PARTY_A
: Allocation to Party A.DEALLOCATE_PARTY_A
: Deallocation from Party A.WITHDRAW_PARTY_A
: A withdrawal from Party A.
BalanceHistoryData
Description: Represents a single record in the balance history.
Properties:
amount
: The amount involved in the transaction.transaction
: The transaction hash.timestamp
: The timestamp of the transaction.account
: The account involved in the transaction.type
: The type of balance change.__typename
: GraphQL typename.
DepositWithdrawalsData
Description: Contains information about deposits and withdrawals.
Properties:
id
: Identifier for the data record.timestamp
: Timestamp of the record.withdraw
: Total amount withdrawn.deposit
: Total amount deposited.updateTimestamp
: Timestamp of the last update.__typename
: GraphQL typename.
WhiteListResponse
Description: Represents the response from a whitelist check.
Type: null or boolean.
GetWhiteListType
Description: Represents the response type for adding an account to the whitelist.
Properties:
successful
: Indicates if the operation was successful.message
: A message related to the operation.
TermsStatus
Description: Enum for terms acceptance status.
Values:
NOT_ACCEPTED
: Terms have not been accepted.ACCEPTED
: Terms have been accepted.UNCLEAR
: Status of terms acceptance is unclear.
BalanceInfo
Description: Represents balance information for an account.
Properties:
Detailed information about the account's balances, including allocated balance, cva, mm, lf, pending balances, upnl, notional amount, timestamp, and available balance.
BalanceInfosType
Description: A mapping from an account address to its BalanceInfo.
Type: Object with account addresses as keys and BalanceInfo as values.
Updaters
updaterUserContract
The UpdaterUserContract
utilizes Redux actions to synchronize the application state with the latest contract statistics (accountPartyAStat and activePartyAStat) and terms acceptance status (isTermsAccepted).
Last updated