Skip to content

Commit

Permalink
fix: type guard and optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamParkhi committed Sep 23, 2024
1 parent 6ac81f5 commit 9adc56c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/site/src/utils/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const connectSnap = async (
await window.ethereum.request({
method: 'wallet_requestSnaps',
params: {
'local:http://localhost:8080': {},
[snapId]: params,
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/kleros/scout-snap.git"
},
"source": {
"shasum": "DlqfDuDIuE5TUyxf/9WDqcnL4mqh4SBnK2LUQ1IKkyg=",
"shasum": "ZPa+cVIYxWQtTVgnX38Z18BQZRsvF20Bx7OSdNBd6so=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
17 changes: 11 additions & 6 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export const onTransaction: OnTransactionHandler = async ({
]),
};
};

export const onSignature: OnSignatureHandler = async ({ signature }) => {
const { signatureMethod, from, data } = signature;
const insights: string[] = [];
Expand All @@ -332,13 +333,17 @@ export const onSignature: OnSignatureHandler = async ({ signature }) => {
signatureMethod === 'eth_signTypedData_v3' ||
signatureMethod === 'eth_signTypedData_v4'
) {
const verifyingContract = data.domain.verifyingContract;
const result = await getInsights(verifyingContract, from || 'NO_DOMAIN');

if (result.length > 0) {
insights.push(...result);
const verifyingContract = data?.domain?.verifyingContract;
if (verifyingContract) {
const result = await getInsights(verifyingContract, from || 'NO_DOMAIN');

if (result.length > 0) {
insights.push(...result);
} else {
insights.push('No insights available for this contract. Interact at your own risk.');
}
} else {
insights.push('No insights available for this contract. Interact at your own risk.');
insights.push('No verifying contract found in the signature data.');
}
}

Expand Down

0 comments on commit 9adc56c

Please sign in to comment.