diff --git a/src/common/store/constants.ts b/src/common/store/constants.ts index c5a59594..e99b7630 100644 --- a/src/common/store/constants.ts +++ b/src/common/store/constants.ts @@ -53,6 +53,7 @@ export const PEGIN_TX_STOP_ASKING_FOR_BALANCE = 'PEGIN_TX_STOP_ASKING_FOR_BALANC export const PEGIN_TX_ADD_STATUS_SAFE_FEE = 'PEGIN_TX_ADD_STATUS_SAFE_FEE'; export const PEGIN_TX_ADD_STATUS_REFUND_ADDRESS = 'PEGIN_TX_ADD_STATUS_REFUND_ADDRESS'; export const PEGIN_TX_ADD_STATUS_TX_ID = 'PEGIN_TX_ADD_STATUS_TX_ID'; +export const PEGIN_TX_ADD_PEGIN_TYPE = 'PEGIN_TX_ADD_PEGIN_TYPE'; // PegOut actions export const PEGOUT_TX_INIT = 'PEGOUT_TX_INIT'; @@ -89,6 +90,7 @@ export const FLYOVER_PEGIN_ADD_AMOUNT = 'FLYOVER_PEGIN_ADD_AMOUNT'; export const FLYOVER_PEGIN_ADD_ROOTSTOCK_ADDRESS = 'FLYOVER_PEGIN_ADD_ROOTSTOCK_ADDRESS'; export const FLYOVER_PEGIN_USE_LIQUIDITY_PROVIDER = 'FLYOVER_PEGIN_USE_LIQUIDITY_PROVIDER'; export const FLYOVER_PEGIN_GET_QUOTES = 'FLYOVER_PEGIN_GET_QUOTES'; +export const FLYOVER_PEGIN_ADD_SELECTED_QUOTE = 'FLYOVER_PEGIN_ADD_SELECTED_QUOTE'; // Session actions export const WEB3_SESSION_GET_ACCOUNT = 'WEB3_SESSION_GET_ACCOUNT'; @@ -129,6 +131,7 @@ export const PEGIN_TX_WALLET_SERVICE_SUBSCRIBE = 'PEGIN_TX_WALLET_SERVICE_SUBSCR export const PEGIN_TX_SET_STATUS_SAFE_FEE = 'PEGIN_TX_SET_STATUS_SAFE_FEE'; export const PEGIN_TX_SET_STATUS_REFUND_ADDRESS = 'PEGIN_TX_SET_STATUS_REFUND_ADDRESS'; export const PEGIN_TX_SET_STATUS_TX_ID = 'PEGIN_TX_SET_STATUS_TX_ID'; +export const PEGIN_TX_SET_PEGIN_TYPE = 'PEGIN_TX_SET_PEGIN_TYPE'; // PegOut mutations export const PEGOUT_TX_SET_SELECTED_FEE_LEVEL = 'PEGOUT_TX_SET_SELECTED_FEE_LEVEL'; @@ -162,6 +165,7 @@ 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'; // Session mutations export const SESSION_SET_ACCOUNT = 'SESSION_SET_ACCOUNT'; diff --git a/src/common/types/pegInTx.ts b/src/common/types/pegInTx.ts index fdcc655c..601ecc39 100644 --- a/src/common/types/pegInTx.ts +++ b/src/common/types/pegInTx.ts @@ -1,6 +1,7 @@ import { AccountBalance, FeeAmountData, NormalizedTx } from '@/common/types/Common'; import SatoshiBig from '@/common/types/SatoshiBig'; import { WalletService } from '@/common/services'; +import * as constants from '@/common/store/constants'; export type BtcAccount = 'BITCOIN_LEGACY_ADDRESS' | 'BITCOIN_SEGWIT_ADDRESS' | @@ -72,6 +73,7 @@ export interface PegInTxState { refundAddress: string; safeFee: SatoshiBig; } + peginType: constants.peginType; } export interface UnusedWalletAddress { diff --git a/src/common/utils/common.ts b/src/common/utils/common.ts index f4e4d88c..5065b587 100644 --- a/src/common/utils/common.ts +++ b/src/common/utils/common.ts @@ -8,6 +8,7 @@ import { } from '@/common/types'; import { FlyoverService } from '@/common/services'; import { markRaw } from 'vue'; +import * as constants from '@/common/store/constants'; export const getChunkedValue = (value: string, maxLength: number) => (value.length < maxLength ? value : `${value.substr(0, maxLength / 2)}...${value.substr(value.length - maxLength / 2, value.length)}`); @@ -65,6 +66,7 @@ export const getClearPeginTxState = (): PegInTxState => ({ refundAddress: '', safeFee: new SatoshiBig(0, 'btc'), }, + peginType: constants.peginType.POWPEG, }); export const getClearPegoutTxState = (): PegOutTxState => ({ diff --git a/src/pegin/components/create/PegInForm.vue b/src/pegin/components/create/PegInForm.vue index b69c7cb9..8595b1de 100644 --- a/src/pegin/components/create/PegInForm.vue +++ b/src/pegin/components/create/PegInForm.vue @@ -88,6 +88,7 @@ import { import AddressWarningDialog from '@/common/components/exchange/AddressWarningDialog.vue'; import BtcFeeSelect from '@/pegin/components/create/BtcFeeSelect.vue'; import { BridgeService } from '@/common/services/BridgeService'; +import { FlyoverService } from '@/common/services'; export default defineComponent({ name: 'PegInForm', @@ -107,7 +108,7 @@ export default defineComponent({ const flyoverEnabled = ref(true); const showOptions = ref(false); const loadingQuotes = ref(false); - const selected = ref(); + const selected = ref(); const selectedQuote = ref(); const account = useStateAttribute('web3Session', 'account'); @@ -116,8 +117,12 @@ export default defineComponent({ const refundAddress = useGetter('pegInTx', constants.PEGIN_TX_GET_REFUND_ADDRESS); const enoughBalanceSelectedFee = useGetter('pegInTx', constants.PEGIN_TX_GET_ENOUGH_FEE_VALUE); const getPeginQuotes = useAction('flyoverPegin', constants.FLYOVER_PEGIN_GET_QUOTES); + const setSelectedQuote = useAction('flyoverPegin', constants.FLYOVER_PEGIN_ADD_SELECTED_QUOTE); const session = useState('web3Session'); const quotes = useStateAttribute>('flyoverPegin', 'quotes'); + const setPeginType = useAction('pegInTx', constants.PEGIN_TX_ADD_PEGIN_TYPE); + const selectedQuoteHash = useStateAttribute('flyoverPegin', 'selectedQuoteHash'); + const flyoverService = useStateAttribute('flyoverPegin', 'flyoverService'); const isReadyToCreate = computed((): boolean => pegInTxState.value.isValidAmountToTransfer && !pegInTxState.value.loadingFee @@ -158,6 +163,7 @@ export default defineComponent({ peginType: constants.peginType.POWPEG, }); } else { + const acceptedQuote = await flyoverService.value.acceptPeginQuote(selectedQuoteHash.value); context.emit('createTx', { amountToTransferInSatoshi: selectedQuote.value?.quote.value .plus(selectedQuote.value?.quote.productFeeAmount) @@ -167,15 +173,17 @@ export default defineComponent({ recipient: '', feeLevel: pegInTxState.value.selectedFee, accountType: pegInTxState.value.selectedAccount, - btcRecipient: selectedQuote.value?.quote.lpBTCAddr, + btcRecipient: acceptedQuote.bitcoinDepositAddressHash, peginType: constants.peginType.FLYOVER, }); } } - function changeSelectedOption(selectedType: constants.peginType, quote?: QuotePegIn2WP) { + async function changeSelectedOption(selectedType: constants.peginType, quote?: QuotePegIn2WP) { selected.value = selectedType; + await setPeginType(selected.value); selectedQuote.value = quote; + setSelectedQuote(quote?.quoteHash); } async function getQuotes() { diff --git a/src/pegin/components/create/SendBitcoin.vue b/src/pegin/components/create/SendBitcoin.vue index 61c5c4d1..53280272 100644 --- a/src/pegin/components/create/SendBitcoin.vue +++ b/src/pegin/components/create/SendBitcoin.vue @@ -50,7 +50,7 @@ import ConnectDevice from '@/common/components/exchange/ConnectDevice.vue'; import TxErrorDialog from '@/common/components/exchange/TxErrorDialog.vue'; import { TrezorError } from '@/common/types/exception/TrezorError'; import LeatherTxBuilder from '@/pegin/middleware/TxBuilder/LeatherTxBuilder'; -import PeginTxService from '../../services/PeginTxService'; +import PeginTxService from '@/pegin/services/PeginTxService'; export default defineComponent({ name: 'SendBitcoin', diff --git a/src/pegin/store/FlyoverPegin/actions.ts b/src/pegin/store/FlyoverPegin/actions.ts index f0ddac1d..07f0c597 100644 --- a/src/pegin/store/FlyoverPegin/actions.ts +++ b/src/pegin/store/FlyoverPegin/actions.ts @@ -52,4 +52,7 @@ export const actions: ActionTree = { .then(() => resolve(commit(constants.FLYOVER_PEGIN_SET_QUOTES, quotesByProvider))) .catch(reject); }), + [constants.FLYOVER_PEGIN_ADD_SELECTED_QUOTE]: ({ commit }, quoteHash: string) => { + commit(constants.FLYOVER_PEGIN_SET_SELECTED_QUOTE, quoteHash); + }, }; diff --git a/src/pegin/store/FlyoverPegin/mutations.ts b/src/pegin/store/FlyoverPegin/mutations.ts index 6106152b..d8451e8e 100644 --- a/src/pegin/store/FlyoverPegin/mutations.ts +++ b/src/pegin/store/FlyoverPegin/mutations.ts @@ -17,4 +17,7 @@ export const mutations: MutationTree = { [constants.FLYOVER_PEGIN_SET_QUOTES]: (state, quotes: Record>) => { state.quotes = quotes; }, + [constants.FLYOVER_PEGIN_SET_SELECTED_QUOTE]: (state, quoteHash: string) => { + state.selectedQuoteHash = quoteHash; + }, }; diff --git a/src/pegin/store/PeginTx/actions.ts b/src/pegin/store/PeginTx/actions.ts index 32b3da40..750b19c9 100644 --- a/src/pegin/store/PeginTx/actions.ts +++ b/src/pegin/store/PeginTx/actions.ts @@ -185,4 +185,7 @@ export const actions: ActionTree = { [constants.PEGIN_TX_ADD_STATUS_TX_ID]: ({ commit }, txId: string): void => { commit(constants.PEGIN_TX_SET_STATUS_TX_ID, txId); }, + [constants.PEGIN_TX_ADD_PEGIN_TYPE]: ({ commit }, peginType: constants.peginType): void => { + commit(constants.PEGIN_TX_SET_PEGIN_TYPE, peginType); + }, }; diff --git a/src/pegin/store/PeginTx/mutations.ts b/src/pegin/store/PeginTx/mutations.ts index 86d547e2..76425934 100644 --- a/src/pegin/store/PeginTx/mutations.ts +++ b/src/pegin/store/PeginTx/mutations.ts @@ -82,4 +82,7 @@ export const mutations: MutationTree = { [constants.PEGIN_TX_SET_STATUS_TX_ID]: (state, txId: string) => { state.statusInfo.txId = txId; }, + [constants.PEGIN_TX_SET_PEGIN_TYPE]: (state, peginType: constants.peginType) => { + state.peginType = peginType; + }, };