Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
[Protocol Dashboard] Hook up OAuth popup to creating dashboard wallet user [C-3562]#7104
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { useQuery } from '@tanstack/react-query' | ||
| import { create, windowScheduler } from '@yornaath/batshit' | ||
| import { audiusSdk } from 'services/Audius/sdk' | ||
| import { DashboardWalletUser } from '@audius/sdk' | ||
| const dashboardWalletUsersBatcher = create({ | ||
| fetcher: async (wallets: string[]): Promise<DashboardWalletUser[]> => { | ||
| const sdk = await audiusSdk() | ||
| const res = await sdk.dashboardWalletUsers.bulkGetDashboardWalletUsers({ | ||
| wallets | ||
| }) | ||
| return res.data | ||
| }, | ||
| resolver: (data, query) => { | ||
| return data.find(d => d.wallet.toLowerCase() === query.toLowerCase()) | ||
| }, | ||
| scheduler: windowScheduler(10) | ||
| }) | ||
| export const useDashboardWalletUser = (wallet: string) => { | ||
| return useQuery({ | ||
| queryKey: ['dashboardWalletUsers', wallet], | ||
| queryFn: async () => { | ||
| const res = await dashboardWalletUsersBatcher.fetch(wallet) | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This batches API requests for dashboard wallet users sent within a 10ms time span | ||
| return res | ||
| } | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,65 @@ | ||
| import { sdk } from '@audius/sdk' | ||
| import { | ||
| DiscoveryNodeSelector, | ||
| EntityManager, | ||
| developmentConfig, | ||
| productionConfig, | ||
| sdk, | ||
| stagingConfig | ||
| } from '@audius/sdk' | ||
| let audiusSdk = null | ||
| let instance = null | ||
| let isReady = false | ||
| let sdkResolve = null | ||
| const sdkPromise = new Promise(resolve => { | ||
| sdkResolve = resolve | ||
| }) | ||
| const initAudiusSdk = () => { | ||
| audiusSdk = sdk({ appName: 'Audius Protocol Dashboard' }) | ||
| const initAudiusSdk = ({ | ||
| signTransaction, | ||
| getAddress | ||
| }: { | ||
| signTransaction: (data: any) => Promise<string> | ||
| getAddress: () => Promise<string> | string | ||
| }) => { | ||
| const env = import.meta.env.VITE_ENVIRONMENT | ||
| const bootstrapConfig = | ||
| env === 'development' | ||
| ? developmentConfig | ||
| : env === 'staging' | ||
| ? stagingConfig | ||
| : productionConfig | ||
| const { | ||
| discoveryNodes, | ||
| entityManagerContractAddress, | ||
| web3ProviderUrl, | ||
| identityServiceUrl | ||
| } = bootstrapConfig | ||
| const dnSelector = new DiscoveryNodeSelector({ | ||
| bootstrapServices: discoveryNodes | ||
| // initialSelectedNode: 'https://discoveryprovider.staging.audius.co' | ||
| }) | ||
| instance = sdk({ | ||
| appName: 'Audius Protocol Dashboard', | ||
| services: { | ||
| auth: { signTransaction, getAddress }, | ||
| discoveryNodeSelector: dnSelector, | ||
| entityManager: new EntityManager({ | ||
| contractAddress: entityManagerContractAddress, | ||
| web3ProviderUrl: web3ProviderUrl, | ||
| identityServiceUrl: identityServiceUrl, | ||
| discoveryNodeSelector: dnSelector | ||
| }) | ||
| } | ||
| }) | ||
| sdkResolve() | ||
| isReady = true | ||
| } | ||
| initAudiusSdk() | ||
| const audiusSdk = async () => { | ||
| if (!isReady) { | ||
| await sdkPromise | ||
| } | ||
| return instance | ||
| } | ||
| export { audiusSdk } | ||
| export { audiusSdk, initAudiusSdk, isReady } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| export const decimalNetworkIdToHexNetworkId = (id: string | number) => { | ||
| const intId = Number(id) | ||
| const hexStr = intId.toString(16) | ||
| return `0x${hexStr}` | ||
| } | ||
| const MISSING_CHAIN_ERROR_CODE = 4902 | ||
| export const AUDIUS_NETWORK_ID = import.meta.env.VITE_AUDIUS_NETWORK_ID | ||
| export const ETH_NETWORK_ID = import.meta.env.VITE_ETH_NETWORK_ID | ||
| export const disableRefreshAfterNetworkChange = { value: false } | ||
| export const switchNetwork = async (to: string) => { | ||
| const chainId = decimalNetworkIdToHexNetworkId(to) | ||
| if (typeof window.ethereum !== 'undefined') { | ||
| const ethereum = window.ethereum | ||
| try { | ||
| await ethereum.request({ | ||
| method: 'wallet_switchEthereumChain', | ||
| params: [{ chainId }] | ||
| }) | ||
| } catch (error) { | ||
| if (error.code === MISSING_CHAIN_ERROR_CODE) { | ||
| try { | ||
| await ethereum.request({ | ||
| method: 'wallet_addEthereumChain', | ||
| params: [ | ||
| { | ||
| chainId: '0x102021', | ||
| chainName: 'Audius Staging', | ||
| rpcUrls: ['https://discoveryprovider.staging.audius.co/chain'] | ||
| } | ||
| ] | ||
| }) | ||
| await ethereum.request({ | ||
| method: 'wallet_switchEthereumChain', | ||
| params: [{ chainId }] | ||
| }) | ||
| } catch (error) { | ||
| console.error(error.message) | ||
| return false | ||
| } | ||
| } else { | ||
| console.error('Network switch request rejected.') | ||
| return false | ||
| } | ||
| } | ||
| } else { | ||
| console.error('MetaMask is not installed.') | ||
| return false | ||
| } | ||
| return true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Maybe
ConnectProfileButtonis big enough to be in a separate file now?