Enhance token data retrieval and improve bot list filtering
- Updated `getTokenDataFromTicker` to support both synthetic and non-synthetic tokens by attempting to fetch v2 tokens first, falling back to a version-less search if necessary. - Added minimum and maximum balance filters to the bot list, allowing users to specify balance constraints for better bot management. - Refactored sorting direction to use a dedicated `SortDirection` enum for improved type safety.
This commit is contained in:
@@ -1168,12 +1168,21 @@ function getMarketInfoFromTicker(ticker: string, marketsInfoData: MarketsInfoDat
|
|||||||
|
|
||||||
export function getTokenDataFromTicker(ticker: string, tokensData: TokensData): TokenData {
|
export function getTokenDataFromTicker(ticker: string, tokensData: TokensData): TokenData {
|
||||||
console.log(`🔍 Looking up token for ticker: ${ticker}`);
|
console.log(`🔍 Looking up token for ticker: ${ticker}`);
|
||||||
const token = getTokenBySymbol(arbitrum.id, ticker, { version: "v2", isSynthetic: false });
|
// Try to find the token without synthetic filter to support both synthetic and non-synthetic tokens
|
||||||
|
// First try v2 tokens (preferred)
|
||||||
|
let token;
|
||||||
|
try {
|
||||||
|
token = getTokenBySymbol(arbitrum.id, ticker, { version: "v2" });
|
||||||
|
} catch (error) {
|
||||||
|
// If not found in v2, try without version constraint
|
||||||
|
token = getTokenBySymbol(arbitrum.id, ticker);
|
||||||
|
}
|
||||||
console.log(`📋 Token found:`, {
|
console.log(`📋 Token found:`, {
|
||||||
symbol: token.symbol,
|
symbol: token.symbol,
|
||||||
address: token.address,
|
address: token.address,
|
||||||
decimals: token.decimals,
|
decimals: token.decimals,
|
||||||
isNative: token.isNative
|
isNative: token.isNative,
|
||||||
|
isSynthetic: token.isSynthetic
|
||||||
});
|
});
|
||||||
const tokenData = getByKey(tokensData, token.address);
|
const tokenData = getByKey(tokensData, token.address);
|
||||||
console.log(`📊 Token data:`, {
|
console.log(`📊 Token data:`, {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
BotSortableColumn,
|
BotSortableColumn,
|
||||||
BotStatus,
|
BotStatus,
|
||||||
MoneyManagement,
|
MoneyManagement,
|
||||||
|
SortDirection,
|
||||||
StartCopyTradingRequest,
|
StartCopyTradingRequest,
|
||||||
TradingBotConfig,
|
TradingBotConfig,
|
||||||
TradingBotResponse
|
TradingBotResponse
|
||||||
@@ -72,8 +73,10 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
const [pageSize, setPageSize] = useState(20)
|
const [pageSize, setPageSize] = useState(20)
|
||||||
const [statusFilter, setStatusFilter] = useState<BotStatus | undefined>(undefined)
|
const [statusFilter, setStatusFilter] = useState<BotStatus | undefined>(undefined)
|
||||||
const [agentFilter, setAgentFilter] = useState<string | undefined>(undefined)
|
const [agentFilter, setAgentFilter] = useState<string | undefined>(undefined)
|
||||||
|
const [minBalance, setMinBalance] = useState<number | undefined>(undefined)
|
||||||
|
const [maxBalance, setMaxBalance] = useState<number | undefined>(undefined)
|
||||||
const [sortBy, setSortBy] = useState<BotSortableColumn>(BotSortableColumn.Roi)
|
const [sortBy, setSortBy] = useState<BotSortableColumn>(BotSortableColumn.Roi)
|
||||||
const [sortDirection, setSortDirection] = useState<'Asc' | 'Desc'>('Desc')
|
const [sortDirection, setSortDirection] = useState<SortDirection>(SortDirection.Desc)
|
||||||
|
|
||||||
// Use the user data for bot ownership checking
|
// Use the user data for bot ownership checking
|
||||||
const checkIsBotOwner = (botAgentName: string) => {
|
const checkIsBotOwner = (botAgentName: string) => {
|
||||||
@@ -82,8 +85,8 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
|
|
||||||
// Fetch paginated bot data
|
// Fetch paginated bot data
|
||||||
const { data: paginatedBots, isLoading } = useQuery({
|
const { data: paginatedBots, isLoading } = useQuery({
|
||||||
queryFn: () => client.bot_GetBotsPaginated(pageNumber, pageSize, statusFilter, undefined, undefined, agentFilter, sortBy, sortDirection),
|
queryFn: () => client.bot_GetBotsPaginated(pageNumber, pageSize, statusFilter, undefined, undefined, agentFilter, minBalance ?? null, maxBalance ?? null, sortBy, sortDirection),
|
||||||
queryKey: ['bots', pageNumber, pageSize, statusFilter, agentFilter, sortBy, sortDirection],
|
queryKey: ['bots', pageNumber, pageSize, statusFilter, agentFilter, minBalance, maxBalance, sortBy, sortDirection],
|
||||||
})
|
})
|
||||||
|
|
||||||
const [showMoneyManagementModal, setShowMoneyManagementModal] =
|
const [showMoneyManagementModal, setShowMoneyManagementModal] =
|
||||||
@@ -355,6 +358,11 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
accessor: 'profitAndLoss',
|
accessor: 'profitAndLoss',
|
||||||
Cell: ({ value }: any) => value?.toFixed(2) || '0.00',
|
Cell: ({ value }: any) => value?.toFixed(2) || '0.00',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Header: 'Trading Balance $',
|
||||||
|
accessor: 'botTradingBalance',
|
||||||
|
Cell: ({ value }: any) => value?.toFixed(2) || '0.00',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Header: 'Actions',
|
Header: 'Actions',
|
||||||
accessor: 'actions',
|
accessor: 'actions',
|
||||||
@@ -410,6 +418,36 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-control">
|
||||||
|
<label className="label">
|
||||||
|
<span className="label-text">Min Balance ($)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
placeholder="Min balance"
|
||||||
|
className="input input-bordered input-sm"
|
||||||
|
value={minBalance ?? ''}
|
||||||
|
onChange={(e) => setMinBalance(e.target.value ? Number(e.target.value) : undefined)}
|
||||||
|
min="0"
|
||||||
|
step="0.01"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-control">
|
||||||
|
<label className="label">
|
||||||
|
<span className="label-text">Max Balance ($)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
placeholder="Max balance"
|
||||||
|
className="input input-bordered input-sm"
|
||||||
|
value={maxBalance ?? ''}
|
||||||
|
onChange={(e) => setMaxBalance(e.target.value ? Number(e.target.value) : undefined)}
|
||||||
|
min="0"
|
||||||
|
step="0.01"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="form-control">
|
<div className="form-control">
|
||||||
<label className="label">
|
<label className="label">
|
||||||
<span className="label-text">Sort By</span>
|
<span className="label-text">Sort By</span>
|
||||||
@@ -422,6 +460,7 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
<option value={BotSortableColumn.Roi}>ROI</option>
|
<option value={BotSortableColumn.Roi}>ROI</option>
|
||||||
<option value={BotSortableColumn.Pnl}>Profit & Loss</option>
|
<option value={BotSortableColumn.Pnl}>Profit & Loss</option>
|
||||||
<option value={BotSortableColumn.WinRate}>Win Rate</option>
|
<option value={BotSortableColumn.WinRate}>Win Rate</option>
|
||||||
|
<option value={BotSortableColumn.BotTradingBalance}>Trading Balance</option>
|
||||||
<option value={BotSortableColumn.Name}>Name</option>
|
<option value={BotSortableColumn.Name}>Name</option>
|
||||||
<option value={BotSortableColumn.Status}>Status</option>
|
<option value={BotSortableColumn.Status}>Status</option>
|
||||||
<option value={BotSortableColumn.CreateDate}>Created At</option>
|
<option value={BotSortableColumn.CreateDate}>Created At</option>
|
||||||
@@ -435,10 +474,10 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
<select
|
<select
|
||||||
className="select select-bordered select-sm"
|
className="select select-bordered select-sm"
|
||||||
value={sortDirection}
|
value={sortDirection}
|
||||||
onChange={(e) => setSortDirection(e.target.value as 'Asc' | 'Desc')}
|
onChange={(e) => setSortDirection(e.target.value as SortDirection)}
|
||||||
>
|
>
|
||||||
<option value="Desc">Descending</option>
|
<option value={SortDirection.Desc}>Descending</option>
|
||||||
<option value="Asc">Ascending</option>
|
<option value={SortDirection.Asc}>Ascending</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user