Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "avail-widgets",
"version": "2.0.5",
"version": "2.0.6",
"description": "A modern component registry built with Next.js and shadcn/ui for Avail Nexus",
"author": "decocereus <amartya@availproject.org>",
"contributors": [
Expand All @@ -25,7 +25,7 @@
"postinstall": "fumadocs-mdx"
},
"dependencies": {
"@avail-project/nexus-core": "2.2.4",
"@avail-project/nexus-core": "2.4.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-collapsible": "^1.1.12",
Expand Down
4 changes: 2 additions & 2 deletions packages/widgets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@avail-project/widgets",
"version": "2.0.5",
"version": "2.0.6",
"description": "Compiled Avail widgets for React applications.",
"author": "shrinathprabhu <shrinathprabhu.123@gmail.com>",
"contributors": [
Expand Down Expand Up @@ -38,7 +38,7 @@
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@avail-project/nexus-core": "2.2.4",
"@avail-project/nexus-core": "2.4.0",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-slot": "^1.2.4",
"class-variance-authority": "^0.7.1",
Expand Down
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react",
"viem"
],
Expand Down Expand Up @@ -609,7 +609,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"clsx",
"lucide-react",
"tailwind-merge",
Expand Down Expand Up @@ -807,7 +807,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react",
"viem"
],
Expand Down Expand Up @@ -1065,7 +1065,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"decimal.js",
"lucide-react",
"viem",
Expand Down Expand Up @@ -1095,7 +1095,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"wagmi"
]
},
Expand Down Expand Up @@ -1348,7 +1348,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react",
"viem"
],
Expand Down Expand Up @@ -1561,7 +1561,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react",
"viem"
],
Expand Down Expand Up @@ -1599,7 +1599,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react"
],
"registryDependencies": [
Expand Down Expand Up @@ -1752,7 +1752,7 @@
}
],
"dependencies": [
"@avail-project/nexus-core@2.2.3",
"@avail-project/nexus-core@2.2.4",
"lucide-react"
],
"registryDependencies": [
Expand Down
19 changes: 7 additions & 12 deletions registry/avail-widgets/deposit/hooks/use-deposit-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ function parseUsdAmount(value?: string): number {
return parsed;
}

function hasPositiveGasLimit(value: unknown): value is bigint {
return typeof value === "bigint" && value > BigInt(0);
}

function summarizeIntentSources(
intentSources: OnSwapIntentHookData["intent"]["sources"] | undefined,
Expand Down Expand Up @@ -526,14 +523,12 @@ export function useDepositWidget(
address,
);

if (!hasPositiveGasLimit(executeParams.gas)) {
const message =
"Deposit config executeDeposit must return a positive gas limit.";
dispatch({ type: "setError", payload: message });
dispatch({ type: "setStatus", payload: "error" });
onError?.(message);
return false;
}
const resolvedGas =
typeof executeParams?.gas === "bigint"
? executeParams.gas
: executeParams?.gas !== undefined && executeParams?.gas !== null
? BigInt(executeParams.gas)
: 1_000_000n;

const newInputs: SwapAndExecuteParams = {
toChainId: destination.chainId,
Expand All @@ -554,7 +549,7 @@ export function useDepositWidget(
spender: executeParams.tokenApproval.spender,
}
: undefined,
gas: executeParams.gas,
gas: resolvedGas,
},
};

Expand Down
4 changes: 2 additions & 2 deletions registry/avail-widgets/deposit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export interface ExecuteDepositParams {
user: Address;
}

export type ExecuteDepositResult = Omit<ExecuteParams, "toChainId"> & {
gas: bigint;
export type ExecuteDepositResult = Omit<ExecuteParams, "toChainId" | "gas"> & {
gas?: bigint;
};

export interface UseDepositWidgetProps {
Expand Down
45 changes: 44 additions & 1 deletion registry/avail-widgets/deposit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,56 @@ export function resolveDepositSourceSelection(params: {
sourceIds: sourcePoolIds,
});

const fromSources = buildSortedFromSources({
const sortedFromSources = buildSortedFromSources({
sourceIds: resolvedSelectedSourceIds,
swapBalance,
destination,
minimumBalanceUsd,
});

const destChainId = destination.chainId;
const nativeSymbol = (CHAIN_METADATA as any)[destChainId]?.nativeCurrency?.symbol?.toUpperCase();
let destGasTokenAddress: Hex = ZERO_ADDRESS as Hex;
for (const asset of swapBalance ?? []) {
for (const breakdown of asset.breakdown ?? []) {
if (breakdown.chain?.id !== destChainId) continue;
const breakdownSymbol = (
breakdown.symbol ??
asset.symbol ??
""
).toUpperCase();
const assetSymbol = (asset.symbol ?? "").toUpperCase();
const isNativeBal =
breakdown.contractAddress?.toLowerCase() === ZERO_ADDRESS ||
breakdown.contractAddress?.toLowerCase() === EVM_NATIVE_PLACEHOLDER ||
Boolean(
nativeSymbol &&
(breakdownSymbol === nativeSymbol || assetSymbol === nativeSymbol)
);
if (isNativeBal && breakdown.contractAddress) {
destGasTokenAddress =
breakdown.contractAddress.toLowerCase() === EVM_NATIVE_PLACEHOLDER
? (ZERO_ADDRESS as Hex)
: (breakdown.contractAddress as Hex);
break;
}
}
}

const hasDestGasToken = sortedFromSources.some(
(s) =>
s.chainId === destChainId &&
(s.tokenAddress.toLowerCase() === ZERO_ADDRESS ||
s.tokenAddress.toLowerCase() === EVM_NATIVE_PLACEHOLDER)
);

const fromSources = hasDestGasToken
? sortedFromSources
: [
...sortedFromSources,
{ chainId: destChainId, tokenAddress: destGasTokenAddress },
];

return {
sourcePoolIds,
selectedSourceIds: resolvedSelectedSourceIds,
Expand Down
Loading