Skip to content

Commit

Permalink
Merge pull request #149 from CudoVentures/cudos-dev
Browse files Browse the repository at this point in the history
Merge latest changes
  • Loading branch information
mlukanova authored May 15, 2023
2 parents 251d727 + 22205cc commit 62a5c7b
Show file tree
Hide file tree
Showing 56 changed files with 592 additions and 616 deletions.
85 changes: 15 additions & 70 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,71 +1,16 @@
# LOCAL
VITE_APP_LOCAL_CAPTCHA_SITE_KEY=''
VITE_APP_LOCAL_FAUCET_URL=''
VITE_APP_LOCAL_FAUCET_ADDRESS=''
VITE_APP_LOCAL_BRIDGE_URL=''
VITE_APP_LOCAL_GRAPHQL_URL=''
VITE_APP_LOCAL_GRAPHQL_WS=''
VITE_APP_LOCAL_RPC=''
VITE_APP_LOCAL_API=''
VITE_APP_LOCAL_EXPLORER_URL=''
VITE_APP_LOCAL_STAKING_URL=''
VITE_APP_LOCAL_CHAIN_NAME=''
VITE_APP_LOCAL_CHAIN_ID=''

# DEV
VITE_APP_DEV_CAPTCHA_SITE_KEY=''
VITE_APP_DEV_FAUCET_URL=''
VITE_APP_DEV_FAUCET_ADDRESS=''
VITE_APP_DEV_BRIDGE_URL=''
VITE_APP_DEV_GRAPHQL_URL=''
VITE_APP_DEV_GRAPHQL_WS=''
VITE_APP_DEV_RPC=''
VITE_APP_DEV_API=''
VITE_APP_DEV_EXPLORER_URL=''
VITE_APP_DEV_STAKING_URL=''
VITE_APP_DEV_CHAIN_NAME=''
VITE_APP_DEV_CHAIN_ID=''

# PRIVATE
VITE_APP_PRIVATE_CAPTCHA_SITE_KEY=''
VITE_APP_PRIVATE_FAUCET_URL=''
VITE_APP_PRIVATE_FAUCET_ADDRESS=''
VITE_APP_PRIVATE_BRIDGE_URL=''
VITE_APP_PRIVATE_GRAPHQL_URL=''
VITE_APP_PRIVATE_GRAPHQL_WS=''
VITE_APP_PRIVATE_RPC=''
VITE_APP_PRIVATE_API=''
VITE_APP_PRIVATE_EXPLORER_URL=''
VITE_APP_PRIVATE_STAKING_URL=''
VITE_APP_PRIVATE_CHAIN_NAME=''
VITE_APP_PRIVATE_CHAIN_ID=''

# PUBLIC
VITE_APP_PUBLIC_CAPTCHA_SITE_KEY=''
VITE_APP_PUBLIC_FAUCET_URL=''
VITE_APP_PUBLIC_FAUCET_ADDRESS=''
VITE_APP_PUBLIC_BRIDGE_URL=''
VITE_APP_PUBLIC_GRAPHQL_UR=''
VITE_APP_PUBLIC_GRAPHQL_WS=''
VITE_APP_PUBLIC_RPC=''
VITE_APP_PUBLIC_API=''
VITE_APP_PUBLIC_EXPLORER_URL=''
VITE_APP_PUBLIC_STAKING_URL=''
VITE_APP_PUBLIC_CHAIN_NAME=''
VITE_APP_PUBLIC_CHAIN_ID=''

# MAINNET
VITE_APP_MAINNET_BRIDGE_URL=''
VITE_APP_MAINNET_GRAPHQL_URL=''
VITE_APP_MAINNET_GRAPHQL_WS=''
VITE_APP_MAINNET_RPC=''
VITE_APP_MAINNET_API=''
VITE_APP_MAINNET_EXPLORER_URL=''
VITE_APP_MAINNET_STAKING_URL=''
VITE_APP_MAINNET_CHAIN_NAME=''
VITE_APP_MAINNET_CHAIN_ID=''

# GENERAL SETTINGS
VITE_NODE_ENV='' #Production or empty
VITE_APP_DEFAULT_NETWORK='' # LOCAL | PRIVATE | PUBLIC | MAINNET
# APP SETTINGS
VITE_APP_DEPLOYMENT_VERSION='' #v0.0.1 format
VITE_APP_NODE_ENV='' #Production or empty
VITE_APP_GAS_PRICE=5000000000000
VITE_APP_CAPTCHA_SITE_KEY=''
VITE_APP_FAUCET_URL=''
VITE_APP_FAUCET_ADDRESS=''
VITE_APP_BRIDGE_URL=''
VITE_APP_GRAPHQL_URL=''
VITE_APP_GRAPHQL_WS=''
VITE_APP_RPC=''
VITE_APP_API=''
VITE_APP_STAKING_URL=''
VITE_APP_EXPLORER_URL=''
VITE_APP_CHAIN_NAME=''
VITE_APP_CHAIN_ID=''
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Edge",
"request": "launch",
"type": "pwa-msedge",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"userDataDir": false
},
{
"type": "pwa-chrome",
"request": "launch",
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-NWBZN9R');</script>
<!-- End Google Tag Manager -->
<script type="module">
import { Buffer } from "buffer";
window.Buffer = Buffer;
</script>
</head>
<body>
<!-- Google Tag Manager (noscript) -->
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"bech32": "^2.0.0",
"big.js": "^6.1.1",
"bignumber.js": "^9.0.2",
"buffer": "^6.0.3",
"copy-to-clipboard": "^3.3.1",
"cosmjs-types": "^0.4.1",
"cudosjs": "^1.2.5",
"cudosjs": "^1.2.7",
"detect-browser": "^5.3.0",
"dompurify": "^2.3.8",
"graphql": "^16.3.0",
Expand Down
60 changes: 18 additions & 42 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect } from 'react'
import { ThemeProvider } from '@mui/material/styles'
import { useDispatch, useSelector } from 'react-redux'
import { Box, CssBaseline } from '@mui/material'
import { ApolloClient, ApolloProvider, NormalizedCacheObject } from '@apollo/client'
import { ApolloProvider } from '@apollo/client'
import { Routes, Route, useLocation, Navigate } from 'react-router-dom'
import { updateUser } from 'store/profile'
import { updateUserTransactions } from 'store/userTransactions'
import NotificationPopup from 'components/NotificationPopup'
import CosmosNetworkConfig from 'ledgers/CosmosNetworkConfig'
import { switchLedgerType } from 'ledgers/utils'
import { connectUser } from './utils/projectUtils'
import { useApollo } from './graphql/client'
Expand All @@ -25,7 +24,7 @@ import theme from './theme'
import { RootState } from './store'

import '@fontsource/poppins'
import { ApolloLinks, defaultApolloLinks } from 'graphql/helpers'
import { defaultApolloLinks } from 'graphql/helpers'
import { CHAIN_DETAILS } from 'utils/constants'
import NetworkChangingLoading from 'components/NetworkChangeLoading'
import { networkLoadingStyles } from 'components/NetworkChangeLoading/styles'
Expand All @@ -35,22 +34,20 @@ const App = () => {
const location = useLocation()
const themeColor = useSelector((state: RootState) => state.settings.theme)
const newApolloClient = useApollo(null)
const [currentApolloClient, setCurrentApolloClient] = useState<ApolloClient<NormalizedCacheObject>>(
newApolloClient(defaultApolloLinks)
)
const isMainnet = CHAIN_DETAILS.CHAIN_ID === 'cudos-1'

const {
lastLoggedAddress,
chosenNetwork: currentNetwork,
connectedLedger,
loadingState
} = useSelector((state: RootState) => state.profile)

const dispatch = useDispatch()

const connectAccount = useCallback(async (chosenNetwork: string, walletName: SUPPORTED_WALLET) => {
const connectAccount = useCallback(async (walletName: SUPPORTED_WALLET) => {
try {

const { address } = await switchLedgerType(chosenNetwork!, walletName)
const { address } = await switchLedgerType(walletName)
if (address !== lastLoggedAddress || lastLoggedAddress === '') {
dispatch(
updateUserTransactions({
Expand All @@ -62,7 +59,7 @@ const App = () => {
)
}

const connectedUser = await connectUser(chosenNetwork, walletName)
const connectedUser = await connectUser(walletName)
dispatch(updateUser(connectedUser))

} catch (e) {
Expand All @@ -82,46 +79,27 @@ const App = () => {
})
)

await connectAccount(currentNetwork, SUPPORTED_WALLET.Keplr)
await connectAccount(SUPPORTED_WALLET.Keplr)
})

if (isExtensionEnabled(SUPPORTED_WALLET.Cosmostation)) {
window.cosmostation.cosmos.on('accountChanged', async () => {
await connectAccount(currentNetwork, SUPPORTED_WALLET.Cosmostation)
await connectAccount(SUPPORTED_WALLET.Cosmostation)
})
}

return () => {
window.removeEventListener('keplr_keystorechange', async () => {
await connectAccount(currentNetwork, SUPPORTED_WALLET.Keplr)
await connectAccount(SUPPORTED_WALLET.Keplr)
})
window.removeEventListener('accountChanged', async () => {
await connectAccount(currentNetwork, SUPPORTED_WALLET.Cosmostation)
await connectAccount(SUPPORTED_WALLET.Cosmostation)
})
}
}, [])


useEffect(() => {
dispatch(updateUser({ loadingState: true })
)
const newApolloLinks: ApolloLinks = {
uri: CHAIN_DETAILS.GRAPHQL_URL[currentNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL],
url: CHAIN_DETAILS.GRAPHQL_WS[currentNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_WS]
}

setCurrentApolloClient(newApolloClient(newApolloLinks))

if (connectedLedger) {
connectAccount(currentNetwork, connectedLedger)
}

setTimeout(() => { dispatch(updateUser({ loadingState: false })) }, 4000)

}, [currentNetwork])

return (
<ApolloProvider client={currentApolloClient!}>
<ApolloProvider client={newApolloClient(defaultApolloLinks)}>
<ThemeProvider theme={theme[themeColor!]}>
<CssBaseline />
{location.pathname !== '/' ? null : (
Expand Down Expand Up @@ -150,13 +128,11 @@ const App = () => {
<Route path=":proposalId" element={<ProposalDetails />} />
</Route>
</Route>
{
CHAIN_DETAILS.CHAIN_ID[currentNetwork! as keyof typeof CHAIN_DETAILS.CHAIN_ID]
=== CHAIN_DETAILS.CHAIN_ID.MAINNET ? null : (
<Route path="faucet">
<Route index element={<Faucet />} />
</Route>
)}
{isMainnet ? null : (
<Route path="faucet">
<Route index element={<Faucet />} />
</Route>
)}
<Route path="*" element={<Navigate to="/dashboard" />} />
</Routes>

Expand Down
3 changes: 1 addition & 2 deletions src/api/getAccountDelegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { CHAIN_DETAILS } from 'utils/constants'
import { AccountDelegationsDocument } from '../graphql/account_actions'

export const fetchDelegations = async (
chosenNetwork: string,
address: string,
signal?: AbortSignal
) => {
const delegationsArray: { address: string; amount: string }[] = []

try {
const { data } = await axios.post(
CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(),
CHAIN_DETAILS.GRAPHQL_URL,
{
variables: { address },
query: AccountDelegationsDocument
Expand Down
3 changes: 1 addition & 2 deletions src/api/getAccountRedelegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CHAIN_DETAILS } from 'utils/constants'
import { AccountRedelegationsDocument } from '../graphql/account_actions'

export const fetchRedelegations = async (
chosenNetwork: string,
address: string,
signal?: AbortSignal
) => {
Expand All @@ -16,7 +15,7 @@ export const fetchRedelegations = async (

try {
const { data } = await axios.post(
CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(),
CHAIN_DETAILS.GRAPHQL_URL,
{
variables: { address },
query: AccountRedelegationsDocument
Expand Down
3 changes: 1 addition & 2 deletions src/api/getAccountUndelegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CHAIN_DETAILS } from 'utils/constants'
import { AccountUndelegationsDocument } from '../graphql/account_actions'

export const fetchUndedelegations = async (
chosenNetwork: string,
address: string,
signal?: AbortSignal
) => {
Expand All @@ -15,7 +14,7 @@ export const fetchUndedelegations = async (

try {
const { data } = await axios.post(
CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(),
CHAIN_DETAILS.GRAPHQL_URL,
{
variables: { address },
query: AccountUndelegationsDocument
Expand Down
4 changes: 2 additions & 2 deletions src/api/getRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { formatBigNum } from '../utils/projectUtils'
import { AccountDelegationRewardsDocument } from '../graphql/account_actions'
import { CHAIN_DETAILS } from 'utils/constants'

export const fetchRewards = async (chosenNetwork: string, address: string, signal?: AbortSignal) => {
export const fetchRewards = async (address: string, signal?: AbortSignal) => {
const defaultReturnValue = new BigNumber(0)
const rewardArray: Array<BigNumber> = []
const validatorArray: { address: string; amount: string }[] = []
try {
const { data } = await axios.post(
CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL].toString(),
CHAIN_DETAILS.GRAPHQL_URL,
{
variables: { address },
query: AccountDelegationRewardsDocument
Expand Down
3 changes: 1 addition & 2 deletions src/api/getUnbondingBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { formatBigNum } from 'utils/projectUtils'
import { AccountUnbondingBalanceDocument } from '../graphql/account_actions'

export const getUnbondingBalance = async (
chosenNetwork: string,
address: string,
signal?: AbortSignal
) => {
Expand All @@ -14,7 +13,7 @@ export const getUnbondingBalance = async (

try {
const { data } = await axios.post(
CHAIN_DETAILS.GRAPHQL_URL[chosenNetwork! as keyof typeof CHAIN_DETAILS.GRAPHQL_URL]?.toString(),
CHAIN_DETAILS.GRAPHQL_URL,
{
variables: { address },
query: AccountUnbondingBalanceDocument
Expand Down
Loading

0 comments on commit 62a5c7b

Please sign in to comment.