Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
thal0x committed Sep 12, 2023
2 parents 7475957 + 0a3cf90 commit c3d1338
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function useSwapWidget() {
]);

const { address } = useChain(
formValues.sourceChain?.chainName ?? "cosmoshub"
formValues.sourceChain?.record?.name ?? "cosmoshub"
);

const { data: balances } = useBalancesByChain(
Expand Down
57 changes: 57 additions & 0 deletions src/solve/client/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { AxiosInstance, AxiosResponse } from "axios";
import { Packet, StatusError, StatusState, TransferInfo } from "../types";

export interface StatusRequest {
tx_hash: string;
chain_id: string;
}

export interface StatusResponse {
status: StatusState;
transfer_sequence: TransferInfo[];
error?: StatusError;
}

export interface TrackRequest {
tx_hash: string;
chain_id: string;
}

export interface TrackResponse {
success: boolean;
tx_hash: string;
}

export class TransactionService {
private httpClient: AxiosInstance;

constructor(httpClient: AxiosInstance) {
this.httpClient = httpClient;
}

async track(txHash: string, chainID: string): Promise<TrackResponse> {
const response = await this.httpClient.post<
TrackResponse,
AxiosResponse<TrackResponse, any>,
TrackRequest
>("/tx/track", {
tx_hash: txHash,
chain_id: chainID,
});

return response.data;
}

async status(txHash: string, chainID: string): Promise<StatusResponse> {
const params: StatusRequest = {
tx_hash: txHash,
chain_id: chainID,
};

const response = await this.httpClient.get<StatusResponse>("/tx/status", {
params,
});

return response.data;
}
}
147 changes: 147 additions & 0 deletions src/solve/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
export interface Asset {
denom: string;
chain_id: string;

origin_denom: string;
origin_chain_id: string;

symbol?: string;
name?: string;
logo_uri?: string;
decimals?: number;
}

export type AssetWithMetadata = Required<Asset>;

export interface Chain {
chain_name: string;
chain_id: string;
pfm_enabled: boolean;
cosmos_sdk_version: string;
modules: Record<string, ModuleVersionInfo>;
}

export interface ChainTransaction {
chain_id: string;
tx_hash: string;
}

export interface ModuleVersionInfo {
path: string;
version: string;
sum: string;
}

export type TransferState =
| "TRANSFER_UNKNOWN"
| "TRANSFER_PENDING"
| "TRANSFER_RECEIVED"
| "TRANSFER_SUCCESS"
| "TRANSFER_FAILURE";

export interface TransferInfo {
src_chain_id: string;
dst_chain_id: string;
state: TransferState;
packet_txs: Packet;
}

export interface Packet {
send_tx?: ChainTransaction;
receive_tx?: ChainTransaction;
acknowledge_tx?: ChainTransaction;
timeout_tx?: ChainTransaction;

error?: PacketError;
}

export interface PacketError {
code: number;
message: string;
}

export interface StatusError {
code: number;
message: string;
}

export type StatusState =
| "STATE_UNKNOWN"
| "STATE_SUBMITTED"
| "STATE_PENDING"
| "STATE_RECEIVED"
| "STATE_COMPLETED"
| "STATE_ABANDONED";

export interface SwapVenue {
name: string;
chain_id: string;
}

export interface SwapOperation {
pool: string;
denom_in: string;
denom_out: string;
}

export interface SwapExactCoinOut {
swap_venue: SwapVenue;
swap_operations: SwapOperation[];
swap_amount_out: string;
}

export interface SwapIn {
swap_venue: SwapVenue;
swap_operations: SwapOperation[];
swap_amount_in?: string;
}

export interface Transfer {
port: string;
channel: string;
chain_id: string;
pfm_enabled: boolean;
dest_denom: string;
}

export interface Swap {
swap_in?: SwapIn;
swap_out?: SwapExactCoinOut;
estimated_affiliate_fee?: string;
}

export interface OperationWithSwap {
swap: Swap;
transfer: never;
}

export interface OperationWithTransfer {
swap: never;
transfer: Transfer;
}

export type Operation = OperationWithSwap | OperationWithTransfer;

export function isSwapOperation(
operation: Operation
): operation is OperationWithSwap {
return operation.swap !== undefined;
}

export function isTransferOperation(
operation: Operation
): operation is OperationWithTransfer {
return operation.transfer !== undefined;
}

export interface Affiliate {
basis_points_fee: string;
address: string;
}

export interface MultiChainMsg {
chain_id: string;
path: string[];
msg: string;
msg_type_url: string;
}

0 comments on commit c3d1338

Please sign in to comment.