From 9d5985bd18c782a9c7e18f29a7db80332ad5ab97 Mon Sep 17 00:00:00 2001 From: Anni Piragauta Date: Tue, 15 Oct 2024 11:24:26 -0500 Subject: [PATCH] refactor: remove max limits and max button, get available liquidity --- .env.local.test | 1 - .github/workflows/deploy_MainNet_UI.yml | 2 - .github/workflows/deploy_TestNet_UI.yml | 2 - .../workflows/deploy_staging_MainNet_UI.yml | 2 - .../workflows/deploy_staging_TestNet_UI.yml | 2 - ENV_VARIABLES.md | 3 -- src/common/services/BridgeService.ts | 6 +-- src/common/services/FlyoverService.ts | 11 ++++- src/common/services/WalletService.ts | 9 +--- src/common/store/constants.ts | 4 +- src/common/types/Flyover/Flyover.ts | 1 + src/common/types/environment-variables.ts | 12 ------ src/common/types/pegInTx.ts | 1 - src/common/types/pegOutTx.ts | 1 - src/common/utils/common.ts | 2 - src/main.ts | 2 - .../components/create/BtcInputAmount.vue | 43 +++---------------- .../services/peginConfigurationService.ts | 2 - src/pegin/store/FlyoverPegin/actions.ts | 28 +++++++++++- src/pegin/store/FlyoverPegin/mutations.ts | 9 ++++ src/pegin/store/PeginTx/actions.ts | 5 +-- src/pegin/store/PeginTx/getters.ts | 4 +- .../components/FlyoverRbtcInputAmount.vue | 33 +++----------- src/pegout/components/RbtcInputAmount.vue | 8 +--- src/pegout/store/FlyoverPegout/getters.ts | 1 - src/pegout/store/pegoutTx/actions.ts | 2 - src/pegout/store/pegoutTx/getters.ts | 3 +- 27 files changed, 65 insertions(+), 134 deletions(-) diff --git a/.env.local.test b/.env.local.test index 6fb1c22b6..4a10b919a 100644 --- a/.env.local.test +++ b/.env.local.test @@ -11,7 +11,6 @@ VUE_APP_RSK_EXPLORER=https://explorer.testnet.rsk.co/ # replace VALUE with the clarity id for the environment the app is being deployed to. VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.005 -VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 #VUE_APP_CLARITY_ID=VALUE ## fee boundaries diff --git a/.github/workflows/deploy_MainNet_UI.yml b/.github/workflows/deploy_MainNet_UI.yml index 26f3073ee..b92fdb9a7 100644 --- a/.github/workflows/deploy_MainNet_UI.yml +++ b/.github/workflows/deploy_MainNet_UI.yml @@ -45,9 +45,7 @@ jobs: VUE_APP_WALLET_ADDRESSES_HARD_STOP=100 VUE_APP_WALLET_ADDRESS_PER_CALL=20 VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004 - VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005 - VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10 VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612' npm run-script build diff --git a/.github/workflows/deploy_TestNet_UI.yml b/.github/workflows/deploy_TestNet_UI.yml index 818fe5f25..fbe25ba81 100644 --- a/.github/workflows/deploy_TestNet_UI.yml +++ b/.github/workflows/deploy_TestNet_UI.yml @@ -45,9 +45,7 @@ jobs: VUE_APP_WALLET_ADDRESSES_HARD_STOP=100 VUE_APP_WALLET_ADDRESS_PER_CALL=20 VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004 - VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005 - VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10 VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300' npm run-script build diff --git a/.github/workflows/deploy_staging_MainNet_UI.yml b/.github/workflows/deploy_staging_MainNet_UI.yml index 64b4330bc..a8f95067c 100644 --- a/.github/workflows/deploy_staging_MainNet_UI.yml +++ b/.github/workflows/deploy_staging_MainNet_UI.yml @@ -45,9 +45,7 @@ jobs: VUE_APP_WALLET_ADDRESSES_HARD_STOP=100 VUE_APP_WALLET_ADDRESS_PER_CALL=20 VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004 - VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005 - VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10 VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612' npm run-script build diff --git a/.github/workflows/deploy_staging_TestNet_UI.yml b/.github/workflows/deploy_staging_TestNet_UI.yml index ed0ac4c48..130ca0e89 100644 --- a/.github/workflows/deploy_staging_TestNet_UI.yml +++ b/.github/workflows/deploy_staging_TestNet_UI.yml @@ -45,9 +45,7 @@ jobs: VUE_APP_WALLET_ADDRESSES_HARD_STOP=100 VUE_APP_WALLET_ADDRESS_PER_CALL=20 VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004 - VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005 - VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10 VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300' npm run-script build diff --git a/ENV_VARIABLES.md b/ENV_VARIABLES.md index ba7e097a8..e17ee9a82 100644 --- a/ENV_VARIABLES.md +++ b/ENV_VARIABLES.md @@ -14,9 +14,7 @@ The value of these variables are used in **environment-variables.ts** file. |VUE_APP_WALLET_ADDRESSES_HARD_STOP | `100` | Maximum number of addresses derived from wallet | |VUE_APP_WALLET_ADDRESS_PER_CALL | `5` | Number of addresses obtained per derivation call | |VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC | `0.004` | 0,004 Minimum allowed value for a PEGOUT transaction | -|VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC | `10` | 10 Maximum allowed value for a PEGOUT transaction | |VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC | `0.005` | Minimum allowed value for a PEGIN transaction | -|VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC | `10` | Maximum allowed value for a PEGIN transaction | |VUE_APP_BURN_DUST_VALUE | `30000` | Max value to burn in the tx fee | |VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST | `8` | Min fee rate (sats/byte) required to broadcast the transaction | |VUE_APP_MIN_FEE_SAT_PER_BYTE_AVG | `4` | Min fee rate (sats/byte) required to broadcast the transaction | @@ -38,7 +36,6 @@ VUE_APP_RSK_EXPLORER=https://explorer.testnet.rootstock.io/ VUE_APP_WALLET_ADDRESSES_HARD_STOP=100 VUE_APP_WALLET_ADDRESS_PER_CALL=5 VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.005 -VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10 VUE_APP_BURN_DUST_VALUE=30000 VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST=8 VUE_APP_MIN_FEE_SAT_PER_BYTE_AVG=4 diff --git a/src/common/services/BridgeService.ts b/src/common/services/BridgeService.ts index a3bd7e4a3..0a70db219 100644 --- a/src/common/services/BridgeService.ts +++ b/src/common/services/BridgeService.ts @@ -72,11 +72,7 @@ export class BridgeService { const rbtcInCirculationToSatoshis = Math.round(rbtcInCirculation / 1e10); let availability = lockingCap - rbtcInCirculationToSatoshis; availability = availability > 0 ? availability : 0; - const maxAllowed = EnvironmentAccessorService.getEnvironmentVariables() - .maxAmountAllowedInSatoshis ? Number(EnvironmentAccessorService - .getEnvironmentVariables().maxAmountAllowedInSatoshis) - : Infinity; - resolve(Math.min(availability, maxAllowed)); + resolve(availability); }) .catch((reason) => { reject(reason); diff --git a/src/common/services/FlyoverService.ts b/src/common/services/FlyoverService.ts index 8b909f853..ca0745dc6 100644 --- a/src/common/services/FlyoverService.ts +++ b/src/common/services/FlyoverService.ts @@ -33,6 +33,8 @@ export default class FlyoverService { private token = ''; + private liquidityProviderIdUsed = -1; + constructor(providerUrl?: string) { this.providerUrl = providerUrl; const appNetwork = EnvironmentAccessorService.getEnvironmentVariables().vueAppCoin; @@ -128,6 +130,7 @@ export default class FlyoverService { const provider = this.liquidityProviders.find((p: LiquidityProvider) => p.id === providerId); if (provider) { this.flyover?.useLiquidityProvider(provider); + this.liquidityProviderIdUsed = providerId; } } @@ -434,13 +437,17 @@ export default class FlyoverService { }); } - public getAvailableLiquidity(): Promise<{peginLiquidity: WeiBig, pegoutLiquidity: SatoshiBig}> { + public getAvailableLiquidity(): Promise<{ + providerId: number, + peginLiquidity: WeiBig, + pegoutLiquidity: SatoshiBig, + }> { return new Promise((resolve, reject) => { this.flyover?.getAvailableLiquidity() .then(({ peginLiquidityAmount, pegoutLiquidityAmount }) => { const peginLiquidity = new WeiBig(peginLiquidityAmount, 'wei'); const pegoutLiquidity = new SatoshiBig(pegoutLiquidityAmount, 'satoshi'); - resolve({ peginLiquidity, pegoutLiquidity }); + resolve({ providerId: this.liquidityProviderIdUsed, peginLiquidity, pegoutLiquidity }); }) .catch((error) => { reject(new ServiceError( diff --git a/src/common/services/WalletService.ts b/src/common/services/WalletService.ts index 39169541b..a20ae3072 100644 --- a/src/common/services/WalletService.ts +++ b/src/common/services/WalletService.ts @@ -185,7 +185,7 @@ export default abstract class WalletService { return (this.subscribers.length > 0); } - public async startAskingForBalance(sessionId: string, maxAmountPegin: number): Promise { + public async startAskingForBalance(): Promise { this.balanceAccumulated = { legacy: new SatoshiBig(0, 'satoshi'), segwit: new SatoshiBig(0, 'satoshi'), @@ -208,13 +208,6 @@ export default abstract class WalletService { while (this.hasSubscribers() && !this.areEnoughUnusedAddresses()) { // eslint-disable-next-line no-await-in-loop await this.askForBalance(); - const maxAmountPeginCompare = new SatoshiBig(maxAmountPegin, 'satoshi'); - if (this.balanceAccumulated.legacy.gte(maxAmountPeginCompare) - && this.balanceAccumulated.segwit.gte(maxAmountPeginCompare) - && this.balanceAccumulated.nativeSegwit.gte(maxAmountPeginCompare) - ) { - break; - } this.setAddressesToFetch(); const maxIndexReached = Math.max( this.addressesToFetch.legacy.lastIndex, diff --git a/src/common/store/constants.ts b/src/common/store/constants.ts index 3c33d12bb..771743cf6 100644 --- a/src/common/store/constants.ts +++ b/src/common/store/constants.ts @@ -86,7 +86,6 @@ export const FLYOVER_PEGOUT_CLEAR_QUOTE_DIFFERENCES = 'FLYOVER_PEGOUT_CLEAR_QUOT export const VIEW_ADD_CURRENT_VIEW = 'VIEW_ADD_CURRENT_VIEW'; // Flyover PegIn actions - export const FLYOVER_PEGIN_INIT = 'FLYOVER_PEGIN_INIT'; export const FLYOVER_PEGIN_GET_PROVIDERS = 'FLYOVER_PEGIN_GET_PROVIDERS'; export const FLYOVER_PEGIN_ADD_AMOUNT = 'FLYOVER_PEGIN_ADD_AMOUNT'; @@ -95,6 +94,7 @@ export const FLYOVER_PEGIN_USE_LIQUIDITY_PROVIDER = 'FLYOVER_PEGIN_USE_LIQUIDITY export const FLYOVER_PEGIN_GET_QUOTES = 'FLYOVER_PEGIN_GET_QUOTES'; export const FLYOVER_PEGIN_ADD_SELECTED_QUOTE = 'FLYOVER_PEGIN_ADD_SELECTED_QUOTE'; export const FLYOVER_PEGIN_CLEAR_QUOTES = 'FLYOVER_PEGIN_CLEAR_QUOTES'; +export const FLYOVER_PEGIN_GET_AVAILABLE_LIQUIDITY = 'FLYOVER_PEGIN_GET_AVAILABLE_LIQUIDITY'; // Hardcoded address for Leather wallet FYI the bridge requires a // BTC address but is not really used during PEGIN-FLYOVER process. export const VALID_ADDRESS_UNUSED_BY_FLYOVER = { @@ -170,12 +170,12 @@ export const FLYOVER_PEGOUT_SET_QUOTES_DIFFERENCES = 'FLYOVER_PEGOUT_SET_QUOTES_ export const VIEW_SET_CURRENT_VIEW = 'VIEW_SET_CURRENT_VIEW'; // Flyover PegIn mutations - export const FLYOVER_PEGIN_SET_PROVIDERS = 'FLYOVER_PEGIN_SET_PROVIDERS'; export const FLYOVER_PEGIN_SET_AMOUNT = 'FLYOVER_PEGIN_SET_AMOUNT'; export const FLYOVER_PEGIN_SET_ROOTSTOCK_ADDRESS = 'FLYOVER_PEGIN_SET_ROOTSTOCK_ADDRESS'; export const FLYOVER_PEGIN_SET_QUOTES = 'FLYOVER_PEGIN_SET_QUOTES'; export const FLYOVER_PEGIN_SET_SELECTED_QUOTE = 'FLYOVER_PEGIN_SET_SELECTED_QUOTE'; +export const FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY = 'FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY'; // Session mutations export const SESSION_SET_ACCOUNT = 'SESSION_SET_ACCOUNT'; diff --git a/src/common/types/Flyover/Flyover.ts b/src/common/types/Flyover/Flyover.ts index ea031cbfb..1069d0d4d 100644 --- a/src/common/types/Flyover/Flyover.ts +++ b/src/common/types/Flyover/Flyover.ts @@ -7,6 +7,7 @@ interface PeginProviderDetail { maxTransactionValue: SatoshiBig; minTransactionValue: SatoshiBig; requiredConfirmations: number; + availableLiquidity?: SatoshiBig; } interface PegoutProviderDetail { fee: WeiBig; diff --git a/src/common/types/environment-variables.ts b/src/common/types/environment-variables.ts index 538c8ce5c..3e21ffbc0 100644 --- a/src/common/types/environment-variables.ts +++ b/src/common/types/environment-variables.ts @@ -25,8 +25,6 @@ export class EnvironmentVariables { public pegoutMinValue: number; - public pegoutMaxValue: number; - public debugMode: boolean; public minFeeSatPerByte: { @@ -43,14 +41,10 @@ export class EnvironmentVariables { public burnDustValue: number; - public maxAmountAllowedInSatoshis: number; - public lbcAddress: string; public peginMinAmountAllowedInBtc: number; - public peginMaxAmountAllowedInBtc: number; - // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(defaultValues: any = {}) { this.vueAppCoin = process.env.VUE_APP_COIN || defaultValues.vueAppCoin; @@ -72,8 +66,6 @@ export class EnvironmentVariables { this.vueAppClarityId = process.env.VUE_APP_CLARITY_ID || defaultValues.vueAppClarityId; this.pegoutMinValue = process.env.VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC || defaultValues.pegoutMinValue; - this.pegoutMaxValue = process.env.VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC - || defaultValues.pegoutMaxValue; this.minFeeSatPerByte = { fast: process.env.VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST || (defaultValues.minFeeSatPerByte ? defaultValues.minFeeSatPerByte.fast : 0), @@ -91,13 +83,9 @@ export class EnvironmentVariables { || (defaultValues.miningSpeedBlock ? defaultValues.miningSpeedBlock.slow : 0), }; this.burnDustValue = Number(process.env.VUE_APP_BURN_DUST_VALUE) || defaultValues.burnDustValue; - this.maxAmountAllowedInSatoshis = process.env.VUE_APP_MAX_AMOUNT_ALLOWED_IN_SATOSHI - || defaultValues.maxAmountAllowedInSatoshis; this.lbcAddress = process.env.VUE_APP_LBC_ADDRESS || defaultValues.lbcAddress; this.debugMode = process.env.VUE_APP_DEBUG_MODE === 'true' || defaultValues.debugMode; this.peginMinAmountAllowedInBtc = Number(process.env.VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC) || defaultValues.peginMinValue; - this.peginMaxAmountAllowedInBtc = Number(process.env.VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC) - || defaultValues.peginMaxValue; } } diff --git a/src/common/types/pegInTx.ts b/src/common/types/pegInTx.ts index 6e2666550..9ada07035 100644 --- a/src/common/types/pegInTx.ts +++ b/src/common/types/pegInTx.ts @@ -27,7 +27,6 @@ export interface RequestBalance { export interface PeginConfiguration { minValue: number; // SatoshiBN - maxValue: number; // SatoshiBN federationAddress: string; feePerKb?: number; // SatoshiBN sessionId: string; diff --git a/src/common/types/pegOutTx.ts b/src/common/types/pegOutTx.ts index 5de4fa83e..b019ade68 100644 --- a/src/common/types/pegOutTx.ts +++ b/src/common/types/pegOutTx.ts @@ -4,7 +4,6 @@ import SatoshiBig from '@/common/types/SatoshiBig'; export interface PegoutConfiguration { minValue: WeiBig; - maxValue: WeiBig; bridgeContractAddress: string; } diff --git a/src/common/utils/common.ts b/src/common/utils/common.ts index 5065b5876..a672ed62d 100644 --- a/src/common/utils/common.ts +++ b/src/common/utils/common.ts @@ -15,7 +15,6 @@ export const getChunkedValue = (value: string, maxLength: number) => (value.leng export const getClearPeginTxState = (): PegInTxState => ({ peginConfiguration: { minValue: 0, - maxValue: 0, federationAddress: '', sessionId: '', }, @@ -73,7 +72,6 @@ export const getClearPegoutTxState = (): PegOutTxState => ({ amountToTransfer: new WeiBig(0, 'wei'), pegoutConfiguration: { minValue: new WeiBig(0, 'wei'), - maxValue: new WeiBig(0, 'wei'), bridgeContractAddress: '', }, validAmount: false, diff --git a/src/main.ts b/src/main.ts index 70d07d6fb..35f48aaa8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,9 +18,7 @@ const defaultEnvironmentVariables = { vueAppHotjarId: '', vueAppClarityId: '', peginMinValue: 0.005, - peginMaxValue: 10, pegoutMinValue: 0.005, - pegoutMaxValue: 10, minFeeSatPerByte: { fast: 8, average: 4, diff --git a/src/pegin/components/create/BtcInputAmount.vue b/src/pegin/components/create/BtcInputAmount.vue index 917c629dc..71476dcb2 100644 --- a/src/pegin/components/create/BtcInputAmount.vue +++ b/src/pegin/components/create/BtcInputAmount.vue @@ -41,9 +41,6 @@ {{ boundaries.minValue.toBTCString().slice(0,5) }} MIN - - {{ boundaries.maxValue.toBTCString().slice(0,5) }} MAX - @@ -143,16 +140,14 @@ export default defineComponent({ const boundaries = computed(() => { const minValue: SatoshiBig = new SatoshiBig(peginConfiguration.value.minValue, 'btc'); - const maxValue: SatoshiBig = new SatoshiBig(peginConfiguration.value.maxValue, 'btc'); return { minValue, - maxValue, }; }); const amountErrorMessage = computed(() => { // mayor rework const feePlusAmount: SatoshiBig = safeAmount.value.plus(safeTxFee.value); - const { minValue, maxValue } = boundaries.value; + const { minValue } = boundaries.value; if (selectedAccountBalance.value.eq('0') && !isValidAmountToTransfer.value) { return 'Selected account has no balance'; } @@ -180,19 +175,15 @@ export default defineComponent({ if (!enoughBalanceSelectedFee) { return 'The selected fee does not satisfy the minimum required by the network'; } - if (safeAmount.value.gt(maxValue)) { - return `The maximum accepted value is ${maxValue.toBTCTrimmedString()} ${environmentContext.getBtcTicker()}`; - } return 'Invalid format'; }); const insufficientAmount = computed(() => { const feePlusAmount: SatoshiBig = safeAmount.value.plus(safeTxFee.value); - const { minValue, maxValue } = boundaries.value; + const { minValue } = boundaries.value; if (safeAmount.value.lte('0') || feePlusAmount.gt(selectedAccountBalance.value) - || safeAmount.value.lt(minValue) - || safeAmount.value.gt(maxValue)) { + || safeAmount.value.lt(minValue)) { return true; } if (safeAmount.value.gt('0') && feePlusAmount.lte(selectedAccountBalance.value)) { @@ -239,10 +230,9 @@ export default defineComponent({ } const isValidAmount = (amount: SatoshiBig) => { - const { minValue, maxValue } = boundaries.value; + const { minValue } = boundaries.value; return isBTCAmountValidRegex(amount.toBTCString()) - && amount.gte(minValue) - && amount.lte(maxValue); + && amount.gte(minValue); }; async function getOptionsData() { @@ -269,33 +259,11 @@ export default defineComponent({ }, }); - function fillMaxValueAvailable() { - const maxAvailable = selectedAccountBalance.value - .cmp(boundaries.value.maxValue.plus(safeTxFee.value)) === -1 - ? selectedAccountBalance.value : boundaries.value.maxValue; - const tempValue = maxAvailable.minus(safeTxFee.value); - bitcoinAmount.value = tempValue.toBTCTrimmedString(); - setBtcAmount(tempValue); - setIsValidAmount(selectedAccountBalance.value.gt('0')); - } - function setMin() { const min = new SatoshiBig(peginConfiguration.value.minValue, 'btc'); bitcoinAmountModel.value = min.toBTCTrimmedString(); } - async function setMax() { - fillMaxValueAvailable(); - calculateTxFee() - .then(() => { - fillMaxValueAvailable(); - bitcoinAmountModel.value = bitcoinAmount.value; - }) - .catch((e) => { - context.emit('pegin-error', e); - }); - } - function watchBitcoinAmount() { checkStep(); amountStyle.value = stepState.value === 'done' ? 'black-box' : 'yellow-box'; @@ -337,7 +305,6 @@ export default defineComponent({ rbtcAmount, amountErrorMessage, mdiArrowRight, - setMax, setMin, mdiBitcoin, boundaries, diff --git a/src/pegin/services/peginConfigurationService.ts b/src/pegin/services/peginConfigurationService.ts index c2113117f..2349a4d8f 100644 --- a/src/pegin/services/peginConfigurationService.ts +++ b/src/pegin/services/peginConfigurationService.ts @@ -8,12 +8,10 @@ export default class PeginConfigurationService { const bridgeService = new BridgeService(); const { peginMinAmountAllowedInBtc: minValue, - peginMaxAmountAllowedInBtc: maxValue, } = EnvironmentAccessorService.getEnvironmentVariables(); bridgeService.getFederationAddress().then((federationAddress) => { const peginConf: PeginConfiguration = ({ minValue, - maxValue, federationAddress, // sessionId should be removed eventually sessionId: '', diff --git a/src/pegin/store/FlyoverPegin/actions.ts b/src/pegin/store/FlyoverPegin/actions.ts index 0ee75c074..3f9ea9072 100644 --- a/src/pegin/store/FlyoverPegin/actions.ts +++ b/src/pegin/store/FlyoverPegin/actions.ts @@ -1,5 +1,5 @@ import { - FlyoverPeginState, QuotePegIn2WP, RootState, SatoshiBig, + FlyoverPeginState, QuotePegIn2WP, RootState, SatoshiBig, WeiBig, } from '@/common/types'; import { ActionTree } from 'vuex'; import * as constants from '@/common/store/constants'; @@ -58,4 +58,30 @@ export const actions: ActionTree = { [constants.FLYOVER_PEGIN_CLEAR_QUOTES]: ({ commit }) => { commit(constants.FLYOVER_PEGIN_SET_QUOTES, {}); }, + [constants.FLYOVER_PEGIN_GET_AVAILABLE_LIQUIDITY]: + ({ state, dispatch, commit }) => new Promise((resolve, reject) => { + const providersPromises: + Promise[] = []; + state.liquidityProviders.forEach((provider) => { + dispatch(constants.FLYOVER_PEGIN_USE_LIQUIDITY_PROVIDER, provider.id); + providersPromises.push(state.flyoverService.getAvailableLiquidity()); + }); + Promise.allSettled(providersPromises) + .then((responses) => responses.forEach((response) => { + if (response.status === 'fulfilled') { + if (response.value instanceof Object) { + const { providerId, peginLiquidity } = response.value; + commit( + constants.FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY, + { providerId, peginLiquidity }, + ); + } + } + })) + .catch(reject); + }), }; diff --git a/src/pegin/store/FlyoverPegin/mutations.ts b/src/pegin/store/FlyoverPegin/mutations.ts index 3f8a635f7..1565782b0 100644 --- a/src/pegin/store/FlyoverPegin/mutations.ts +++ b/src/pegin/store/FlyoverPegin/mutations.ts @@ -20,4 +20,13 @@ export const mutations: MutationTree = { [constants.FLYOVER_PEGIN_SET_SELECTED_QUOTE]: (state, quoteHash: string) => { state.selectedQuoteHash = quoteHash; }, + [constants.FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY]: (state, payload) => { + const { providerId, peginLiquidity } = payload; + const providers = state.liquidityProviders; + providers.forEach((provider, idx) => { + if (provider.id === providerId) { + state.liquidityProviders[idx].pegin.availableLiquidity = peginLiquidity; + } + }); + }, }; diff --git a/src/pegin/store/PeginTx/actions.ts b/src/pegin/store/PeginTx/actions.ts index 3c188ec87..2a22dd51b 100644 --- a/src/pegin/store/PeginTx/actions.ts +++ b/src/pegin/store/PeginTx/actions.ts @@ -173,10 +173,7 @@ export const actions: ActionTree = { [constants.PEGIN_TX_START_ASKING_FOR_BALANCE]: ({ state }): Promise => { if (state.walletService) { return state.walletService - .startAskingForBalance( - state.peginConfiguration.sessionId, - state.peginConfiguration.maxValue, - ); + .startAskingForBalance(); } return Promise.reject(new Error('Wallet service is not set')); }, diff --git a/src/pegin/store/PeginTx/getters.ts b/src/pegin/store/PeginTx/getters.ts index c60a4b9b1..189a1204b 100644 --- a/src/pegin/store/PeginTx/getters.ts +++ b/src/pegin/store/PeginTx/getters.ts @@ -214,11 +214,9 @@ export const getters: GetterTree = { .plus(moduleGetters[constants.PEGIN_TX_GET_SAFE_TX_FEE]); const selectedAccountBalance = moduleGetters[constants.PEGIN_TX_GET_SELECTED_BALANCE]; const minValue: SatoshiBig = new SatoshiBig(state.peginConfiguration.minValue, 'btc'); - const maxValue: SatoshiBig = new SatoshiBig(state.peginConfiguration.maxValue, 'btc'); if (state.amountToTransfer.lte('0') || feePlusAmount.gt(selectedAccountBalance) - || state.amountToTransfer.lt(minValue) - || state.amountToTransfer.gt(maxValue)) { + || state.amountToTransfer.lt(minValue)) { return false; } if (state.amountToTransfer.gt('0') && feePlusAmount.lte(selectedAccountBalance)) { diff --git a/src/pegout/components/FlyoverRbtcInputAmount.vue b/src/pegout/components/FlyoverRbtcInputAmount.vue index 18a35a1b4..8634d368d 100644 --- a/src/pegout/components/FlyoverRbtcInputAmount.vue +++ b/src/pegout/components/FlyoverRbtcInputAmount.vue @@ -44,9 +44,6 @@ {{ minStrVal }} MIN - - {{ maxStrVal }} MAX - @@ -110,20 +107,17 @@ export default defineComponent({ const addAmount = useAction('pegOutTx', constants.PEGOUT_TX_ADD_AMOUNT); const calculateFee = useAction('pegOutTx', constants.PEGOUT_TX_CALCULATE_FEE); const estimatedBtcToReceive = useGetter('pegOutTx', constants.PEGOUT_TX_GET_ESTIMATED_BTC_TO_RECEIVE); - const getRbtcGasFee = useGetter>('web3Session', constants.SESSION_GET_RBTC_GAS_FEE); const pegoutConfiguration = useStateAttribute('pegOutTx', 'pegoutConfiguration'); const account = useStateAttribute('web3Session', 'account'); const minStrVal = computed(() => pegoutConfiguration.value.minValue.toRBTCString().slice(0, 5)); - const maxStrVal = computed(() => pegoutConfiguration.value.maxValue.toRBTCString().slice(0, 5)); const isComposing = ref(false); const isValidAmount = (amount: WeiBig) => { - const { minValue, maxValue } = pegoutConfiguration.value; + const { minValue } = pegoutConfiguration.value; const { balance } = web3SessionState.value; return isRBTCAmountValidRegex(amount.toRBTCString()) && amount.gte(minValue) - && amount.lte(balance) - && amount.lte(maxValue); + && amount.lte(balance); }; const rbtcAmountModel = computed({ @@ -145,7 +139,7 @@ export default defineComponent({ const safeAmount = computed((): WeiBig => new WeiBig(rbtcAmount.value ?? '0', 'rbtc')); const amountErrorMessage = computed(() => { - const { minValue, maxValue } = pegoutConfiguration.value; + const { minValue } = pegoutConfiguration.value; const { balance } = web3SessionState.value; if (rbtcAmount.value.toString() === '') { return 'Please, enter an amount'; @@ -165,19 +159,15 @@ export default defineComponent({ if (safeAmount.value.lt(minValue)) { return `This value is below the minimum allowed value of ${minValue.toRBTCTrimmedString()} ${environmentContext.getRbtcTicker()}`; } - if (safeAmount.value.gt(maxValue)) { - return `This value is above the maximum allowed value of ${maxValue.toRBTCTrimmedString()} ${environmentContext.getRbtcTicker()}`; - } return ''; }); const insufficientAmount = computed(() => { - const { minValue, maxValue } = pegoutConfiguration.value; + const { minValue } = pegoutConfiguration.value; const { balance } = web3SessionState.value; return safeAmount.value.lte('0') || safeAmount.value.gt(balance) - || safeAmount.value.lt(minValue) - || safeAmount.value.gt(maxValue); + || safeAmount.value.lt(minValue); }); function blockLetterKeyDown(e: KeyboardEvent) { @@ -212,17 +202,6 @@ export default defineComponent({ } } - async function setMax() { - const { maxValue } = pegoutConfiguration.value; - const { balance } = web3SessionState.value; - const minFee = await getRbtcGasFee.value; - if (balance.lt(maxValue)) { - rbtcAmountModel.value = balance.minus(minFee).toRBTCTrimmedString(); - } else { - rbtcAmountModel.value = maxValue.toRBTCTrimmedString(); - } - } - function clearInput() { rbtcAmountModel.value = ''; stepState.value = 'unset'; @@ -242,11 +221,9 @@ export default defineComponent({ mdiInformationOutline, mdiBitcoin, setMin, - setMax, estimatedBtcToReceive, rbtcAmountModel, minStrVal, - maxStrVal, isComposing, }; }, diff --git a/src/pegout/components/RbtcInputAmount.vue b/src/pegout/components/RbtcInputAmount.vue index 8974d31c7..e8af813e8 100644 --- a/src/pegout/components/RbtcInputAmount.vue +++ b/src/pegout/components/RbtcInputAmount.vue @@ -134,7 +134,7 @@ export default defineComponent({ const amountErrorMessage = computed(() => { const feePlusAmount: WeiBig = safeAmount.value.plus(safeTxFee.value); - const { minValue, maxValue } = pegOutTxState.value.pegoutConfiguration; + const { minValue } = pegOutTxState.value.pegoutConfiguration; const { balance } = web3SessionState.value; if (rbtcAmount.value.toString() === '') { return 'Please, enter an amount'; @@ -157,9 +157,6 @@ export default defineComponent({ if (safeAmount.value.lt(minValue)) { return `The minimum accepted value is ${minValue.toRBTCTrimmedString()} ${environmentContext.getRbtcTicker()}`; } - if (safeAmount.value.gt(maxValue)) { - return `The maximum accepted value is ${maxValue.toRBTCTrimmedString()} ${environmentContext.getRbtcTicker()}`; - } return ''; }); @@ -169,8 +166,7 @@ export default defineComponent({ const { balance } = web3SessionState.value; if (safeAmount.value.lte('0') || feePlusAmount.gt(balance) - || safeAmount.value.lt(pegoutConfiguration.minValue) - || safeAmount.value.gt(pegoutConfiguration.maxValue)) { + || safeAmount.value.lt(pegoutConfiguration.minValue)) { return true; } if (safeAmount.value.gt('0') && feePlusAmount.lte(balance)) { diff --git a/src/pegout/store/FlyoverPegout/getters.ts b/src/pegout/store/FlyoverPegout/getters.ts index a0df3daf3..5c56696e0 100644 --- a/src/pegout/store/FlyoverPegout/getters.ts +++ b/src/pegout/store/FlyoverPegout/getters.ts @@ -28,7 +28,6 @@ export const getters: GetterTree = { if (state.liquidityProviders.length === 0) { return { minValue: new WeiBig(EnvironmentAccessorService.getEnvironmentVariables().pegoutMinValue, 'rbtc'), - maxValue: new WeiBig(EnvironmentAccessorService.getEnvironmentVariables().pegoutMaxValue, 'rbtc'), }; } const { pegout } = state.liquidityProviders[0]; diff --git a/src/pegout/store/pegoutTx/actions.ts b/src/pegout/store/pegoutTx/actions.ts index 5bd97fed2..f3fd10d8a 100644 --- a/src/pegout/store/pegoutTx/actions.ts +++ b/src/pegout/store/pegoutTx/actions.ts @@ -48,8 +48,6 @@ export const actions: ActionTree = { commit(constants.PEGOUT_TX_SET_PEGOUT_CONFIGURATION, { minValue: new WeiBig(EnvironmentAccessorService.getEnvironmentVariables().pegoutMinValue, 'rbtc'), - maxValue: - new WeiBig(EnvironmentAccessorService.getEnvironmentVariables().pegoutMaxValue, 'rbtc'), bridgeContractAddress: constants.BRIDGE_CONTRACT_ADDRESS, }); }, diff --git a/src/pegout/store/pegoutTx/getters.ts b/src/pegout/store/pegoutTx/getters.ts index ff6e23219..407426a8d 100644 --- a/src/pegout/store/pegoutTx/getters.ts +++ b/src/pegout/store/pegoutTx/getters.ts @@ -25,8 +25,7 @@ export const getters: GetterTree = { .plus(moduleGetters[constants.PEGOUT_TX_GET_SAFE_TX_FEE]); if (state.amountToTransfer.lte('0') || feePlusAmount.gt(balance) - || state.amountToTransfer.lt(state.pegoutConfiguration.minValue) - || state.amountToTransfer.gt(state.pegoutConfiguration.maxValue)) { + || state.amountToTransfer.lt(state.pegoutConfiguration.minValue)) { return false; } if (state.amountToTransfer.gt('0') && feePlusAmount.lte(balance)) {