Skip to content

Commit

Permalink
chore: update @oraichain/common to version 1.2.1-beta3 and refactor t…
Browse files Browse the repository at this point in the history
…oken service
  • Loading branch information
vuonghuuhung committed Nov 28, 2024
1 parent 1edeb09 commit ce824d1
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/oraidex-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@oraichain/oraidex-contracts-sdk": "latest",
"@injectivelabs/sdk-ts": "1.12.1",
"tronweb": "6.0.0-beta.4",
"@oraichain/common": "1.1.5-beta.2"
"@oraichain/common": "^1.2.1-beta3"
},
"devDependencies": {},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions packages/oraidex-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from "./axios-request";
export * from "./celestia-network";
export * from "./config";
export * from "./supported";
export * from "./test";
2 changes: 0 additions & 2 deletions packages/oraidex-common/src/supported/supported-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const readSupportedChainInfoStatic = async () => {
await fetchRetry(`${ORAIDEX_API_ENDPOINTS.BASE_URL}${ORAIDEX_API_ENDPOINTS.SUPPORTED_INFO}`, options)
).json();

console.log("supportedChainInfo", supportedChainInfo);

if (!supportedChainInfo) {
return oraidexJson;
}
Expand Down
140 changes: 88 additions & 52 deletions packages/oraidex-common/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,88 @@
const fetchRetry = async (url, options?: any) => {
let retry = options?.retry ?? 3;
const { callback, timeout = 30000, ...init } = options || {};
init.signal = AbortSignal.timeout(timeout);
while (retry > 0) {
try {
return await fetch(url, init);
} catch (e) {
callback?.(retry);
retry--;
if (retry === 0) {
throw e;
}
}
}
};

const ORAICHAIN_COMMON_GITHUB_API_ENDPOINTS = {
BASE_URL: "https://raw.githubusercontent.com/oraidex/oraidex-sdk",
// SUPPORTED_INFO: "/oraidex/oraidex-sdk/main/packages/oraidex-common/src/supported/config/"
SUPPORTED_INFO: "/packages/oraidex-common/src/supported/config/"
};

const readSupportedChainInfoStatic = async () => {
const options = {
method: "GET",
headers: {
Accept: "application/json"
}
};
console.log(
"requesting . . .",
`${ORAICHAIN_COMMON_GITHUB_API_ENDPOINTS.BASE_URL}${"/feat/intergrate_common"}${
ORAICHAIN_COMMON_GITHUB_API_ENDPOINTS.SUPPORTED_INFO
}${"oraidex.json"}`
);

const supportedChainInfo = await (
await fetchRetry(
`${ORAICHAIN_COMMON_GITHUB_API_ENDPOINTS.BASE_URL}${"/feat/intergrate_common"}${
ORAICHAIN_COMMON_GITHUB_API_ENDPOINTS.SUPPORTED_INFO
}${"oraidex.json"}`,
options
)
).json();

console.log("supportedChainInfo", supportedChainInfo);

return supportedChainInfo;
};

readSupportedChainInfoStatic();
import { ChainInfos, OraiCommon, TokenItems } from "@oraichain/common";
import { flatten } from "lodash";
import { mapListWithIcon, tokensIcon } from "./config";

export class TokenService {
constructor(private readonly tokenConfig: TokenItems, private readonly chainConfig: ChainInfos) {}

static async load(): Promise<TokenService> {
const oraiCommon = await OraiCommon.initializeFromBackend("https://oraicommon-staging.oraidex.io", "oraidex");
return new TokenService(oraiCommon.tokenItems, oraiCommon.chainInfos);
}

get oraichainTokens() {
return this.tokenConfig.oraichainTokens;
}

get otherChainTokens() {
return this.tokenConfig.otherChainTokens;
}

get chainInfosCommon() {
return this.chainConfig;
}

get tokens() {
return this.tokenConfig.tokens;
}

get flattenTokens() {
return this.tokenConfig.flattenTokens;
}

get tokenMap() {
return this.tokenConfig.tokenMap;
}

get assetInfoMap() {
return this.tokenConfig.assetInfoMap;
}

get cosmosTokens() {
return this.tokenConfig.cosmosTokens;
}

get cw20Tokens() {
return this.tokenConfig.cw20Tokens;
}

get cw20TokenMap() {
return this.tokenConfig.cw20TokenMap;
}

get evmTokens() {
return this.tokenConfig.evmTokens;
}

get kawaiiTokens() {
return this.tokenConfig.kawaiiTokens;
}

get oraichainTokensWithIcon() {
return mapListWithIcon(this.oraichainTokens, tokensIcon, "coinGeckoId");
}

get otherTokensWithIcon() {
return mapListWithIcon(this.otherChainTokens, tokensIcon, "coinGeckoId");
}

get tokensWithIcon() {
return [this.otherTokensWithIcon, this.oraichainTokensWithIcon];
}

get flattenTokensWithIcon() {
return flatten(this.tokensWithIcon);
}
}

// const main = async () => {
// const tokenService = await TokenService.load();
// };

// main()
// .then(() => {
// console.log("Done");
// })
// .catch((error) => {
// console.error(error);
// });
5 changes: 2 additions & 3 deletions packages/oraidex-common/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const initOraiCommon = async () => {
if (isInitial) {
oraiCommon = await OraiCommon.initializeFromBackend();

console.log("oraiCommon", oraiCommon);
const tokenListSupports = await readSupportedChainInfoStatic();

const tokenInfos = [];
Expand Down Expand Up @@ -133,12 +132,12 @@ export const initOraiCommon = async () => {

return { tokenConfig, oraiCommon };
};
await initOraiCommon();
// await initOraiCommon();

// other chains, oraichain
export const oraichainTokens = tokenConfig.oraichainTokens;
export const otherChainTokens = tokenConfig.otherChainTokens;
export const chainInfosCommon = oraiCommon.chainInfos;
export const chainInfosCommon = oraiCommon?.chainInfos;
export const tokens = [otherChainTokens, oraichainTokens];
export const flattenTokens = flatten(tokens);
export const tokenMap = Object.fromEntries(flattenTokens.map((c) => [c.denom, c]));
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3757,6 +3757,19 @@
ethers "^5.5.1"
lodash "^4.17.21"

"@oraichain/common@^1.2.1-beta3":
version "1.2.1-beta3"
resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.1-beta3.tgz#11bc4ea0b87395121af5bd932ffa0bf0b63122ac"
integrity sha512-OKbEhSs9iuEpxqq7mRzeaGDaVUWJ6nkyg/2IjrddQ/kiMEZoCr+xaVOLlf4tUQ6IFKWf4ViSaWpfduJvptaH2w==
dependencies:
"@keplr-wallet/types" "0.12.141"
axios "0.21.4"
axios-extensions "3.1.6"
bech32 "^1.1.4"
cosmjs-types "^0.8.0"
ethers "^5.5.1"
lodash "^4.17.21"

"@oraichain/cosmwasm-vm-js@^0.2.82":
version "0.2.82"
resolved "https://registry.yarnpkg.com/@oraichain/cosmwasm-vm-js/-/cosmwasm-vm-js-0.2.82.tgz#3744951e64f57ca12925dccbd3e62f19d0d0932e"
Expand Down

0 comments on commit ce824d1

Please sign in to comment.