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

Support linking in gnosis safe profile info #7550

Merged
merged 2 commits into from
Feb 10, 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
1,570 changes: 1,570 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion protocol-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"homepage": "./",
"dependencies": {
"@apollo/client": "3.3.7",
"@audius/sdk": "*",
"@audius/common": "*",
"@audius/sdk": "*",
"@audius/stems": "0.3.10",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@radix-ui/react-slot": "^1.0.2",
"@react-spring/web": "^9.7.3",
"@reduxjs/toolkit": "1.9.7",
"@safe-global/api-kit": "2.1.0",
"@self.id/3box-legacy": "0.3.0",
"@self.id/core": "0.4.1",
"@tanstack/react-query": "5.0.5",
Expand Down
33 changes: 31 additions & 2 deletions protocol-dashboard/src/hooks/useDashboardWalletUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
getAccountWallet,
getIsAudiusProfileRefetchDisabled
} from 'store/account/hooks'
import { useEffect, useState } from 'react'
import { safeService } from 'services/Safe'

const dashboardWalletUsersBatcher = create({
fetcher: async (wallets: string[]): Promise<DashboardWalletUser[]> => {
Expand All @@ -30,17 +32,44 @@ export const getDashboardWalletUserQueryKey = (
}

export const useDashboardWalletUser = (wallet: string) => {
const [hasInitted, setHasInitted] = useState(false)
useEffect(() => {
const awaitInit = async () => {
await window.aud.awaitSetup()
setHasInitted(true)
}
awaitInit()
})

const isAudiusProfileRefetchDisabled = useSelector(
getIsAudiusProfileRefetchDisabled
)
const currentUserWallet = useSelector(getAccountWallet)
return useQuery({
queryKey: getDashboardWalletUserQueryKey(wallet),
queryFn: async () => {
const res = await dashboardWalletUsersBatcher.fetch(wallet)
return res ?? null
const isEoa = await window.aud.isEoa(wallet)
if (isEoa) {
const res = await dashboardWalletUsersBatcher.fetch(wallet)
return res ?? null
} else {
try {
// Try to get Safe address info and if nothing is found, return null
const { owners } = await safeService.getSafeInfo(wallet)
for (const owner of owners) {
const res = await dashboardWalletUsersBatcher.fetch(owner)
if (res) {
return res
}
}
return null
} catch (e) {
return null
}
}
},
enabled:
hasInitted &&
!!wallet &&
!(
isAudiusProfileRefetchDisabled &&
Expand Down
2 changes: 2 additions & 0 deletions protocol-dashboard/src/services/Audius/AudiusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getEthWallet,
getBlock,
getBlockNearTimestamp,
isEoa,
toChecksumAddress,
onSetup,
onSetupFinished,
Expand Down Expand Up @@ -80,6 +81,7 @@ export class AudiusClient {
getAverageBlockTime = getAverageBlockTime
getBlockNearTimestamp = getBlockNearTimestamp
getBlock = getBlock
isEoa = isEoa
toChecksumAddress = toChecksumAddress

// Static Util Functions
Expand Down
6 changes: 6 additions & 0 deletions protocol-dashboard/src/services/Audius/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export async function getEthWallet(this: AudiusClient) {
return this.libs.ethWeb3Manager.ownerWallet
}

export async function isEoa(this: AudiusClient, wallet: string) {
const web3 = this.libs.ethWeb3Manager.web3
const code = await web3.eth.getCode(wallet)
return code === '0x'
}

export async function getAverageBlockTime(this: AudiusClient) {
await this.hasPermissions()
const web3 = this.libs.ethWeb3Manager.web3
Expand Down
1 change: 0 additions & 1 deletion protocol-dashboard/src/services/Audius/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const initAudiusSdk = () => {
} = bootstrapConfig
const dnSelector = new DiscoveryNodeSelector({
bootstrapServices: discoveryNodes
// initialSelectedNode: 'https://discoveryprovider4.staging.audius.co'
})
audiusSdk = sdk({
appName: 'Audius Protocol Dashboard',
Expand Down
1 change: 1 addition & 0 deletions protocol-dashboard/src/services/Safe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './safe'
5 changes: 5 additions & 0 deletions protocol-dashboard/src/services/Safe/safe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SafeApiKit from '@safe-global/api-kit'

export const safeService = new SafeApiKit({
chainId: 1n
})