Skip to content

Commit

Permalink
Merge pull request #222 from zkLinkProtocol/feat/add_withdrawal_api
Browse files Browse the repository at this point in the history
Feat/add withdrawal api
  • Loading branch information
zkLeonardo authored May 4, 2024
2 parents 571a0ab + 69b974f commit 5e5ae5e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
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

0 comments on commit 5e5ae5e

Please sign in to comment.