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

Alizas additions #2

Merged
merged 2 commits into from
Feb 28, 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 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/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "jEdGT6w7t5WQKKdMQm65ewACay1q3oFRR+Dy9hvOKZs=",
"shasum": "VEwAj9TM4OXOeabZsmGokpBue9m4rOrPyAAtyxids3o=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/harpieFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class harpieFunctions {
static provider = getProvider() //new ethers.BrowserProvider(window.ethereum)//getProvider()
/**
*
* @param {AddressLike} address
* @param {any} address
* @returns {Bool} isContract
*/
static async isContract(address: AddressLike, provider: Provider = this.provider) {
static async isContract(address: any, provider: Provider = this.provider) {
return "0x" !== (await provider.getCode(address))
}

Expand Down
16 changes: 14 additions & 2 deletions packages/snap/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { installSnap } from '@metamask/snaps-jest';
import { panel, text, heading } from '@metamask/snaps-sdk';
import {harpieFunctions} from "./harpieFunctions"
import { ethers } from 'ethers';
import { SourcifyFunctions } from './sourcifyFunctions';


describe('happyHarpie', () => {
it('should return insight of a normal eth transfer to the 3pool contract', async () => {
Expand Down Expand Up @@ -29,12 +30,23 @@ describe('happyHarpie', () => {

const harpieTransactionInformation = await harpieFunctions.createInformationMessage(transaction)

let harpieContractYesNo = await harpieFunctions.isContract(transaction["to"]);
console.log("This is the bool from isContract: ", harpieContractYesNo);
let sourcifyTxInfo:string = "You are not interacting with a smart contract";
// console.log(typeof(sourcifyTxInfo), "This is STxIn", sourcifyTxInfo);

if (harpieContractYesNo === true) {
sourcifyTxInfo = await SourcifyFunctions.evaluation(transaction.to);
// console.log(typeof(sourcifyTxInfo), "This is STxIn", sourcifyTxInfo);
}

//checks if the info rendered matches that with what onTransaction(transaction) made from simulating
//this is from jest https://jestjs.io/docs/getting-started
expect(response).toRender(
panel([
heading(harpieTransactionInformation.header),
text(harpieTransactionInformation.body)
text(harpieTransactionInformation.body),
text(sourcifyTxInfo)
]),
);
});
Expand Down
14 changes: 10 additions & 4 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import { SourcifyFunctions } from './sourcifyFunctions';
//the function needs to called onTransaction otherwise metamask doesnt see it
//https://docs.metamask.io/snaps/reference/entry-points/#ontransaction
export const onTransaction: OnTransactionHandler = async ({ transaction }) => {
console.log(transaction)
console.log("the tx:",transaction)

//get the infornmation from harpie about the tx
const harpieTransactionInformation = await harpieFunctions.createInformationMessage(transaction)
console.log(`tx info from harpie: ${String(JSON.stringify(harpieTransactionInformation))}`)
const sourcifyTxInfo = await SourcifyFunctions.getSourcifyInfo(transaction);

// need to check if interaction is w a contract not an EOA, if so run this, if not skip
let harpieContractYesNo = await harpieFunctions.isContract(transaction["to"]);
let sourcifyTxInfo:string = "You are not interacting with a smart contract";

if (harpieContractYesNo === true) {
sourcifyTxInfo = await SourcifyFunctions.evaluation(transaction.to);
}

//displays the info gathered
//panel, heading and text are from metasmask snap api:
Expand All @@ -23,8 +30,7 @@ export const onTransaction: OnTransactionHandler = async ({ transaction }) => {
content: panel([
heading(harpieTransactionInformation.header),
text(harpieTransactionInformation.body),
heading(sourcifyTxInfo.header),
text(sourcifyTxInfo.body)
text(sourcifyTxInfo),
]),
};
};
5 changes: 2 additions & 3 deletions packages/snap/src/sourcifyFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ export class SourcifyFunctions {
static async evaluation(address: any) {
const sourcifyInfo: any = await this.getSourcifyInfo(address);
const firstResult = sourcifyInfo[0]; // whole json object is an array at index 0

// console.log(firstResult); // json data object

if (firstResult.status === 'false') {
return "DANGEROUS";
return "Sourcify is reporting that the contract you are trying to interact with is not verified.";
} else {
return "SAFE";
return "Sourcify is reporting that the contract you are trying to interact with is verified!";
}
}
}
Expand Down
Loading