import { AccountCreateData, BalanceData, LoginData, Reward, TxHistoryEntry, TxHistoryParams } from './types'; import ApiGroup, { ApiConfig } from '../ApiGroup'; import { Wallet } from 'ethers'; import { ApiReponse } from '../ApiClient'; import CurrentAccount from './CurrentAccount'; import { SupernetType } from '../ApiClient/WebSocketClient/types'; import { Tokens } from '../lib/AuthManager'; /** * Account API methods that let you interact with the user's account. * Can be accessed via `client.account`. Look for more samples below. * * @example Retrieve the current account balance * ```typescript * const balance = await client.account.refreshBalance(); * console.log(balance); * ``` * */ declare class AccountApi extends ApiGroup { readonly currentAccount: CurrentAccount; constructor(config: ApiConfig); private handleBalanceUpdate; private handleServerConnected; private handleServerDisconnected; private handleAuthUpdated; private getNonce; /** * Create Ethers.js Wallet instance from username and password. * This method is used internally to create a wallet for the user. * You can use this method to create a wallet if you need to sign transactions. * * @example Create a wallet from username and password * ```typescript * const wallet = client.account.getWallet('username', 'password'); * console.log(wallet.address); * ``` * * @param username - Sogni account username * @param password - Sogni account password */ getWallet(username: string, password: string): Wallet; /** * Create a new account with the given username, email, and password. * @internal * * @param username * @param email * @param password * @param subscribe * @param referralCode */ create(username: string, email: string, password: string, subscribe?: boolean, referralCode?: string): Promise; /** * Restore session with username and refresh token. * * You can save access token that you get from the login method and restore the session with this method. * * @example Store access token to local storage * ```typescript * const { username, token, refreshToken } = await client.account.login('username', 'password'); * localStorage.setItem('sogni-username', username); * localStorage.setItem('sogni-token', token); * localStorage.setItem('sogni-refresh-token', refreshToken); * ``` * * @example Restore session from local storage * ```typescript * const username = localStorage.getItem('sogni-username'); * const token = localStorage.getItem('sogni-token'); * const refreshToken = localStorage.getItem('sogni-refresh-token'); * if (username && refreshToken) { * client.account.setToken(username, {token, refreshToken}); * console.log('Session restored'); * } * ``` * * @param username * @param tokens - Refresh token, access token pair { refreshToken: string, token: string } */ setToken(username: string, tokens: Tokens): Promise; /** * Login with username and password. WebSocket connection is established after successful login. * * @example Login with username and password * ```typescript * await client.account.login('username', 'password'); * console.log('Logged in'); * ``` * * @param username * @param password */ login(username: string, password: string): Promise; /** * Logout the user and close the WebSocket connection. * * @example Logout the user * ```typescript * await client.account.logout(); * console.log('Logged out'); * ``` */ logout(): Promise; /** * Refresh the balance of the current account. * * Usually, you don't need to call this method manually. Balance is updated automatically * through WebSocket events. But you can call this method to force a balance refresh. * * @example Refresh user account balance * ```typescript * const balance = await client.account.refreshBalance(); * console.log(balance); * // { net: '100.000000', settled: '100.000000', credit: '0.000000', debit: '0.000000' } * ``` */ refreshBalance(): Promise; /** * Get the balance of the wallet address. * * This method is used to get the balance of the wallet address. It returns $SOGNI and ETH balance. * * @example Get the balance of the wallet address * ```typescript * const address = client.account.currentAccount.walletAddress; * const balance = await client.account.walletBalance(address); * console.log(balance); * // { token: '100.000000', ether: '0.000000' } * ``` * * @param walletAddress */ walletBalance(walletAddress: string): Promise<{ token: string; ether: string; }>; /** * Validate the username before signup * @internal * @param username */ validateUsername(username: string): Promise>; /** * Switch between fast and relaxed networks. * This will change default network used to process projects. After switching, client will receive * list of AI models available for on selected network. * * @example Switch to the fast network * ```typescript * await client.account.switchNetwork('fast'); * console.log('Switched to the fast network, now lets wait until we get list of models'); * await client.projects.waitForModels(); * ``` * @param network - Network type to switch to */ switchNetwork(network: SupernetType): Promise; /** * Get the transaction history of the current account. * * @example Get the transaction history * ```typescript * const { entries, next } = await client.account.transactionHistory({ * status: 'completed', * limit: 10, * address: client.account.currentAccount.walletAddress * }); * ``` * * @param params - Transaction history query parameters * @returns Transaction history entries and next query parameters */ transactionHistory(params: TxHistoryParams): Promise<{ entries: TxHistoryEntry[]; next: TxHistoryParams; }>; /** * Get the rewards of the current account. * @internal */ rewards(): Promise; /** * Claim rewards by reward IDs. * @internal * @param rewardIds */ claimRewards(rewardIds: string[]): Promise; /** * Withdraw funds from the current account to wallet. * @example withdraw to current wallet address * ```typescript * await client.account.withdraw('your-account-password', 100); * ``` * * @param password - account password * @param amount - amount of tokens to withdraw from account to wallet */ withdraw(password: string, amount: number): Promise; /** * Deposit tokens from wallet to account * @example withdraw to current wallet address * ```typescript * await client.account.deposit('your-account-password', 100); * ``` * * @param password - account password * @param amount - amount to transfer */ deposit(password: string, amount: number): Promise; } export default AccountApi;