Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add withdrawal api #222

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/transfers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const fetch = () => {
if (!isConnected.value) return;
transfersHistoryStore.requestRecentTransfers();
failedDepositHistory.requestFailedDepositTransfers();
transfersHistoryStore.requestWithdrawals();
};
fetch();

Expand Down
41 changes: 38 additions & 3 deletions store/zksync/transfersHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,24 @@ export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistor
url.searchParams.set("limit", TRANSACTIONS_FETCH_LIMIT.toString());
return url;
});
const transfers = ref<Transfer[]>([]);

const {
canLoadMore: canLoadMoreWithdrawals,
loadNext: loadNextWithdrawals,
reset: resetPaginatedWithdrawalsRequest,
} = usePaginatedRequest<Api.Response.Transfer>(() => {
if (!eraNetwork.value.blockExplorerApi)
throw new Error(`Block Explorer API is not available on ${eraNetwork.value.name}`);

const url = new URL(
`/address/${account.value.address}/withdrawalTransfers?limit=100`,
eraNetwork.value.blockExplorerApi
);
return url;
});

const transfers = ref<Transfer[]>([]);
const withdrawals = ref<Transfer[]>([]);
const {
inProgress: recentTransfersRequestInProgress,
error: recentTransfersRequestError,
Expand All @@ -90,10 +106,27 @@ export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistor
}
const response = await loadNext();
const mappedTransfers = response.items.map(mapApiTransfer);
useZkSyncWithdrawalsStore().updateWithdrawals();
transfers.value = filterOutDuplicateTransfers(mappedTransfers);
},
{ cache: 30000 }
);

const {
inProgress: requestWithdrawalsInProgress,
error: requestWithdrawalsError,
execute: requestWithdrawals,
reset: restRequestWithdrawals,
reload: reloadRequestWithdrawals,
} = usePromise(
async () => {
if (withdrawals.value.length) {
restRequestWithdrawals();
}
const response = await loadNextWithdrawals();
const mappedTransfers = response.items.map(mapApiTransfer);
withdrawals.value = filterOutDuplicateTransfers(mappedTransfers);
//TODO put withdrawals into local storage
for (const withdrawal of transfers.value.filter((e) => e.type === "withdrawal")) {
for (const withdrawal of withdrawals.value.filter((e) => e.type === "withdrawal")) {
if (!userTransactions.value.find((e) => e.transactionHash === withdrawal.transactionHash)) {
const eraNetworks = getNetworkInfo(withdrawal);
const obj = {
Expand Down Expand Up @@ -128,6 +161,7 @@ export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistor
});
}
}
useZkSyncWithdrawalsStore().updateWithdrawals();
},
{ cache: 30000 }
);
Expand Down Expand Up @@ -169,5 +203,6 @@ export const useZkSyncTransfersHistoryStore = defineStore("zkSyncTransfersHistor
previousTransfersRequestInProgress,
previousTransfersRequestError,
requestPreviousTransfers,
requestWithdrawals,
};
});
2 changes: 1 addition & 1 deletion store/zksync/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () =>
const transfers: { items: any[] } = await $fetch(
`${eraNetwork.value.blockExplorerApi}/address/${
account.value.address
}/transfers?limit=${TRANSACTIONS_FETCH_LIMIT.toString()}`
}/withdrawalTransfers?limit=${TRANSACTIONS_FETCH_LIMIT.toString()}`
);
const withdrawals = transfers.items.filter((e) => e.type === "withdrawal" && e.token && e.amount);
for (const withdrawal of withdrawals) {
Expand Down
Loading