Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testnets #152

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/app/[pohid]/[chain]/[request]/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
const errorRef = useRef(false);
const offChainRef = useRef(false);
const [action, setAction] = useState(ActionType.NONE);
const [canAdvance, setCanAdvance] = useState(true);
const [didIVouchFor, setDidIVouchFor] = useState(false);
const [isVouchOnchain, setIsVouchOnchain] = useState(false);

Expand Down Expand Up @@ -205,7 +206,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
onFail() {
!errorRef.current && toast.error("Advance is not possible");
errorRef.current = true;
//setAction(ActionType.VOUCH);
setCanAdvance(false);
},
}),
[loading],
Expand Down Expand Up @@ -240,6 +241,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({

useEffect(() => {
if (action === ActionType.ADVANCE && !revocation) {
setCanAdvance(true);
prepareAdvance({
args: [
requester,
Expand Down Expand Up @@ -267,6 +269,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
revocation,
chain,
userChainId,
canAdvance,
]);

useEffect(() => {
Expand Down Expand Up @@ -405,7 +408,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
/>
) : null}
<button
disabled={pending || userChainId !== chain.id}
disabled={pending || userChainId !== chain.id || !canAdvance}
className="btn-main mb-2"
onClick={advance}
>
Expand Down
34 changes: 25 additions & 9 deletions src/app/[pohid]/[chain]/[request]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,32 @@ export default async function Request({ params }: PageProps) {
contractData.arbitrationInfo.extraData,
);

const onChainVouches = request.claimer.vouchesReceived.map(
(v) => v.from.id as Address,
);
let onChainVouches: Array<Address> = [];

// This are vouches to be read directly from supabase, ie, vouches still not processed
// (only necessary before advance state in vouching status)
const offChainVouches: {
voucher: Address;
expiration: number;
signature: Hash;
}[] = [];

if (request.status.id === "vouching") {
onChainVouches = request.claimer.vouchesReceived.map(
(v) => v.from.id as Address,
);
offChainVouches.push(
...(await getOffChainVouches(chain.id, request.claimer.id, pohId)),
);

// If offChain voucher has been registered before, it will appear at subgraph,
// so we remove it from onChain since the contract has no data of it
onChainVouches = onChainVouches.filter(
(onChainVoucher) =>
offChainVouches.filter((voucher) => voucher.voucher === onChainVoucher)
.length === 0,
);
} else {
// For any other request status there are registered vouches for this request
onChainVouches = request.vouches.map((v) => v.voucher.id as Address);
}

const hasExpired = () => {
Expand Down Expand Up @@ -456,7 +466,7 @@ export default async function Request({ params }: PageProps) {
)}
{vourchesForData.find((v) => v) && (
<div className="text-secondaryText mt-8 flex flex-col">
Vouched for
This PoHID vouched for
<div className="flex flex-wrap gap-2">
{vourchesForData.map(async (vouch, idx) => {
const vouchLocal = await Promise.resolve(vouch);
Expand All @@ -482,22 +492,28 @@ export default async function Request({ params }: PageProps) {
<div className="w-full flex-wrap justify-between gap-2 md:flex-row md:items-center">
{vouchersData.find((v) => v) && (
<div className="text-secondaryText mt-8 flex flex-col">
Vouched by
{request.status.id === "vouching"
? "Available vouches for this PoHID"
: "Vouched for this request"}
<div className="flex flex-wrap gap-2">
{vouchersData.map(async (vouch, idx) => {
const vouchLocal = await Promise.resolve(vouch);
return (
<Vouch
isActive={vouchLocal.vouchStatus?.isValid}
reason={vouchLocal.vouchStatus?.reason}
reason={
request.status.id === "vouching"
? vouchLocal.vouchStatus?.reason
: undefined
}
name={vouchLocal.name}
photo={vouchLocal.photo}
idx={idx}
href={`/${prettifyId(vouchLocal.pohId!)}`}
pohId={vouchLocal.pohId}
address={vouchLocal.voucher}
isOnChain={vouchLocal.isOnChain}
reducedTooltip={false}
reducedTooltip={request.status.id !== "vouching"}
/>
);
})}
Expand Down
19 changes: 19 additions & 0 deletions src/contracts/apis/APIPoH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,23 @@ export class APIPoH {
});
}
}

public static async isValidVouch(
_chainId: SupportedChainId,
_voucher: Address,
_pohId: Address,
_address: Address,
): Promise<boolean> {
const apiReader = APIPoH.getApiReader(_chainId);
let out: boolean = false;
try {
out = await apiReader.get("vouches", [_voucher, _pohId, _address]);
return out;
} catch (error) {
throw new Error({
statusCode: 520,
title: "Error while reading ProofOfHumanity",
});
}
}
}
Loading