This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
audius-backend-instance.ts
90 lines (85 loc) · 3.31 KB
/
audius-backend-instance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as nativeLibs from '@audius/sdk/dist/native-libs'
import type { AudiusLibs } from '@audius/sdk/dist/native-libs'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { audiusBackend } from 'audius-client/src/common/services/audius-backend'
import Config from 'react-native-config'
import { track } from 'app/utils/analytics'
import { monitoringCallbacks } from './monitoringCallbacks'
import { getFeatureEnabled } from './remote-config'
import { remoteConfigInstance } from './remote-config/remote-config-instance'
// TODO: declare this at the root and use actual audiusLibs type
declare global {
interface Window {
audiusLibs: any
}
}
let audiusLibs: AudiusLibs
/**
* audiusBackend initialized for a mobile environment
*/
export const audiusBackendInstance = audiusBackend({
claimDistributionContractAddress: Config.CLAIM_DISTRIBUTION_CONTRACT_ADDRESS,
ethOwnerWallet: Config.ETH_OWNER_WALLET,
ethProviderUrls: (Config.ETH_PROVIDER_URL || '').split(','),
ethRegistryAddress: Config.ETH_REGISTRY_ADDRESS,
ethTokenAddress: Config.ETH_TOKEN_ADDRESS,
fetchCID: async () => ({}),
getFeatureEnabled,
getHostUrl: () => {
return `${Config.PUBLIC_PROTOCOL}//${Config.PUBLIC_HOSTNAME}`
},
getWeb3Config: async (libs, registryAddress, web3ProviderUrls) => {
return {
error: false,
web3Config: libs.configInternalWeb3(registryAddress, web3ProviderUrls)
}
},
identityServiceUrl: Config.IDENTITY_SERVICE,
isElectron: false,
isMobile: true,
legacyUserNodeUrl: Config.LEGACY_USER_NODE,
localStorage: AsyncStorage,
monitoringCallbacks,
nativeMobile: Config.NATIVE_MOBILE === 'true',
onLibsInit: (libs) => {
audiusLibs = libs
},
recaptchaSiteKey: Config.RECAPTCHA_SITE_KEY,
recordAnalytics: (event: any, properties: any) =>
track({ eventName: event, properties }),
registryAddress: Config.REGISTRY_ADDRESS,
remoteConfigInstance,
setLocalStorageItem: async (key, value) => AsyncStorage.setItem(key, value),
solanaConfig: {
anchorAdminAccount: Config.ANCHOR_ADMIN_ACCOUNT,
anchorProgramId: Config.ANCHOR_PROGRAM_ID,
claimableTokenPda: Config.CLAIMABLE_TOKEN_PDA,
claimableTokenProgramAddress: Config.CLAIMABLE_TOKEN_PROGRAM_ADDRESS,
rewardsManagerProgramId: Config.REWARDS_MANAGER_PROGRAM_ID,
rewardsManagerProgramPda: Config.REWARDS_MANAGER_PROGRAM_PDA,
rewardsManagerTokenPda: Config.REWARDS_MANAGER_TOKEN_PDA,
solanaClusterEndpoint: Config.SOLANA_CLUSTER_ENDPOINT,
solanaFeePayerAddress: Config.SOLANA_FEE_PAYER_ADDRESS,
solanaTokenAddress: Config.SOLANA_TOKEN_PROGRAM_ADDRESS,
waudioMintAddress: Config.WAUDIO_MINT_ADDRESS,
wormholeAddress: Config.WORMHOLE_ADDRESS
},
userNodeUrl: Config.USER_NODE,
web3NetworkId: Config.WEB3_NETWORK_ID,
web3ProviderUrls: (Config.WEB3_PROVIDER_URL || '').split(','),
waitForWeb3: async () => {},
wormholeConfig: {
ethBridgeAddress: Config.ETH_BRIDGE_ADDRESS,
ethTokenBridgeAddress: Config.ETH_TOKEN_BRIDGE_ADDRESS,
solBridgeAddress: Config.SOL_BRIDGE_ADDRESS,
solTokenBridgeAddress: Config.SOL_TOKEN_BRIDGE_ADDRESS,
wormholeRpcHosts: Config.WORMHOLE_RPC_HOSTS
},
getLibs: async () => nativeLibs,
waitForLibsInit: async () => {},
withEagerOption: ({ normal }, ...args) => {
if (audiusLibs) {
return normal(audiusLibs)(...args)
}
}
})