Skip to content

Commit

Permalink
chore: updating function implementation, adding explorer urls as cons…
Browse files Browse the repository at this point in the history
…tants
  • Loading branch information
wainola committed Nov 4, 2023
1 parent 1045243 commit fe0c188
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@changesets/cli": "^2.14.1",
"ethers": "5.4.5"
"ethers": "5.6.2"
},
"devDependencies": {
"@chainsafe/eslint-config": "^1.1.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export enum IndexerUrl {
MAINNET = 'https://api.buildwithsygma.com',
TESTNET = 'https://api.test.buildwithsygma.com',
}

export enum ExplorerUrl {
MAINNET = 'https://scan.buildwithsygma.com',
TESTNET = 'https://scan.test.buildwithsygma.com',
}
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './chains/index.js';
export * from './config.js';
export * from './constants.js';
export * from './types/index.js';
export { getTransferStatusData } from './utils.js';
5 changes: 5 additions & 0 deletions packages/sdk/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ export type Transfer<TransferType> = {
export type LiquidityError = Error & { maximumTransferAmount: bigint };

export type TransferStatus = 'pending' | 'executed' | 'failed';

export type TransferStatusResponse = {
status: TransferStatus;
explorerUrl: string;
};
30 changes: 19 additions & 11 deletions packages/sdk/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IndexerUrl } from './constants';
import { Environment, TransferStatus } from './types';
import { IndexerUrl, ExplorerUrl } from './constants';
import { Environment, TransferStatus, TransferStatusResponse } 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 @@ -18,26 +18,34 @@ export function getFeeOracleBaseURL(environment?: Environment): string {
}

/**
* @@description Get the status of a transfer using transaction hash and optionally domain id
* @@description Get the status of a transfer using transaction hash and optionally domain id
*/
export async function getTransferStatus(
export async function getTransferStatusData(
environment: Environment,
txHash: string,
domainId?: string,
): Promise<TransferStatus> {
): Promise<TransferStatusResponse> {
let url: string;
let explorerUrl: string;

if (environment === Environment.TESTNET) {
url = IndexerUrl.TESTNET;
url = `${IndexerUrl.TESTNET}/api/transfers/txHash/${txHash}${
domainId ? `?domainId=${domainId}` : ''
}`;
explorerUrl = `${ExplorerUrl.TESTNET}/transfer/${txHash}`;
} else if (environment === Environment.MAINNET) {
url = IndexerUrl.MAINNET;
url = `${IndexerUrl.MAINNET}/api/transfers/txHash/${txHash}${
domainId ? `?domainId=${domainId}` : ''
}`;
explorerUrl = `${ExplorerUrl.MAINNET}/transfer/${txHash}`;
} else {
throw new Error('Invalid environment');
}

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

0 comments on commit fe0c188

Please sign in to comment.