Skip to content

Commit

Permalink
chore(private-credential): rename contractResult to result
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmoro committed Nov 11, 2024
1 parent dd9ee57 commit f7d94fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
18 changes: 8 additions & 10 deletions packages/features/src/web-connector/routes/web-connector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export const WebConnectorRoute = () => {
}
}
const onSubmit: SubmitHandler<
UserInputForm & { contractResult?: ContractResult }
> = async ({ userInput, contractResult }) => {
UserInputForm & { result?: ContractResult }
> = async ({ userInput, result }) => {
const { id } = await windows.getCurrent()
await runtime.sendMessage({
userInput,
contractResult,
result,
windowId: id,
})
window.close()
Expand All @@ -88,13 +88,11 @@ export const WebConnectorRoute = () => {
setLoading(false)
}
}
const confirm = async ({
contractResult,
}: { contractResult?: ContractResult }) => {
const confirm = async ({ result }: { result?: ContractResult }) => {
const { id } = await windows.getCurrent()
await runtime.sendMessage({
userConfirmed: true,
contractResult,
result,
windowId: id,
})
if (request.emitConnected) {
Expand All @@ -121,18 +119,18 @@ export const WebConnectorRoute = () => {
const eventListener = (event: MessageEvent) => {
if (event.data.type === "validate-credential-result") {
return confirm({
contractResult: {
result: {
type: event.data.type,
result: event.data.result,
error: event.data.error,
},
})
}
if (request.inputType === "confirmation")
return confirm({ contractResult: event.data.result })
return confirm({ result: event.data.result })
return onSubmit({
userInput: event.data.userInput,
contractResult: event.data.result,
result: event.data.result,
})
}
// biome-ignore lint/correctness/useExhaustiveDependencies: wontdo
Expand Down
12 changes: 6 additions & 6 deletions packages/web-provider/src/mina-network/mina-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export const createMinaProvider = async (): Promise<
const stringifiedCredential = JSON.stringify(credential)

try {
const { value: userConfirmed, contractResult } =
const { value: userConfirmed, result } =
await showUserPrompt<boolean>({
inputType: "confirmation",
contract: "validate-credential",
Expand All @@ -354,20 +354,20 @@ export const createMinaProvider = async (): Promise<
throw createProviderRpcError(4001, "User Rejected Request")
}

if (contractResult?.error) {
if (result?.error) {
throw createProviderRpcError(
4100,
`Credential validation failed: ${contractResult.error}`,
`Credential validation failed: ${result.error}`,
)
}

if (!contractResult?.result) {
if (!result?.result) {
throw createProviderRpcError(4100, "Missing validation result")
}

try {
await _vault.storePrivateCredential(contractResult.result)
return { success: contractResult.result }
await _vault.storePrivateCredential(result.result)
return { success: result.result }
} catch (error: any) {
throw createProviderRpcError(
4100,
Expand Down
6 changes: 3 additions & 3 deletions packages/web-provider/src/utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ContractResult = {

type PromptResult<T> = {
value: T
contractResult?: ContractResult
result?: ContractResult
}

export const showUserPrompt = async <T extends boolean | string = boolean>({
Expand Down Expand Up @@ -48,15 +48,15 @@ export const showUserPrompt = async <T extends boolean | string = boolean>({
if (response.userConfirmed) {
return resolve({
value: true as T,
contractResult: response.contractResult,
result: response.result,
})
}
return reject(new Error("4001 - User Rejected Request"))
}
if (response.userInput.length > 0) {
return resolve({
value: response.userInput,
contractResult: response.contractResult,
result: response.result,
})
}
return reject(new Error("4100 - Unauthorized"))
Expand Down

0 comments on commit f7d94fa

Please sign in to comment.