Skip to content

Commit

Permalink
Merge branch 'djeck1432:main' into pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
1nonlypiece authored Dec 25, 2024
2 parents f207af3 + 457c189 commit 4725fea
Show file tree
Hide file tree
Showing 10 changed files with 33,224 additions and 1,608 deletions.
21,908 changes: 21,908 additions & 0 deletions frontend/package-lock.json

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions frontend/src/hooks/useClosePosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,42 @@ import { useWalletStore } from 'stores/useWalletStore';
import { notify } from 'components/layout/notifier/Notifier';

export const useClosePosition = () => {
const { walletId } = useWalletStore();
const { walletId } = useWalletStore();

return useMutation({
mutationFn: async () => {
if (!walletId) {
console.error('closePositionEvent: walletId is undefined');
return;
}
const response = await axiosInstance.get(`/api/get-repay-data?wallet_id=${walletId}`);
await closePosition(response.data);
await axiosInstance.get(`/api/close-position?position_id=${response.data.position_id}`);
},
onError: (error) => {
console.error('Error during closePositionEvent', error);
notify(`Error during closePositionEvent: ${error.message}`, 'error');
},
});
return useMutation({
mutationFn: async () => {
if (!walletId) {
console.error('closePositionEvent: walletId is undefined');
return;
}
const response = await axiosInstance.get(`/api/get-repay-data?wallet_id=${walletId}`);
const transactionResult = await closePosition(response.data);

await axiosInstance.post(`/api/close-position`, {
position_id: response.data.position_id,
transaction_hash: transactionResult.transaction_hash
});
},
onError: (error) => {
console.error('Error during closePositionEvent', error);
notify(`Error during closePositionEvent: ${error.message}`, 'error');
},
});
};

export const useCheckPosition = () => {
const { walletId } = useWalletStore();
const { walletId } = useWalletStore();

return useQuery({
queryKey: ['hasOpenPosition', walletId],
queryFn: async () => {
if (!walletId) return { has_opened_position: false };
return useQuery({
queryKey: ['hasOpenPosition', walletId],
queryFn: async () => {
if (!walletId) return { has_opened_position: false };

const { data } = await axiosInstance.get('/api/has-user-opened-position', {
params: { wallet_id: walletId },
});
return data;
},
enabled: !!walletId,
});
const { data } = await axiosInstance.get('/api/has-user-opened-position', {
params: { wallet_id: walletId },
});
return data;
},
enabled: !!walletId,
});
};
4 changes: 2 additions & 2 deletions frontend/src/services/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export const handleTransaction = async (connectedWalletId, formData, setTokenAmo
const response = await axiosInstance.post(`/api/create-position`, formData);

const transactionData = response.data;
await sendTransaction(transactionData, transactionData.contract_address);
const { loopTransaction: transaction_hash } = await sendTransaction(transactionData, transactionData.contract_address);
console.log('Transaction executed successfully');

const openPositionResponse = await axiosInstance.get(`/api/open-position`, {
params: { position_id: transactionData.position_id },
params: { position_id: transactionData.position_id, transaction_hash },
});

openPositionResponse == openPositionResponse;
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/services/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('Transaction Functions', () => {
expect(mockSetLoading).toHaveBeenCalledWith(true);
expect(axiosInstance.post).toHaveBeenCalledWith('/api/create-position', mockFormData);
expect(axiosInstance.get).toHaveBeenCalledWith('/api/open-position', {
params: { position_id: mockTransactionData.position_id },
params: { position_id: mockTransactionData.position_id, transaction_hash: mockTransactionHash },
});
expect(mockSetTokenAmount).toHaveBeenCalledWith('');
expect(mockSetLoading).toHaveBeenCalledWith(false);
Expand All @@ -181,4 +181,4 @@ describe('Transaction Functions', () => {
expect(mockSetLoading).toHaveBeenCalledWith(false);
});
});
});
});
3,357 changes: 1,807 additions & 1,550 deletions frontend/yarn.lock

Large diffs are not rendered by default.

Loading

0 comments on commit 4725fea

Please sign in to comment.