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

Use actual call to submit a secret recovery request #575

Merged
merged 1 commit into from
May 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@creativecommons/cc-assets": "^0.1.0",
"@logion/client": "^0.45.0-7",
"@logion/client": "^0.45.0-8",
"@logion/client-browser": "^0.3.5",
"@logion/crossmint": "^0.1.32",
"@logion/extension": "^0.8.1-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ function mockClient(expectedLocId: UUID, data: { locType: LocType, status: LocRe
return Promise.resolve(undefined);
}
}
},
secretRecovery: {
createSecretRecoveryRequest: () => {
return Promise.resolve(undefined);
}
}
} as unknown as LogionClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,49 @@ import { useCallback, useState } from "react";
import Alert from "src/common/Alert";
import Icon from "src/common/Icon";
import CopyPasteButton from "src/common/CopyPasteButton";
import { useLogionChain } from "../../../logion-chain";
import { UUID } from "@logion/node-api";

export default function SecretRecoveryRequestFormPage() {
const { colorTheme } = useCommonContext();
const { control: secretControl, trigger: secretTrigger, formState: { errors: secretErrors }, setValue, getValues } = useForm<SecretFormValues>();
const { control: identityControl, trigger: identityTrigger, formState: { errors: identityErrors } } = useForm<IdentityFormValues>();
const { control: identityControl, trigger: identityTrigger, formState: { errors: identityErrors }, getValues: getIdentityValues } = useForm<IdentityFormValues>();
const [ error, setError ] = useState<string>();
const [ submitting, setSubmitting ] = useState(false);
const [ submitted, setSubmitted ] = useState(false);
const { client } = useLogionChain();

const submit = useCallback(async () => {
setError(undefined);
setSubmitting(true);
setSubmitted(false);
const results = await Promise.all([ secretTrigger(), identityTrigger() ]);
const formError = !(results[0] && results[1]);
if(formError) {
const { locId, secretName, challenge } = getValues();
const requesterIdentityLocId = UUID.fromAnyString(locId);
if(formError || requesterIdentityLocId === undefined) {
setError("Some information above is not valid");
} else {
try {
// TODO: actually submit data
const identity = getIdentityValues();
await client!.secretRecovery.createSecretRecoveryRequest({
requesterIdentityLocId,
secretName,
challenge,
userIdentity: {
firstName: identity.firstName,
lastName: identity.lastName,
email: identity.email,
phoneNumber: identity.phoneNumber,
},
userPostalAddress: {
line1: identity.line1,
line2: identity.line2,
postalCode: identity.postalCode,
city: identity.city,
country: identity.country,
},
})
setSubmitted(true);
} catch(e) {
if(e instanceof Error) {
Expand All @@ -42,7 +65,7 @@ export default function SecretRecoveryRequestFormPage() {
}
}
setSubmitting(false);
}, [ secretTrigger, identityTrigger ]);
}, [ secretTrigger, identityTrigger, client, getValues, getIdentityValues ]);

return (
<div className="SecretRecoveryRequestFormPage">
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3216,15 +3216,15 @@ __metadata:
languageName: node
linkType: hard

"@logion/client@npm:^0.45.0-7":
version: 0.45.0-7
resolution: "@logion/client@npm:0.45.0-7"
"@logion/client@npm:^0.45.0-8":
version: 0.45.0-8
resolution: "@logion/client@npm:0.45.0-8"
dependencies:
"@logion/node-api": ^0.30.0
axios: ^1.6.7
luxon: ^3.4.4
mime-db: ^1.52.0
checksum: 37679a03af0afa468e6378c430fb31923397c268f94f8a4edaeece8d65fc38e0871dda9f19b96faf05d6be4c423ab9f2c5ce5573af1ca7e76e645eb5832c93a0
checksum: 8a7d999934c1e051f5cf0b76ac6f5dffe42a8676aaf79aeac2f5846ae700fb63a4d7fb9b3d1b7561855d89b1c9b0dce5535429a220f9c1cc82730e0c315beb41
languageName: node
linkType: hard

Expand Down Expand Up @@ -12106,7 +12106,7 @@ __metadata:
"@babel/preset-react": ^7.23.3
"@babel/preset-typescript": ^7.23.3
"@creativecommons/cc-assets": ^0.1.0
"@logion/client": ^0.45.0-7
"@logion/client": ^0.45.0-8
"@logion/client-browser": ^0.3.5
"@logion/crossmint": ^0.1.32
"@logion/extension": ^0.8.1-1
Expand Down
Loading