Skip to content

Commit

Permalink
feat: add transaction history to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Jul 10, 2024
1 parent 7e814a2 commit b47e3b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 6 additions & 6 deletions apps/staking/app/faucet/AuthModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ export const AuthModule = () => {
}

const { hash, error, faucetError, history } = res;

if (history && history.length) {
setTransactionHistory(history);
}

if (hash) {
setTransactionHash(hash);
setFormState(FORM_STATE.SUCCESS);

if (history && history.length) {
setTransactionHistory(history);
}

return resolve(hash);
}

Expand Down Expand Up @@ -356,7 +356,7 @@ export const AuthModule = () => {
</>
) : null}

{formState === FORM_STATE.SUCCESS && transactionHistory && transactionHistory.length > 0 ? (
{transactionHistory && transactionHistory.length > 0 ? (
<FaucetTransactions transactionHistory={transactionHistory} />
) : null}

Expand Down
18 changes: 15 additions & 3 deletions apps/staking/app/faucet/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ import {

class FaucetError extends Error {
faucetError: FAUCET_ERROR;
constructor(faucetError: FAUCET_ERROR, message: string) {
history?: Array<TransactionHistory>;

constructor(faucetError: FAUCET_ERROR, message: string, history?: Array<TransactionHistory>) {
super(message);
this.name = 'FaucetError';
this.faucetError = faucetError;
this.history = history;
}
}

Expand Down Expand Up @@ -227,7 +230,12 @@ export async function transferTestTokens({
hoursBetweenTransactions,
})
) {
throw new FaucetError(FAUCET_ERROR.ALREADY_USED, dictionary('alreadyUsed'));
const transactionHistory = getTransactionHistory({ db, address: targetAddress });
throw new FaucetError(
FAUCET_ERROR.ALREADY_USED,
dictionary('alreadyUsed'),
transactionHistory
);
}

usedOperatorAddress = true;
Expand Down Expand Up @@ -360,7 +368,11 @@ export async function transferTestTokens({
} catch (error) {
console.error(error);
if (error instanceof FaucetError) {
result = new FaucetResult({ error: error.message, faucetError: error.faucetError });
result = new FaucetResult({
error: error.message,
faucetError: error.faucetError,
history: error.history,
});
} else if (error instanceof Error) {
result = new FaucetResult({ error: error.message });
} else {
Expand Down

0 comments on commit b47e3b4

Please sign in to comment.