Skip to content

Commit

Permalink
feat: make the simulation publicly accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
dzimiks committed Jun 28, 2023
1 parent 2b9ceea commit c04f939
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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/Tenderly/tenderly-metamask-snap-simulate-asset-changes.git"
},
"source": {
"shasum": "ofP5HZGWp8337nJJ6Fy8wRn2eqMx0iZr6Tm5UdTDx1o=",
"shasum": "L6hmfJq6J10dJVtzOLfv47Goz5j6SUfo2FvXJToowyE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/snap/src/tenderly/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:'),
Expand All @@ -306,5 +307,7 @@ export function formatSimulationUrl(
`**Status:** ${data.transaction?.status ? 'Success ✅' : 'Failed ❌'}`,
),
text(`**${simulationUrl}**`),
text('Share simulation details with others! 🤗'),
text(`**${sharedSimulationUrl}**`),
];
}
21 changes: 19 additions & 2 deletions packages/snap/src/tenderly/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function handleSendTenderlyTransaction(origin: string) {
*/
export async function simulate(
transaction: { [key: string]: Json },
transactionOrigin: any,
transactionOrigin: string,
): Promise<Panel> {
const credentials = await fetchCredentials(transactionOrigin);

Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit c04f939

Please sign in to comment.