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

Fix: adds missing log and improves typing #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions pages/issuer/issue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<h2 class="text-xl font-semibold">Updates</h2>
<ol class="list-decimal">
<li v-for="message in logMessages">
[{{ message.source }}<p v-if="message.target !== undefined"> -> {{ message.target }}</p>] {{ message.message }}
[{{ message.source }}<span v-if="message.target !== undefined"> -> {{ message.target }}</span>] {{ message.message }}
</li>
</ol>
</div>
Expand All @@ -65,7 +65,7 @@
console.log(`createCredentialData..... ${createdCredential}`)
CredentialData.value = createdCredential;
step.value = Step.CONNECTION_SETUP;
addToLog("Credential Data saved", 'Issuer', null)
addToLog("Credential Data saved", 'Issuer', undefined)
}

function SendCredentialToWallet(walletConnectionID: string) {
Expand All @@ -82,7 +82,7 @@
addToLog("Credential received successfully!", "Wallet", "Issuer")
}

function addToLog(message: string, source: string = "Issuer", target: string | null = "Wallet") {
function addToLog(message: string, source: string = "Issuer", target: string | undefined = "Wallet") {
logMessages.value.push({
source: source,
target: target,
Expand Down
12 changes: 6 additions & 6 deletions pages/verifier/verify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
</div>
<div v-if="step===Step.REQUESTING_CREDENTIALS">Requesting Credentials...</div>
<VerifierIndyWalletCredentialRequest v-if="step===Step.REQUESTING_CREDENTIALS" :connectionID="WalletConnectionID" @verifiable-credential-proof="displayProof"/>
<VerifierIndyWalletCredentialRequest v-if="step===Step.REQUESTING_CREDENTIALS" :connectionID="WalletConnectionID" @add-to-log="addToLog" @verifiable-credential-proof="displayProof"/>
<div v-if="step===Step.DONE" class="container mx-auto max-w-4xl bg-white rounded-lg shadow-lg p-6 my-8">
<h2 class="text-2xl font-semibold mb-4 text-gray-800">Credential Information</h2>
<div class="space-y-2 font-medium text-gray-700">
Expand All @@ -39,15 +39,15 @@
<h2 class="text-xl font-semibold">Updates</h2>
<ol class="list-decimal">
<li v-for="message in logMessages">
[{{ message.source }}<p v-if="message.target !== undefined"> -> {{ message.target }}</p>] {{ message.message }}
[{{ message.source }}<span v-if="message.target !== undefined"> -> {{ message.target }}</span>] {{ message.message }}
</li>
</ol>
</div>
</div>
</template>

<script setup lang="ts">
import {ActionLog} from "~/composables/VerifiableCredential";
import type {ActionLog} from "~/composables/VerifiableCredential";

definePageMeta({layout: 'leo-inc'})

Expand All @@ -63,14 +63,14 @@
const proofRequestDegree = ref("");
const proofRequestDocumentNumber = ref("");
const logMessages = ref([] as ActionLog[]);
let createdInterval: number = null
let createdInterval: number

const generateQRCodeForConnection = () => {
createConnection(false).then(({invitationURL, connectionID}) => {
console.log(`invitation.....${invitationURL}`)
invitationLink.value = invitationURL
WalletConnectionID.value = connectionID
addToLog('Creating connection QRCode', 'Verifier', null)
addToLog('Creating connection QRCode', 'Verifier', undefined)
createdInterval = setInterval(manageIntervalForAcceptedInvitation, 3000);
})
}
Expand Down Expand Up @@ -112,7 +112,7 @@
proofRequestDocumentNumber.value = data.documentNumber
}

function addToLog(message: string, source: string = "Issuer", target?: string = "Wallet") {
function addToLog(message: string, source: string = "Issuer", target: string | undefined = "Wallet") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? When writing target?: string, it is already string | undefined, and you don't need to give the target argument to the method. So you can write:

addToLog('Creating connection QRCode', 'Verifier')

That simplifies the code a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have "Wallet" as a default "target" but can be optionally set to null/undefined.

Using target?: string = "wallet" was what I wanted initially, but it turned out to syntactically incorrect. It's not possible to use ? with a default value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is to use target? : string without a default. But in that case, I'll have to put "wallet" everywhere, and I will not need to put undefined only in one place.

My solution above looked better for me, since I won't need to put "Wallet" everywhere, except for one place where I will need to put undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't accept your solution in production code, because somebody skimming over your code will not realize that addToLog uses wallet as the target by default. It will only get clear once you read the definition of addToLog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only get clear once you read the definition of addToLog.

Reading a function's signature is a requirement to understanding what it does. It only becomes bad if you need to read the implementation of the function to understand what it does.

Since the default value "wallet" is written in the signature, it's not bad.

Copy link
Member Author

@lanterno lanterno Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, looking at it..

addToLog('message', 'Verifier') // [Verifier -> Wallet]
addToLog('message', 'Verifier', null) // [Verifier]

looks "counter-intuitive" to me.
This is why I felt uncomfortable as well. But since you strongly see it's not clean, I'll switch to the other approach, with the default being null, and wallet to be added where it's needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reading code, my preference is:

  1. understanding what a method does by its name
  2. include the context, comments
  3. look at the signature, method comments
  4. look at the implementation

When reading lots of code, even having to look at the context, or, worse, looking at the signature of a method, slows down a lot.

Of course this doesn't apply to important methods, where often it is needed to actually look at the method comments, or even the implementation.

But something trivial as addToLog should not need further investigation.

Now, addToLog could've been named addToLogDefaultToWalletDestination, but that's also slowing down reading a lot.

Anyway, as I wrote above, don't worry about this for the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit different from how I think about it. I would be happy to discuss that a bit further in person.

Anyway, as I wrote above, don't worry about this for the moment.

Does this equal a PR approval then?

logMessages.value.push({
source: source,
target: target,
Expand Down