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

Add subscan links to solo multisigs or proxy #345

Merged
merged 3 commits into from
Sep 13, 2023
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
17 changes: 14 additions & 3 deletions packages/ui/src/hooks/useSubscanLink.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { useCallback } from 'react'
import { useNetwork } from '../contexts/NetworkContext'
import { getSubscanExtrinsicLink } from '../utils'
import { getSubscanExtrinsicLink, getSubscanAccountLink } from '../utils'

export const useGetSubscanLinks = () => {
const { selectedNetworkInfo } = useNetwork()

const _getSubscanExtrinsicLink = useCallback(
(txHash: string) => getSubscanExtrinsicLink(selectedNetworkInfo?.explorerNetworkName, txHash),
[selectedNetworkInfo]
)

const _getSubscanAccountLink = useCallback(
(account?: string, multisig = false) =>
getSubscanAccountLink(selectedNetworkInfo?.explorerNetworkName, account, multisig),
[selectedNetworkInfo]
)
return {
getSubscanExtrinsicLink: (txHash: string) =>
getSubscanExtrinsicLink(selectedNetworkInfo?.explorerNetworkName, txHash)
getSubscanExtrinsicLink: _getSubscanExtrinsicLink,
getSubscanAccountLink: _getSubscanAccountLink
}
}
24 changes: 22 additions & 2 deletions packages/ui/src/pages/Home/MultisigActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,34 @@ import { HiOutlinePencil } from 'react-icons/hi2'
import { MdOutlineLockReset as LockResetIcon } from 'react-icons/md'
import { useMultiProxy } from '../../contexts/MultiProxyContext'
import { useModals } from '../../contexts/ModalsContext'
import { HiOutlineArrowTopRightOnSquare as LaunchIcon } from 'react-icons/hi2'
import { useGetSubscanLinks } from '../../hooks/useSubscanLink'

interface MultisigActionMenuProps {
withSendButton?: boolean
}

const MultisigActionMenu = ({ withSendButton = true }: MultisigActionMenuProps) => {
const { selectedHasProxy, selectedIsWatched } = useMultiProxy()
const { selectedHasProxy, selectedIsWatched, selectedMultiProxy } = useMultiProxy()
const { setIsEditModalOpen, setIsChangeMultiModalOpen, setIsSendModalOpen } = useModals()
const { getSubscanAccountLink } = useGetSubscanLinks()

const options: MenuOption[] = useMemo(() => {
const opts = [
{
text: 'Edit names',
icon: <HiOutlinePencil size={20} />,
onClick: () => setIsEditModalOpen(true)
},
{
text: 'Subscan',
icon: <LaunchIcon size={20} />,
onClick: () =>
window.open(
selectedMultiProxy?.proxy
? getSubscanAccountLink(selectedMultiProxy?.proxy)
: getSubscanAccountLink(selectedMultiProxy?.multisigs[0].address, true)
)
}
]

Expand All @@ -33,7 +46,14 @@ const MultisigActionMenu = ({ withSendButton = true }: MultisigActionMenuProps)
})

return opts
}, [selectedHasProxy, selectedIsWatched, setIsChangeMultiModalOpen, setIsEditModalOpen])
}, [
getSubscanAccountLink,
selectedHasProxy,
selectedIsWatched,
selectedMultiProxy,
setIsChangeMultiModalOpen,
setIsEditModalOpen
])

return (
<>
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/utils/getSubscanAccountLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const getSubscanAccountLink = (
network?: string,
account?: string,
multisigTab?: boolean
) => {
if (!network || !account) return

return `https://${network}.subscan.io/account/${account}${
multisigTab ? '?tab=multisig_extrinsic' : ''
}`
}
3 changes: 2 additions & 1 deletion packages/ui/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './isProxyCall'
export * from './decode'
export * from './getDisplayAddress'
export * from './bnUtils'
export * from './getSubscanLink'
export * from './getSubscanExtrinsicLink'
export * from './getSubscanAccountLink'
export * from './getExtrinsicName'
export * from './getDisplayArgs'
Loading