Skip to content

Commit

Permalink
feat: core plugin approve handling (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
towanTG committed May 6, 2024
1 parent 547e4b2 commit acf1100
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-rules-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@swapkit/helpers": patch
"@swapkit/core": patch
---

Fixes core plugin approval handling
14 changes: 12 additions & 2 deletions packages/swapkit/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,18 @@ export function SwapKit<
}) {
const plugin = availablePlugins[spenderAddress];

if (plugin && "approve" in plugin) {
return plugin.approve({ assetValue, type }) as ApproveReturnType<T>;
if (plugin) {
if (type === ApproveMode.CheckOnly && "isAssetValueApproved" in plugin) {
return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;
}
if (type === ApproveMode.Approve && "approveAssetValue" in plugin) {
return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;
}

throw new SwapKitError(
"core_approve_asset_target_invalid",
`Target ${String(spenderAddress)} cannot be used for approve operation`,
);
}

const { address, chain, isGasAsset, isSynthetic } = assetValue;
Expand Down
1 change: 1 addition & 0 deletions packages/swapkit/helpers/src/modules/swapKitError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const errorMessages = {
core_approve_asset_address_or_from_not_found: 10005,
core_plugin_not_found: 10006,
core_plugin_swap_not_found: 10007,
core_approve_asset_target_invalid: 10008,
core_chain_halted: 10099,

/**
Expand Down

0 comments on commit acf1100

Please sign in to comment.