Skip to content

Commit

Permalink
chore: async imports (#1199)
Browse files Browse the repository at this point in the history
* chore: async imports and playground preparations

* chore: update async imports and try to minimise first import

* fix: going to definitions
  • Loading branch information
ice-chillios committed Feb 19, 2025
1 parent 97d30c6 commit f463b98
Show file tree
Hide file tree
Showing 45 changed files with 613 additions and 601 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,16 @@ jobs:
- name: Setup Repo
uses: ./tools/github/setup-repo

- name: Build
run: bun install; bun run build

- name: Lint Packages
run: |
bun --filter='./packages/toolboxes/**' lint && bun --filter='./packages/toolboxes/**' type-check
bun --filter='./packages/wallets/**' lint && bun --filter='./packages/wallets/**' type-check
bun --filter='./packages/plugins/**' lint && bun --filter='./packages/plugins/**' type-check
bun --filter='./packages/swapkit/**' lint && bun --filter='./packages/swapkit/**' type-check
- run: bun build:ci
- run: bun lint:ci

- name: Lint Playgrounds
continue-on-error: true
run: bun --filter='./playgrounds/**' lint && bun --filter='./playgrounds/**' type-check

- name: Test
if: contains(github.ref_name, 'nightly') == false
run: bun run test
run: bun test:ci

publish:
if: contains(github.ref_name, 'develop') || contains(github.ref_name, 'nightly') || contains(github.ref_name, 'beta')
Expand All @@ -58,15 +51,15 @@ jobs:

- name: Change nightly changeset
if: contains(github.ref_name, 'nightly')
continue-on-error: true
run: |
bun changeset version --snapshot nightly
- name: Change beta changeset
if: contains(github.ref_name, 'beta')
continue-on-error: true
run: |
echo 'publishName="Beta"' >> $GITHUB_OUTPUT
bun changeset pre enter beta
bun changeset version
- name: Set job params
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:
container:
image: returntocorp/semgrep:sha-b396800
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: semgrep ci --config p/ci --config p/xss --config p/jwt --config p/r2c --config p/react --config p/r2c-ci --config p/secrets --config p/javascript --config p/clientside-js --config p/owasp-top-ten --config p/security-audit --config p/github-actions --max-lines-per-finding 0 --force-color
192 changes: 175 additions & 17 deletions bun.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
"scripts": {
"bootstrap": "bun clean; bun install --force; bun run build",
"build": "bun --filter '*' --elide-lines=100 build",
"build:ci": "bun --filter '*' build",
"build:debug": "DEBUG=true bun --filter '*' build",
"clean": "bun --filter '*' clean && rm -rf node_modules; bun install",
"deps": "bun ncu --root -u -i -ws",
"generate:tokens": "bun --filter '@swapkit/helpers' build; bun --cwd packages/helpers generate-tokens; bun lint",
"lint": "bun --filter '*' --elide-lines=100 lint",
"lint:ci": "bun lint && bun type-check",
"lint:ci": "bun --filter '*' lint && bun --filter '*' type-check",
"lint:ws": "bun x sherif@latest",
"playground:next": "bun --cwd ./playgrounds/nextjs",
"playground:node": "bun --cwd ./playgrounds/node",
"playground:vite": "bun --cwd ./playgrounds/vite",
"postinstall": "lefthook install; bun lint:ws",
"publish-packages": "bun run build && bun version-bump && bun changeset publish",
"test": "bun --filter '*' --elide-lines=1000 test",
"test:coverage": "bun --filter '*' test:coverage",
"test:ci": "bun --filter '*' test:ci",
"type-check": "bun --filter '*' --elide-lines=100 type-check",
"version-bump": "bun changeset version"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clean": "rm -rf dist node_modules *.tsbuildinfo",
"lint": "biome check --write ./src",
"test": "echo 'bun test'",
"test:coverage": "bun test --coverage",
"test:ci": "bun test --coverage",
"type-check": "tsc --noEmit"
},
"type": "module",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/helpers/walletAddressValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export async function getAddressValidator() {
const { evmValidateAddress } = await import("@swapkit/toolboxes/evm");
const { substrateValidateAddress } = await import("@swapkit/toolboxes/substrate");
const { utxoValidateAddress } = await import("@swapkit/toolboxes/utxo");
const { validateAddress: solanaValidateAddress } = await import("@swapkit/toolboxes/solana");
const { getAddressValidator: getSolValidator } = await import("@swapkit/toolboxes/solana");
const { validateAddress: validateRadixAddress } = await import("@swapkit/toolboxes/radix");

const solanaValidateAddress = await getSolValidator();

return function validateAddress({ address, chain }: { address: string; chain: Chain }) {
switch (chain) {
case Chain.Arbitrum:
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"lint": "biome check --write ./src",
"generate-tokens": "bun --bun ./fetchTokenLists.ts",
"test": "bun test",
"test:coverage": "bun test --coverage",
"test:ci": "bun test --coverage",
"type-check": "tsc --noEmit"
},
"type": "module",
Expand Down
56 changes: 19 additions & 37 deletions packages/helpers/src/modules/assetValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,44 +167,26 @@ or by passing asyncTokenLookup: true to the from() function, which will make it
return assetValue as ConditionalAssetValueReturn<T>;
}

static loadStaticAssets() {
return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
(resolve, reject) => {
try {
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor
import("@swapkit/helpers/tokens").then((tokenPackage) => {
if (!tokenPackage.tokenLists) {
console.warn(
"No token lists found in @swapkit/tokens package. Ensure you have installed it correctly.",
);
return;
}

for (const tokenList of Object.values(tokenPackage.tokenLists)) {
for (const { identifier, chain, ...rest } of tokenList.tokens) {
staticTokensMap.set(
chain === "SOL" ? identifier : (identifier.toUpperCase() as TokenNames),
{
identifier,
decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain as Chain],
},
);
}
}

resolve({ ok: true });
});
} catch (error) {
console.error(error);
reject({
ok: false,
error,
message:
"Couldn't load static assets. Ensure you have installed @swapkit/tokens package",
});
static async loadStaticAssets() {
try {
await import("@swapkit/helpers/tokens").then(({ tokenLists }) => {
for (const { tokens } of Object.values(tokenLists)) {
for (const { identifier, chain, ...rest } of tokens) {
staticTokensMap.set(
chain === "SOL" ? identifier : (identifier.toUpperCase() as TokenNames),
{
identifier,
decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain as Chain],
},
);
}
}
},
);
});
return true;
} catch (error) {
console.error(error);
return false;
}
}
}

Expand Down
13 changes: 0 additions & 13 deletions packages/helpers/src/tokens/helpers.ts

This file was deleted.

17 changes: 15 additions & 2 deletions packages/helpers/src/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
export * as tokenLists from "./lists";
export * from "./helpers";
import * as tokenLists from "./lists";

export function getTokenIcon(identifier: string): string | undefined {
// Search through all lists for a matching token
for (const list of Object.values(tokenLists)) {
const token = list.tokens.find((token) => token.identifier === identifier);
if (token?.logoURI) {
return token.logoURI;
}
}

return undefined;
}

export { tokenLists };
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"clean": "rm -rf dist node_modules *.tsbuildinfo",
"lint": "biome check --write ./src",
"test": "echo 'bun test'",
"test:coverage": "bun test --coverage",
"test:ci": "bun test --coverage",
"type-check": "tsc --noEmit"
},
"type": "module",
Expand Down
20 changes: 0 additions & 20 deletions packages/plugins/src/chainflip/broker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Assets, Chains } from "@chainflip/sdk/swap";
import { decodeAddress } from "@polkadot/keyring";
import { isHex, u8aToHex } from "@polkadot/util";
import { AssetValue, Chain, SwapKitError, wrapWithThrow } from "@swapkit/helpers";
Expand All @@ -8,25 +7,6 @@ import type { ChainflipToolbox } from "@swapkit/toolboxes/substrate";

import type { WithdrawFeeResponse } from "./types";

export const chainToChainflipChain = new Map<Chain, keyof typeof Chains>([
[Chain.Arbitrum, Chains.Arbitrum],
[Chain.Bitcoin, Chains.Bitcoin],
[Chain.Ethereum, Chains.Ethereum],
[Chain.Polkadot, Chains.Polkadot],
[Chain.Solana, Chains.Solana],
[Chain.Polkadot, Chains.Polkadot],
]);

export const assetTickerToChainflipAsset = new Map<string, keyof typeof Assets>([
["FLIP", Assets.FLIP],
["BTC", Assets.BTC],
["ETH", Assets.ETH],
["USDC", Assets.USDC],
["USDT", Assets.USDT],
["DOT", Assets.DOT],
["SOL", Assets.SOL],
]);

export const assetIdentifierToChainflipTicker = new Map<string, string>([
["ARB.ETH", "ArbEth"],
["ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831", "ArbUsdc"],
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"author": "swapkit-oss",
"dependencies": {
"@swapkit/core": "workspace:*",
"@swapkit/helpers": "workspace:*",
"@swapkit/plugins": "workspace:*",
"@swapkit/wallets": "workspace:*"
},
Expand Down
Loading

0 comments on commit f463b98

Please sign in to comment.