Skip to content

Commit

Permalink
chore: converting gmp and s3 service clients to use dynamic imports a…
Browse files Browse the repository at this point in the history
…s well
  • Loading branch information
canhtrinh committed Sep 15, 2023
1 parent 30591cf commit 341324a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
6 changes: 6 additions & 0 deletions packages/transaction-recovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @axelarjs/transaction-recovery

## 0.0.14

### Patch Changes

- converting gmp and s3 service clients to use dynamic imports as well

## 0.0.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-recovery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelarjs/transaction-recovery",
"version": "0.0.13",
"version": "0.0.14",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/transaction-recovery/src/addGas/addGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { COSMOS_GAS_RECEIVER_OPTIONS, Environment } from "@axelarjs/core";
import { assertIsDeliverTxSuccess, Coin } from "@cosmjs/stargate";

import { getCosmosSigner } from "../cosmosSigner";
import { gmpClient, s3Client } from "../services";
import { getGmpClient, getS3Client } from "../services";
import { AddGasParams, AddGasResponse, GetFullFeeOptions } from "../types";

/**
Expand Down Expand Up @@ -113,16 +113,16 @@ export async function addGas({
}

async function fetchChainConfig(environment: Environment, chain: string) {
return s3Client(environment)
const s3Client = await getS3Client(environment);
return s3Client
.getChainConfigs(environment)
.then((res) => res.chains[chain] as S3CosmosChainConfig)
.catch(() => undefined);
}

async function fetchGMPTransaction(environment: Environment, txHash: string) {
const [tx] = await gmpClient(environment)
.searchGMP({ txHash })
.catch(() => []);
const gmpClient = await getGmpClient(environment);
const [tx] = await gmpClient.searchGMP({ txHash }).catch(() => []);

return tx;
}
Expand Down
26 changes: 16 additions & 10 deletions packages/transaction-recovery/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { createGMPNodeClient } from "@axelarjs/api/gmp/node";
import { createS3NodeClient } from "@axelarjs/api/s3/node";
import { AXELARSCAN_API_URLS, Environment, S3_API_URLS } from "@axelarjs/core";

export const gmpClient = (env: Environment) =>
createGMPNodeClient({
prefixUrl: AXELARSCAN_API_URLS[env],
});
export const getGmpClient = async (env: Environment) =>
typeof window === "undefined"
? (await import("@axelarjs/api/gmp/node")).createGMPNodeClient({
prefixUrl: AXELARSCAN_API_URLS[env],
})
: (await import("@axelarjs/api/gmp/browser")).createGMPBrowserClient({
prefixUrl: AXELARSCAN_API_URLS[env],
});

export const s3Client = (env: Environment) =>
createS3NodeClient({
prefixUrl: S3_API_URLS[env],
});
export const getS3Client = async (env: Environment) =>
typeof window === "undefined"
? (await import("@axelarjs/api/s3/node")).createS3NodeClient({
prefixUrl: S3_API_URLS[env],
})
: (await import("@axelarjs/api/s3/browser")).createS3BrowserClient({
prefixUrl: S3_API_URLS[env],
});

0 comments on commit 341324a

Please sign in to comment.