Skip to content

Commit

Permalink
feat: get transfer status function
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Nov 3, 2023
1 parent 8bf7067 commit 98191b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ export enum ConfigUrl {
TESTNET = 'https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json',
MAINNET = 'https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json',
}

export enum IndexerUrl {
MAINNET = 'https://api.buildwithsygma.com',
TESTNET = 'https://api.test.buildwithsygma.com',
}
2 changes: 2 additions & 0 deletions packages/sdk/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ export type Transfer<TransferType> = {
};

export type LiquidityError = Error & { maximumTransferAmount: bigint };

export type TransferStatus = 'pending' | 'executed' | 'failed';
22 changes: 21 additions & 1 deletion packages/sdk/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Environment } from './types';
import { IndexerUrl } from './constants';
import { Environment, TransferStatus } from './types';

export const DEVNET_FEE_ORACLE_BASE_URL: string = 'https://fee-oracle.develop.buildwithsygma.com/';
export const TESTNET_FEE_ORACLE_BASE_URL: string = 'https://fee-oracle.test.buildwithsygma.com/';
Expand All @@ -15,3 +16,22 @@ export function getFeeOracleBaseURL(environment?: Environment): string {
return MAINNET_FEE_ORACLE_BASE_URL;
}
}

export async function getTransferStatus(
txHash: string,
environment: Environment,
): Promise<TransferStatus> {
let url: string;

if (environment === Environment.TESTNET) {
url = IndexerUrl.TESTNET;
} else if (environment === Environment.MAINNET) {
url = IndexerUrl.MAINNET;
} else {
throw new Error('Invalid environment');
}

const response = await fetch(`${url}/transfers/txHash/${txHash}`);
const data = (await response.json()) as Record<string, unknown> & { status: TransferStatus };
return data.status;
}

0 comments on commit 98191b6

Please sign in to comment.