Skip to main content

Fetching Cover Details

The getCover method retrieves detailed information about a specific insurance cover based on the provided coverId. This includes critical details such as the bet associated with the cover, coverage amount, premium, and the current state of the cover. The primary application of this method is to check the status of an insurance cover.

The cover's status is determined according to its state, represented as an enum:

  • 0: Active – The cover is currently active and can be used.
  • 1: Claimed – The cover has already been claimed.
  • 2: Expired – The cover has expired and is no longer valid.
  • 3: Claimable – The cover can be claimed, as the conditions for a claim are met.
  • 4: Manual – The cover's status requires manual intervention or is in a special state.

By using this method, users can monitor the cover’s state and take appropriate actions based on its current status.

Usage

import kohin from "./kohinInstance";

const coverDetails = await kohin.getCover({ coverId: 97 });

if (coverDetails.success) {
console.log("Cover Details:", coverDetails.cover);
toastify("Cover details fetched successfully!", "autoSuccess");
} else {
console.error("Error fetching cover details:", coverDetails.error);
toastify(`Error: ${coverDetails.error}`, "autoError");
}

Parameters

The getCover method accepts a parameter object with the following structure:

{
coverId: number; // Unique identifier for the cover
}

Return Value

The getCover method returns an object with the following structure:

{
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
cover?: Cover; // Cover details if the operation was successful
}

The Cover interface provides detailed information about the cover:

export interface Cover {
betId: bigint; // Unique identifier for the bet
betType: number; // Numerical representation of the bet type (e.g., 1 for "Combo")
coverId: bigint; // Unique identifier for the cover
coverageAmount: bigint; // Total amount of coverage
depositId: number; // Identifier for the deposit
insured: string; // Address of the insured party
odds: bigint; // Odds associated with the cover
premium: bigint; // Premium paid for the cover
settlementAmount: bigint; // Settlement amount (if applicable)
state: number; // State of the cover (e.g., active, settled)
}

Error Handling

The following example demonstrates how to handle errors while fetching cover details:

try {
const coverDetails = await kohin.getCover({ coverId: 97 });

if (coverDetails.success) {
toastify("Cover details fetched successfully!", "autoSuccess");
console.log("Cover Details:", coverDetails.cover);
} else {
toastify(`Error: ${coverDetails.error}`, "autoError");
console.error("Error fetching cover details:", coverDetails.error);
}
} catch (error: any) {
toastify(
"Unexpected error fetching cover details. Please try again.",
"autoError"
);
console.error("Unexpected error:", error);
}

Example Responses

Success Response:


{
"success": true,
"cover": {
"betId": 123456789n,
"betType": 1,
"coverId": 97n,
"coverageAmount": 100000000n,
"depositId": 1234,
"insured": "0xAbC1234567890DEF1234567890abcdef12345678",
"odds": 2578721433438n,
"premium": 53976024n,
"settlementAmount": 0n,
"state": 1
}
}

Error Response:

{
"success": false,
"error": "Cover ID not found."
}

Additional Use Case: Checking Claim Status

You can use the getCover method to check the claim status of a cover:

import kohin from "./kohinInstance";

const checkClaimStatus = async () => {
try {
const claimStatusRes = await kohin.getCover({ coverId: 97 });

if (claimStatusRes.success && claimStatusRes.cover?.state) {
const state = claimStatusRes.cover.state;
toastify(`Claim status: ${state}`, "autoSuccess");
} else {
toastify("Fetching claim status went wrong! Try again!", "autoError");
}
} catch (error: any) {
toastify(
"Unexpected error fetching claim status. Please try again.",
"autoError"
);
console.error("Error:", error);
}
};