Settling a Claim
The settleClaim
method settles an insurance claim based on the provided coverId
. It interacts with the blockchain to trigger the claim settlement process and provides transaction details upon success or failure.
Before calling settleClaim, it is essential to check the cover's status using the getCover
method to ensure it is "Claimable" (state value 3). If eligible, settleClaim triggers the settlement, returning transaction details, including success status, transaction hash, and the settled amount. This ensures that claims are processed based on eligibility and provides tracking information.
- For the integration of Claim Functionality in the Bet Cards Component, developers should first use the
getBetsStatusData
method. This method fetches a bettor's bet status, including bet ID, status, potential payouts, and cover status. It is crucial for tracking bet covers, verifying claim eligibility, and monitoring active or resolved bets before proceeding with the claim settlement process.
Before proceeding, users need to follow these steps:
- Pass WalletClient instance: Refer to the
Pass WalletClient Instance
for selecting the appropriatewalletClient
instance based on authentication.
Usage
import kohin from "./kohinInstance";
const claimResponse = await kohin.settleClaim({
coverId: 97, // The unique identifier of the cover for which the claim is being settled
walletClient: walletClient, // Refer to Pass WalletClient Instance section for appropriate usage
});
consolg.log("claimResponse", claimResponse);
Return Value
{
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
amount?: number; // The amount settled (optional)
transactionHash?: string; // The transaction hash of the settlement (if successful)
transactionData?: any; // Detailed transaction receipt data (if successful)
}
Error Handling
The following example demonstrates how to handle errors during the claim settlement
process:
try {
const res = await kohin.settleClaim({
coverId: Number(coverId),
walletClient: walletClient,
});
if (res.success) {
if (res.transactionData?.status === "success") {
if (res.transactionHash) {
onClaimSettleTrigger(res.transactionHash);
toastify("Claim settled successfully!", "autoSuccess");
}
} else {
onClaimSettleTrigger(res.transactionHash, true);
if (res.transactionHash) {
toastLink(
"Claim settle transaction failed!",
res.transactionHash,
"error"
);
}
}
} else {
if (res.error) {
toastify(res.error, "autoError");
}
}
} catch (error: any) {
console.error(error);
errorHandle(error, "Claim settle transaction failed!");
}
Example Response
Success Response:
{
"success": true,
"transactionHash": "0x846e820bc7662d2169259c0335bd07127bc6cdfa24f917e718c7cec65e4a9d25",
"transactionData": {
"blockNumber": 16796590,
"contractAddress": null,
"cumulativeGasUsed": 426125,
"effectiveGasPrice": 99680306396,
"from": "0x670eebd1efdf8d576e1fe554f3d8e905f28cc5a9",
"gasUsed": 426125,
"logs": [
/* log data */
],
"logsBloom": "0x04100000000000000000000000020000000000000000000000000008000000000000008000000000020000004000008000108000000000000000000000000000000000000000000000008000000800000000000000000000100000000020000000040020000000000000000000800000000000000000880000010002000000000000000000000000000000000000000008000000000000000000000104000200008020000000000000100000000000400000000001000000000000000004000000022000040000801000010000000000000000000000000100000000020000001000000000000000000000000000000000004008000000000008000102000",
"status": "success",
"to": "0x34a07094a4e49a1cc745438ba5aa033f2579daae",
"transactionHash": "0x846e820bc7662d2169259c0335bd07127bc6cdfa24f917e718c7cec65e4a9d25",
"transactionIndex": 0,
"type": "eip1559"
}
}
Error Response:
{
"success": false,
"error": "No cover available for this cover Id"
}