Skip to content

Commit

Permalink
Merge pull request #16 from dmccartney/daniel-direct-safe-link
Browse files Browse the repository at this point in the history
feat: more directly deep-link into the safe app
  • Loading branch information
dmccartney authored Jun 9, 2023
2 parents a45ee1f + e73c907 commit 858411e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions web/src/components/SafeSweepCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import _ from "lodash";
import { useState } from "react";
import { ethers } from "ethers";
import { useAccount } from "wagmi";
import { useAccount, useEnsName } from "wagmi";
import SafeAppsSDK from "@safe-global/safe-apps-sdk";
import {
BNSortComparator,
Expand Down Expand Up @@ -221,15 +221,20 @@ function useSortedMinipoolDetails(nodeAddress) {
.value();
}

function SafeAlert({ sx, label, safeAddress }) {
function SafeAlert({ sx, label, nodeAddress, safeAddress }) {
let { data: name } = useEnsName({ address: nodeAddress });
let nodeAddressOrName = name || nodeAddress;
let { connector } = useAccount();
if (connector?.id === "safe") {
// No alert when it is already open as a Safe app.
return null;
}
return (
<Card sx={sx} elevation={8} square>
<CardActionArea href={safeAppUrl({ safeAddress })} target="_blank">
<CardActionArea
href={safeAppUrl({ safeAddress, path: `/node/${nodeAddressOrName}` })}
target="_blank"
>
<CardHeader
avatar={<SafeIcon color="primary" size={"medium"} />}
title={"Open as Safe App"}
Expand Down Expand Up @@ -294,10 +299,18 @@ function SweepCardContent({ sx, nodeAddress }) {
</Alert>
)}
{hasSafeNodeAddress && (
<SafeAlert label="Node" safeAddress={nodeAddress} />
<SafeAlert
label="Node"
nodeAddress={nodeAddress}
safeAddress={nodeAddress}
/>
)}
{hasSafeWithdrawalAddress && (
<SafeAlert label="Withdrawal" safeAddress={withdrawalAddress} />
<SafeAlert
label="Withdrawal"
nodeAddress={nodeAddress}
safeAddress={withdrawalAddress}
/>
)}
{unupgradedMps.length > 0 && (
<Alert
Expand Down
3 changes: 2 additions & 1 deletion web/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export function rocketscanUrl({ network = "mainnet", node, minipool }) {
export function safeAppUrl({
safeAddress,
appUrl = process.env.REACT_APP_ROCKET_SWEEP_URL,
path = "",
}) {
return `https://app.safe.global/apps/open?safe=eth:${safeAddress}&appUrl=${appUrl}`;
return `https://app.safe.global/apps/open?safe=eth:${safeAddress}&appUrl=${appUrl}${path}`;
}

export function bnSum(arr) {
Expand Down

0 comments on commit 858411e

Please sign in to comment.