Add initAddress api

This commit is contained in:
2025-05-10 14:41:17 +07:00
parent b7d5a0b6a7
commit 549c4ae746
10 changed files with 170 additions and 46 deletions

View File

@@ -2159,6 +2159,45 @@ export class TradingClient extends AuthorizedApiBase {
}
return Promise.resolve<Position>(null as any);
}
trading_InitPrivyWallet(publicAddress: string): Promise<PrivyInitAddressResponse> {
let url_ = this.baseUrl + "/Trading/InitPrivyWallet";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(publicAddress);
let options_: RequestInit = {
body: content_,
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
};
return this.transformOptions(options_).then(transformedOptions_ => {
return this.http.fetch(url_, transformedOptions_);
}).then((_response: Response) => {
return this.processTrading_InitPrivyWallet(_response);
});
}
protected processTrading_InitPrivyWallet(response: Response): Promise<PrivyInitAddressResponse> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as PrivyInitAddressResponse;
return result200;
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<PrivyInitAddressResponse>(null as any);
}
}
export class UserClient extends AuthorizedApiBase {
@@ -3072,6 +3111,14 @@ export enum RiskLevel {
Adaptive = "Adaptive",
}
export interface PrivyInitAddressResponse {
success?: boolean;
usdcHash?: string | null;
orderVaultHash?: string | null;
exchangeRouterHash?: string | null;
error?: string | null;
}
export interface LoginRequest {
name: string;
address: string;

View File

@@ -1,21 +1,12 @@
import {
ChevronDownIcon,
ChevronRightIcon,
ClipboardCopyIcon,
TrashIcon,
} from '@heroicons/react/solid'
import React, { useEffect, useState, useMemo } from 'react'
import { useNavigate } from 'react-router-dom'
import { FiPlus, FiTrash2, FiKey, FiTrendingUp } from 'react-icons/fi'
import {ChevronDownIcon, ChevronRightIcon,} from '@heroicons/react/solid'
import React, {useEffect, useMemo, useState} from 'react'
import {useNavigate} from 'react-router-dom'
import {FiKey, FiPlay, FiTrash2, FiTrendingUp} from 'react-icons/fi'
import useApiUrlStore from '../../../app/store/apiStore'
import {
SelectColumnFilter,
Table,
Toast,
} from '../../../components/mollecules'
import type { Account } from '../../../generated/ManagingApi'
import { AccountClient, AccountType } from '../../../generated/ManagingApi'
import {SelectColumnFilter, Table, Toast,} from '../../../components/mollecules'
import type {Account} from '../../../generated/ManagingApi'
import {AccountClient, AccountType, TradingClient} from '../../../generated/ManagingApi'
import AccountRowDetails from './accountRowDetails'
import PrivyDelegationModal from './PrivyDelegationModal'
@@ -48,6 +39,22 @@ const AccountTable: React.FC<IAccountList> = ({ list, isFetching }) => {
})
}
async function initPrivyWallet(publicAddress: string) {
const t = new Toast('Initializing Privy wallet')
const client = new TradingClient({}, apiUrl)
try {
const response = await client.trading_InitPrivyWallet(publicAddress)
if (response.success) {
t.update('success', 'Privy wallet initialized successfully')
} else {
t.update('error', `Initialization failed: ${response.error || 'Unknown error'}`)
}
} catch (err) {
t.update('error', 'Error: ' + err)
}
}
const columns = useMemo(
() => [
{
@@ -114,29 +121,37 @@ const AccountTable: React.FC<IAccountList> = ({ list, isFetching }) => {
</button>
{account.type === AccountType.Privy && (
<button
className="btn btn-sm btn-primary btn-outline"
onClick={() => {
setModalAccount(account)
setIsDelegationModalOpen(true)
}}
>
<FiKey />
<span className="ml-1">Delegate</span>
</button>
)}
<>
<button
className="btn btn-sm btn-primary btn-outline"
onClick={() => {
setModalAccount(account)
setIsDelegationModalOpen(true)
}}
>
<FiKey />
<span className="ml-1">Delegate</span>
</button>
{account.type === AccountType.Privy && (
<button
className="btn btn-sm btn-success btn-outline"
onClick={() => {
setModalAccount(account)
setIsGmxPositionModalOpen(true)
}}
>
<FiTrendingUp />
<span className="ml-1">GMX</span>
</button>
<button
className="btn btn-sm btn-info btn-outline"
onClick={() => initPrivyWallet(account.key)}
>
<FiPlay />
<span className="ml-1">Init</span>
</button>
<button
className="btn btn-sm btn-success btn-outline"
onClick={() => {
setModalAccount(account)
setIsGmxPositionModalOpen(true)
}}
>
<FiTrendingUp />
<span className="ml-1">GMX</span>
</button>
</>
)}
</div>
)