From 4013af0c5ce2ddb5deed3e60bfacaa4c25d4b6a8 Mon Sep 17 00:00:00 2001 From: ronaldsg Date: Thu, 21 Nov 2024 13:54:20 -0500 Subject: [PATCH] Update store quote to include acceptedQuoteSignature --- src/common/store/constants.ts | 2 ++ src/common/store/helper.ts | 4 ++-- src/common/types/Flyover/FlyoverPegin.ts | 1 + src/common/types/TxInfo.ts | 1 + src/common/utils/common.ts | 1 + src/pegin/components/create/ConfirmTx.vue | 2 ++ src/pegin/components/create/PegInForm.vue | 5 +++-- src/pegin/store/FlyoverPegin/actions.ts | 8 ++++++++ src/pegin/store/FlyoverPegin/mutations.ts | 3 +++ 9 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/common/store/constants.ts b/src/common/store/constants.ts index c917cbaf3..ef8700bf7 100644 --- a/src/common/store/constants.ts +++ b/src/common/store/constants.ts @@ -90,6 +90,7 @@ 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'; +export const FLYOVER_PEGIN_ACCEPT_QUOTE = 'FLYOVER_PEGIN_ACCEPT_QUOTE'; // 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 = { @@ -168,6 +169,7 @@ export const FLYOVER_PEGIN_SET_ROOTSTOCK_ADDRESS = 'FLYOVER_PEGIN_SET_ROOTSTOCK_ 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'; +export const FLYOVER_PEGIN_SET_ACCEPTED_QUOTE_SIGNATURE = 'FLYOVER_PEGIN_SET_ACCEPTED_QUOTE_SIGNATURE'; // Session mutations export const SESSION_SET_ACCOUNT = 'SESSION_SET_ACCOUNT'; diff --git a/src/common/store/helper.ts b/src/common/store/helper.ts index e698541f1..72929151c 100644 --- a/src/common/store/helper.ts +++ b/src/common/store/helper.ts @@ -17,10 +17,10 @@ export function useGetters(module: string, getters: string[]) { return Object.fromEntries(keyPair); } -export function useAction(module: string, action: string) { +export function useAction(module: string, action: string) { const store = useStore(); // eslint-disable-next-line - return async (param?: any): Promise => store.dispatch(`${module}/${action}`, param); + return async (param?: any): Promise => store.dispatch(`${module}/${action}`, param); } export function useGetter(module: string, getter: string): ComputedRef { diff --git a/src/common/types/Flyover/FlyoverPegin.ts b/src/common/types/Flyover/FlyoverPegin.ts index 9d5148bed..7963791ed 100644 --- a/src/common/types/Flyover/FlyoverPegin.ts +++ b/src/common/types/Flyover/FlyoverPegin.ts @@ -14,4 +14,5 @@ export interface FlyoverPeginState { flyoverService: FlyoverService; txHash?: string; selectedQuoteHash: string; + acceptedQuoteSignature: string; } diff --git a/src/common/types/TxInfo.ts b/src/common/types/TxInfo.ts index abdabfe79..da6430187 100644 --- a/src/common/types/TxInfo.ts +++ b/src/common/types/TxInfo.ts @@ -50,4 +50,5 @@ export interface TxInfo { details?: Record; quote?: PeginQuoteDbModel | PegoutQuoteDbModel; quoteHash?: string; + acceptedQuoteSignature?: string; } diff --git a/src/common/utils/common.ts b/src/common/utils/common.ts index d22a91722..37946fdde 100644 --- a/src/common/utils/common.ts +++ b/src/common/utils/common.ts @@ -119,6 +119,7 @@ export const getClearFlyoverPeginState = (): FlyoverPeginState => ({ quotes: {}, flyoverService: markRaw(new FlyoverService()), selectedQuoteHash: '', + acceptedQuoteSignature: '', }); export const compareObjects = ( diff --git a/src/pegin/components/create/ConfirmTx.vue b/src/pegin/components/create/ConfirmTx.vue index 8cba41a25..bc1bc3143 100644 --- a/src/pegin/components/create/ConfirmTx.vue +++ b/src/pegin/components/create/ConfirmTx.vue @@ -66,6 +66,7 @@ export default defineComponent({ const liquidityProviders = useStateAttribute('flyoverPegin', 'liquidityProviders'); const recipientAddress = useStateAttribute('flyoverPegin', 'rootstockRecipientAddress'); const peginType = useStateAttribute('pegInTx', 'peginType'); + const acceptedQuoteSignature = useStateAttribute('flyoverPegin', 'acceptedQuoteSignature'); const isFlyover = computed(() => peginType.value === constants.peginType.FLYOVER); function getLPName(): string { @@ -109,6 +110,7 @@ export default defineComponent({ }, quote: dbQuote, quoteHash: selectedQuote.value.quoteHash, + acceptedQuoteSignature: acceptedQuoteSignature.value, }; }); diff --git a/src/pegin/components/create/PegInForm.vue b/src/pegin/components/create/PegInForm.vue index 090013a05..303e6e37f 100644 --- a/src/pegin/components/create/PegInForm.vue +++ b/src/pegin/components/create/PegInForm.vue @@ -100,6 +100,7 @@ import { BridgeService } from '@/common/services/BridgeService'; import { FlyoverService } from '@/common/services'; import FullTxErrorDialog from '@/common/components/exchange/FullTxErrorDialog.vue'; import RskDestinationAddress from '@/pegin/components/create/RskDestinationAddress.vue'; +import { AcceptedQuote } from '@rsksmart/flyover-sdk'; export default defineComponent({ name: 'PegInForm', @@ -134,9 +135,9 @@ export default defineComponent({ const getPeginQuotes = useAction('flyoverPegin', constants.FLYOVER_PEGIN_GET_QUOTES); const setSelectedQuote = useAction('flyoverPegin', constants.FLYOVER_PEGIN_ADD_SELECTED_QUOTE); const clearQuotes = useAction('flyoverPegin', constants.FLYOVER_PEGIN_CLEAR_QUOTES); + const acceptQuote = useAction('flyoverPegin', constants.FLYOVER_PEGIN_ACCEPT_QUOTE); 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 selectedFee = useGetter('pegInTx', constants.PEGIN_TX_GET_SAFE_TX_FEE); const selectedAccountBalance = useGetter('pegInTx', constants.PEGIN_TX_GET_SELECTED_BALANCE); @@ -190,7 +191,7 @@ export default defineComponent({ peginType: constants.peginType.POWPEG, }); } else { - flyoverService.value.acceptPeginQuote(selectedQuoteHash.value) + acceptQuote() .then((acceptedQuote) => { context.emit('createTx', { amountToTransferInSatoshi: selectedQuote.value?.valueToTransfer, diff --git a/src/pegin/store/FlyoverPegin/actions.ts b/src/pegin/store/FlyoverPegin/actions.ts index 08e58f7a0..d3b6df57e 100644 --- a/src/pegin/store/FlyoverPegin/actions.ts +++ b/src/pegin/store/FlyoverPegin/actions.ts @@ -120,4 +120,12 @@ export const actions: ActionTree = { })) .catch(reject); }), + [constants.FLYOVER_PEGIN_ACCEPT_QUOTE]: ({ commit, state }) => new Promise((resolve, reject) => { + state.flyoverService.acceptPeginQuote(state.selectedQuoteHash) + .then((acceptedQuote) => { + commit(constants.FLYOVER_PEGIN_SET_ACCEPTED_QUOTE_SIGNATURE, acceptedQuote.signature); + resolve(acceptedQuote); + }) + .catch(reject); + }), }; diff --git a/src/pegin/store/FlyoverPegin/mutations.ts b/src/pegin/store/FlyoverPegin/mutations.ts index 1565782b0..a57ebf2a4 100644 --- a/src/pegin/store/FlyoverPegin/mutations.ts +++ b/src/pegin/store/FlyoverPegin/mutations.ts @@ -29,4 +29,7 @@ export const mutations: MutationTree = { } }); }, + [constants.FLYOVER_PEGIN_SET_ACCEPTED_QUOTE_SIGNATURE]: (state, quoteSignature: string) => { + state.acceptedQuoteSignature = quoteSignature; + }, };