From c04f939a980d96bbc9bf23b9c7ad217d06f30174 Mon Sep 17 00:00:00 2001 From: dzimiks Date: Wed, 28 Jun 2023 15:12:06 +0200 Subject: [PATCH] feat: make the simulation publicly accessible --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/tenderly/formatter.ts | 3 +++ packages/snap/src/tenderly/simulation.ts | 21 +++++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index ba35ddf..dd716b4 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/Tenderly/tenderly-metamask-snap-simulate-asset-changes.git" }, "source": { - "shasum": "ofP5HZGWp8337nJJ6Fy8wRn2eqMx0iZr6Tm5UdTDx1o=", + "shasum": "L6hmfJq6J10dJVtzOLfv47Goz5j6SUfo2FvXJToowyE=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/tenderly/formatter.ts b/packages/snap/src/tenderly/formatter.ts index 648aaf3..a46182f 100644 --- a/packages/snap/src/tenderly/formatter.ts +++ b/packages/snap/src/tenderly/formatter.ts @@ -298,6 +298,7 @@ export function formatSimulationUrl( credentials: TenderlyCredentials, ): Component[] { const simulationUrl = `https://dashboard.tenderly.co/${credentials.userId}/${credentials.projectId}/simulator/${data.simulation?.id}`; + const sharedSimulationUrl = `https://dashboard.tenderly.co/shared/simulation/${data.simulation?.id}`; return [ heading('Tenderly Dashboard:'), @@ -306,5 +307,7 @@ export function formatSimulationUrl( `**Status:** ${data.transaction?.status ? 'Success ✅' : 'Failed ❌'}`, ), text(`**${simulationUrl}**`), + text('Share simulation details with others! 🤗'), + text(`**${sharedSimulationUrl}**`), ]; } diff --git a/packages/snap/src/tenderly/simulation.ts b/packages/snap/src/tenderly/simulation.ts index 144513e..0636d2a 100644 --- a/packages/snap/src/tenderly/simulation.ts +++ b/packages/snap/src/tenderly/simulation.ts @@ -25,7 +25,7 @@ export async function handleSendTenderlyTransaction(origin: string) { */ export async function simulate( transaction: { [key: string]: Json }, - transactionOrigin: any, + transactionOrigin: string, ): Promise { const credentials = await fetchCredentials(transactionOrigin); @@ -72,7 +72,24 @@ async function submitSimulation( }, }, ); - return response.json(); + + const parsedResponse = await response.json(); + + // Make the simulation publicly accessible + if (parsedResponse?.simulation?.id) { + await fetch( + `https://api.tenderly.co/api/v1/account/${credentials.userId}/project/${credentials.projectId}/simulations/${parsedResponse.simulation.id}/share`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Access-Key': credentials.accessKey, + }, + }, + ); + } + + return parsedResponse; } /**