Skip to content

Commit

Permalink
[Add] Extension - Intergrate Simple Swap]
Browse files Browse the repository at this point in the history
  • Loading branch information
tunghp2002 committed Nov 26, 2024
1 parent 2bf7bb2 commit a7098b4
Show file tree
Hide file tree
Showing 15 changed files with 508 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ BITTENSOR_API_KEY_3=abafdbad3
BITTENSOR_API_KEY_4=abafdbad4
BITTENSOR_API_KEY_5=abafdbad5
BITTENSOR_API_KEY_6=abafdbad6
SIMPLE_SWAP_API_KEY=abacasdf
1 change: 1 addition & 0 deletions .github/workflows/push-koni-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
BITTENSOR_API_KEY_4: ${{ secrets.BITTENSOR_API_KEY_4 }}
BITTENSOR_API_KEY_5: ${{ secrets.BITTENSOR_API_KEY_5 }}
BITTENSOR_API_KEY_6: ${{ secrets.BITTENSOR_API_KEY_6 }}
SIMPLE_SWAP_API_KEY: ${{ secrets.SIMPLE_SWAP_API_KEY }}
GH_RELEASE_FILES: master-build.zip,master-src.zip
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
REF_NAME: ${{ github.ref_name }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
BITTENSOR_API_KEY_4: ${{ secrets.BITTENSOR_API_KEY_4 }}
BITTENSOR_API_KEY_5: ${{ secrets.BITTENSOR_API_KEY_5 }}
BITTENSOR_API_KEY_6: ${{ secrets.BITTENSOR_API_KEY_6 }}
SIMPLE_SWAP_API_KEY: ${{ secrets.SIMPLE_SWAP_API_KEY }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-web-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
BITTENSOR_API_KEY_4: ${{ secrets.BITTENSOR_API_KEY_4 }}
BITTENSOR_API_KEY_5: ${{ secrets.BITTENSOR_API_KEY_5 }}
BITTENSOR_API_KEY_6: ${{ secrets.BITTENSOR_API_KEY_6 }}
SIMPLE_SWAP_API_KEY: ${{ secrets.SIMPLE_SWAP_API_KEY }}
BRANCH_NAME: master
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-webapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
CHAINFLIP_BROKER_API: ${{ secrets.CHAINFLIP_BROKER_API }}
BITTENSOR_API_KEY_1: ${{ secrets.BITTENSOR_API_KEY_1 }}
BITTENSOR_API_KEY_2: ${{ secrets.BITTENSOR_API_KEY_2 }}
SIMPLE_SWAP_API_KEY: ${{ secrets.SIMPLE_SWAP_API_KEY }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
29 changes: 28 additions & 1 deletion packages/extension-base/src/core/logic-validation/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SwapError } from '@subwallet/extension-base/background/errors/SwapError
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
import { _getAssetDecimals, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
import { BasicTxErrorType } from '@subwallet/extension-base/types';
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SimpleSwapValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
import { formatNumber } from '@subwallet/extension-base/utils';
import BigN from 'bignumber.js';

Expand Down Expand Up @@ -163,3 +163,30 @@ export function _getEarlyAssetHubValidationError (error: SwapErrorType, metadata
return new SwapError(error);
}
}

export function _getSimpleSwapEarlyValidationError (error: SwapErrorType, metadata: SimpleSwapValidationMetadata): SwapError { // todo: support more providers
switch (error) {
case SwapErrorType.NOT_MEET_MIN_SWAP: {
const message = `Amount too low. Increase your amount above ${metadata.minSwap.value} ${metadata.minSwap.symbol} and try again`;

return new SwapError(error, message);
}

case SwapErrorType.SWAP_EXCEED_ALLOWANCE: {
if (metadata.maxSwap) {
return new SwapError(error, `Amount too high. Lower your amount below ${metadata.maxSwap.value} ${metadata.maxSwap.symbol} and try again`);
} else {
return new SwapError(error, 'Amount too high. Lower your amount and try again');
}
}

case SwapErrorType.ASSET_NOT_SUPPORTED:
return new SwapError(error, 'This swap pair is not supported');
case SwapErrorType.UNKNOWN:
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
case SwapErrorType.ERROR_FETCHING_QUOTE:
return new SwapError(error, 'No swap quote found. Adjust your amount or try again later.');
default:
return new SwapError(error);
}
}
Loading

0 comments on commit a7098b4

Please sign in to comment.