Auction Actions
The auction system provides several Redux actions for managing bids.
The stakeAuctionBid
action handles placing new bids:
// src/oada/actions.ts
// Async thunk for placing bids in the stake auction
export const stakeAuctionBid = createAsyncThunk<
BasicResponse<string>,
StakeAuctionBidRequest,
{
dispatch: AppDispatch;
state: RootState;
extra: Services;
rejectValue: FailResponse;
}
>("stakeAuctionBid", async (request: StakeAuctionBidRequest, thunkApi) => {
const wallet = thunkApi.getState().wallet.wallet!;
const [utxos, changeAddress] = await getWalletUtxos(wallet);
const ownerPkh = bech32AddressToPaymentPkh(changeAddress);
const stakeAddress = addressToStakeAddress(changeAddress);
if (stakeAddress === null) {
return {
tag: "Fail",
contents: `Could not get stake address from ${changeAddress}`,
};
}
const serverRequest = {
ownerPkh,
stakeAddressBech32: request.stakeAddressBech32,
bidType: request.bidType,
bidApy: BigInt(request.bidApy.toString()),
bidValue: request.bidValue,
};
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json;charset=UTF-8",
},
body: Json.stringify(serverRequest),
};
const rawResponse = await fetch(
`${oadaEndpointsUrl}/stake-auction-bid`,
requestOptions
);
return await getRecipeBuildSendTx(utxos, changeAddress, rawResponse);
});
The cancelStakeAuctionBid
action handles canceling existing bids:
// src/oada/actions.ts
// Async thunk for canceling existing stake auction bids
export const cancelStakeAuctionBid = createAsyncThunk<
BasicResponse<string>,
CancelStakeAuctionBidRequest,
{
dispatch: AppDispatch;
state: RootState;
extra: Services;
rejectValue: FailResponse;
}
>(
"cancelStakeAuctionBid",
async (request: CancelStakeAuctionBidRequest, thunkApi) => {
const wallet = thunkApi.getState().wallet.wallet!;
const [utxos, changeAddress] = await getWalletUtxos(wallet);
const ownerPkh = bech32AddressToPaymentPkh(changeAddress);
const serverRequest = {
ownerPkh,
txOutRef: bidIdToTxOutRef(request.bidId),
};
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json;charset=UTF-8",
},
body: Json.stringify(serverRequest),
};
const rawResponse = await fetch(
`${oadaEndpointsUrl}/cancel-stake-auction-bid`,
requestOptions
);
return await getRecipeBuildSendTx(utxos, changeAddress, rawResponse);
}
);
Last updated