Skip to content

Commit

Permalink
Update store quote to include acceptedQuoteSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldsg20 committed Nov 21, 2024
1 parent 31c39a7 commit 4013af0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/common/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/common/store/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(module: string, action: string) {
const store = useStore();
// eslint-disable-next-line
return async (param?: any): Promise<void> => store.dispatch(`${module}/${action}`, param);
return async (param?: any): Promise<T> => store.dispatch(`${module}/${action}`, param);
}

export function useGetter<T>(module: string, getter: string): ComputedRef<T> {
Expand Down
1 change: 1 addition & 0 deletions src/common/types/Flyover/FlyoverPegin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface FlyoverPeginState {
flyoverService: FlyoverService;
txHash?: string;
selectedQuoteHash: string;
acceptedQuoteSignature: string;
}
1 change: 1 addition & 0 deletions src/common/types/TxInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export interface TxInfo {
details?: Record<string, unknown>;
quote?: PeginQuoteDbModel | PegoutQuoteDbModel;
quoteHash?: string;
acceptedQuoteSignature?: string;
}
1 change: 1 addition & 0 deletions src/common/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const getClearFlyoverPeginState = (): FlyoverPeginState => ({
quotes: {},
flyoverService: markRaw(new FlyoverService()),
selectedQuoteHash: '',
acceptedQuoteSignature: '',
});

export const compareObjects = (
Expand Down
2 changes: 2 additions & 0 deletions src/pegin/components/create/ConfirmTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default defineComponent({
const liquidityProviders = useStateAttribute<LiquidityProvider2WP[]>('flyoverPegin', 'liquidityProviders');
const recipientAddress = useStateAttribute<string>('flyoverPegin', 'rootstockRecipientAddress');
const peginType = useStateAttribute<string>('pegInTx', 'peginType');
const acceptedQuoteSignature = useStateAttribute<string>('flyoverPegin', 'acceptedQuoteSignature');
const isFlyover = computed(() => peginType.value === constants.peginType.FLYOVER);
function getLPName(): string {
Expand Down Expand Up @@ -109,6 +110,7 @@ export default defineComponent({
},
quote: dbQuote,
quoteHash: selectedQuote.value.quoteHash,
acceptedQuoteSignature: acceptedQuoteSignature.value,
};
});
Expand Down
5 changes: 3 additions & 2 deletions src/pegin/components/create/PegInForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<AcceptedQuote>('flyoverPegin', constants.FLYOVER_PEGIN_ACCEPT_QUOTE);
const quotes = useStateAttribute<Record<number, QuotePegIn2WP[]>>('flyoverPegin', 'quotes');
const setPeginType = useAction('pegInTx', constants.PEGIN_TX_ADD_PEGIN_TYPE);
const selectedQuoteHash = useStateAttribute<string>('flyoverPegin', 'selectedQuoteHash');
const flyoverService = useStateAttribute<FlyoverService>('flyoverPegin', 'flyoverService');
const selectedFee = useGetter<SatoshiBig>('pegInTx', constants.PEGIN_TX_GET_SAFE_TX_FEE);
const selectedAccountBalance = useGetter<SatoshiBig>('pegInTx', constants.PEGIN_TX_GET_SELECTED_BALANCE);
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/pegin/store/FlyoverPegin/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ export const actions: ActionTree<FlyoverPeginState, RootState> = {
}))
.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);
}),
};
3 changes: 3 additions & 0 deletions src/pegin/store/FlyoverPegin/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ export const mutations: MutationTree<FlyoverPeginState> = {
}
});
},
[constants.FLYOVER_PEGIN_SET_ACCEPTED_QUOTE_SIGNATURE]: (state, quoteSignature: string) => {
state.acceptedQuoteSignature = quoteSignature;
},
};

0 comments on commit 4013af0

Please sign in to comment.