Skip to content

Commit

Permalink
Purge yalc, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Jul 24, 2024
1 parent beed4e3 commit 1db940d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 35 deletions.
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@
"@coral-xyz/anchor": "^0.28.0",
"@gorhom/bottom-sheet": "4.6.0",
"@gorhom/portal": "1.0.14",
"@helium/account-fetch-cache": "^0.9.0-alpha.1",
"@helium/account-fetch-cache-hooks": "^0.9.0-alpha.2",
"@helium/account-fetch-cache": "0.9.0-alpha.6",
"@helium/account-fetch-cache-hooks": "0.9.0-alpha.6",
"@helium/address": "4.10.2",
"@helium/circuit-breaker-sdk": "^0.9.0-alpha.2",
"@helium/circuit-breaker-sdk": "^0.9.0-alpha.6",
"@helium/crypto-react-native": "4.8.0",
"@helium/currency-utils": "^0.9.0-alpha.1",
"@helium/data-credits-sdk": "^0.9.0-alpha.3",
"@helium/distributor-oracle": "^0.9.0-alpha.3",
"@helium/fanout-sdk": "^0.9.0-alpha.2",
"@helium/helium-entity-manager-sdk": "^0.9.0-alpha.3",
"@helium/helium-react-hooks": "^0.9.0-alpha.3",
"@helium/helium-sub-daos-sdk": "^0.9.0-alpha.3",
"@helium/currency-utils": "^0.9.0-alpha.6",
"@helium/data-credits-sdk": "^0.9.0-alpha.6",
"@helium/distributor-oracle": "0.9.0-alpha.6",
"@helium/fanout-sdk": "^0.9.0-alpha.6",
"@helium/helium-entity-manager-sdk": "^0.9.0-alpha.6",
"@helium/helium-react-hooks": "0.9.0-alpha.6",
"@helium/helium-sub-daos-sdk": "^0.9.0-alpha.6",
"@helium/http": "4.7.5",
"@helium/idls": "^0.9.0-alpha.1",
"@helium/lazy-distributor-sdk": "^0.9.0-alpha.3",
"@helium/idls": "0.9.0-alpha.6",
"@helium/lazy-distributor-sdk": "^0.9.0-alpha.6",
"@helium/modular-governance-hooks": "^0.0.8",
"@helium/modular-governance-idls": "^0.0.8",
"@helium/modular-governance-idls": "0.9.0-alpha.6",
"@helium/onboarding": "4.11.0",
"@helium/organization-sdk": "^0.0.8",
"@helium/proto-ble": "4.0.0",
"@helium/react-native-sdk": "^3.0.4",
"@helium/spl-utils": "^0.9.0-alpha.2",
"@helium/react-native-sdk": "0.9.0-alpha.6",
"@helium/spl-utils": "0.9.0-alpha.6",
"@helium/state-controller-sdk": "^0.0.8",
"@helium/sus": "^0.9.0-alpha.1",
"@helium/sus": "0.9.0-alpha.6",
"@helium/transactions": "4.8.1",
"@helium/treasury-management-sdk": "^0.9.0-alpha.3",
"@helium/voter-stake-registry-hooks": "^0.9.0-alpha.3",
"@helium/voter-stake-registry-sdk": "^0.9.0-alpha.3",
"@helium/treasury-management-sdk": "^0.9.0-alpha.6",
"@helium/voter-stake-registry-hooks": "0.9.0-alpha.6",
"@helium/voter-stake-registry-sdk": "0.9.0-alpha.6",
"@helium/wallet-link": "4.11.0",
"@jup-ag/api": "^6.0.6",
"@ledgerhq/hw-app-solana": "7.0.13",
Expand Down Expand Up @@ -266,11 +266,11 @@
},
"resolutions": {
"@types/react": "17",
"@helium/account-fetch-cache": "^0.9.0-alpha.1",
"@helium/account-fetch-cache-hooks": "^0.9.0-alpha.2",
"@helium/helium-react-hooks": "^0.9.0-alpha.3",
"@helium/voter-stake-registry-hooks": "^0.9.0-alpha.3",
"@helium/voter-stake-registry-sdk": "^0.9.0-alpha.3",
"@helium/account-fetch-cache": "^0.9.0-alpha.6",
"@helium/account-fetch-cache-hooks": "^0.9.0-alpha.6",
"@helium/helium-react-hooks": "^0.9.0-alpha.6",
"@helium/voter-stake-registry-hooks": "^0.9.0-alpha.6",
"@helium/voter-stake-registry-sdk": "^0.9.0-alpha.6",
"@helium/modular-governance-hooks": "^0.0.8",
"@helium/onboarding": "4.11.0"
},
Expand Down
8 changes: 5 additions & 3 deletions src/features/account/TokenListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { humanReadable } from '@utils/solanaUtils'
import BN from 'bn.js'
import React, { useCallback, useMemo } from 'react'
import {
getPositionKeys,
getPositionKeysForOwner,
useHeliumVsrState,
usePositions,
} from '@helium/voter-stake-registry-hooks'
Expand Down Expand Up @@ -196,7 +196,7 @@ export const TokenListGovItem = ({ mint }: { mint: PublicKey }) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async (args: any | undefined, useContext: boolean) => {
if (args && !useContext) {
return getPositionKeys(args)
return getPositionKeysForOwner(args)
}
},
[args, useContextPositions],
Expand All @@ -217,7 +217,9 @@ export const TokenListGovItem = ({ mint }: { mint: PublicKey }) => {
if (positions && positions.length) {
let amountLocked = new BN(0)
positions.forEach((position) => {
if (position) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (position && !position.isProxiedToMe) {
amountLocked = amountLocked.add(position.amountDepositedNative)
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/features/governance/AssignProxyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export const AssignProxyScreen = () => {
instructions,
{
basePriorityFee: await getBasePriorityFee(),
useFirstEstimateForAll: true,
computeScaleUp: 1.4,
},
)
const populatedTxs = await Promise.all(
Expand Down
42 changes: 39 additions & 3 deletions src/features/governance/PositionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useColors } from '@theme/themeHooks'
import { times } from 'lodash'
import React, { useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { FlatList, RefreshControl } from 'react-native'
import { RefreshControl, SectionList } from 'react-native'
import { PositionCard } from './PositionCard'

interface IPositionsListProps extends BoxProps<Theme> {
Expand Down Expand Up @@ -59,6 +59,14 @@ export const PositionsList = ({ header, ...boxProps }: IPositionsListProps) => {
[positions, loading],
)

const proxiedPositions = useMemo(
() => sortedPositions?.filter((p) => p.isProxiedToMe),
[sortedPositions],
)
const unProxiedPositions = useMemo(
() => sortedPositions?.filter((p) => !p.isProxiedToMe),
[sortedPositions],
)
const renderItem = useCallback(
({ item: p, index: idx }) => {
return (
Expand Down Expand Up @@ -109,8 +117,36 @@ export const PositionsList = ({ header, ...boxProps }: IPositionsListProps) => {
)
}, [loading, positions, t])

const SectionData = useMemo(() => {
return [
{ title: 'My Positions', data: unProxiedPositions || [] },
{ title: 'Proxied To Me', data: proxiedPositions || [] },
]
}, [proxiedPositions, unProxiedPositions])

const renderSectionHeader = useCallback(
({ section: { title, icon } }) => (
<Box
flexDirection="row"
alignItems="center"
paddingTop="xl"
paddingBottom="m"
paddingHorizontal="l"
backgroundColor="primaryBackground"
justifyContent="center"
>
{icon !== undefined && icon}
<Text variant="body3" textAlign="center" color="secondaryText">
{title}
</Text>
</Box>
),
[],
)

return (
<FlatList
<SectionList
renderSectionHeader={renderSectionHeader}
ListHeaderComponent={
<>
{header}
Expand Down Expand Up @@ -150,7 +186,7 @@ export const PositionsList = ({ header, ...boxProps }: IPositionsListProps) => {
</>
}
keyExtractor={keyExtractor}
data={sortedPositions}
sections={SectionData}
renderItem={renderItem}
ListEmptyComponent={renderEmptyComponent}
refreshControl={
Expand Down
2 changes: 2 additions & 0 deletions src/features/governance/ProposalScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ export const ProposalScreen = () => {
instructions,
{
basePriorityFee: await getBasePriorityFee(),
useFirstEstimateForAll: true,
computeScaleUp: 1.4,
},
)
const populatedTxs = await Promise.all(
Expand Down
2 changes: 2 additions & 0 deletions src/features/governance/RevokeProxyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export const RevokeProxyScreen = () => {
instructions,
{
basePriorityFee: await getBasePriorityFee(),
useFirstEstimateForAll: true,
computeScaleUp: 1.4,
},
)
const populatedTxs = await Promise.all(
Expand Down
14 changes: 10 additions & 4 deletions src/features/governance/VotersScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { GovernanceNavigationProp } from './governanceTypes'
import { GovernanceWrapper } from './GovernanceWrapper'
import { VoterCardStat } from './VoterCardStat'

const DECENTRALIZATION_RISK_INDEX = 6
const DECENTRALIZATION_RISK_PERCENT = 10
const VOTER_HEIGHT = 110

export const VoterSkeleton = () => {
Expand Down Expand Up @@ -89,9 +89,15 @@ export default function VotersScreen() {
)
}, [proxies, isLoading, loading, t])

const renderBelowIndex = useMemo(() => {
return proxies.findIndex(
(proxy) => Number(proxy.percent) < DECENTRALIZATION_RISK_PERCENT,
)
}, [proxies])

const renderItem = useCallback(
({ item: proxy, index }) => {
const majority = index < DECENTRALIZATION_RISK_INDEX
const majority = Number(proxy.percent) >= DECENTRALIZATION_RISK_PERCENT
const card = (
<VoterCard
decimals={decimals}
Expand Down Expand Up @@ -123,7 +129,7 @@ export default function VotersScreen() {
</>
)
}
if (index === DECENTRALIZATION_RISK_INDEX) {
if (renderBelowIndex > 0 && index === renderBelowIndex) {
return (
<>
<Box p="m">
Expand All @@ -146,7 +152,7 @@ export default function VotersScreen() {
}
return card
},
[decimals, t],
[decimals, renderBelowIndex, t],
)

const keyExtractor = useCallback((proxy) => proxy.wallet, [])
Expand Down
11 changes: 10 additions & 1 deletion src/solana/AsyncAccountCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ const TWO_MB = 2 * 1024 * 1024
export class AsyncAccountCache implements AccountCache {
cacheKey: string

timeout: any | null = null

cache = new Map<string, ParsedAccountBase<unknown> | null>()

private cacheOrder: Map<string, number> = new Map() // Maintain the order of keys based on usage

debouncedSet: () => void
debouncedSet() {
if (this.timeout) {
clearTimeout(this.timeout)
}
this.timeout = setTimeout(() => {
this.setAsyncStorage()
}, 10000)
}

constructor(cacheKey: string) {
this.cacheKey = cacheKey
Expand Down

0 comments on commit 1db940d

Please sign in to comment.