-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Thorianite <100335276+Thorian1te@users.noreply.github.com>
- Loading branch information
1 parent
39c4922
commit dfed819
Showing
33 changed files
with
832 additions
and
187 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/renderer/components/uielements/radioGroup/RadioGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import clsx from 'clsx' | ||
|
||
export const RadioGroup = ({ | ||
options, | ||
activeIndex = 0, | ||
onChange | ||
}: { | ||
options: { label: React.ReactNode; value: string | number }[] | ||
activeIndex?: number | ||
onChange: (index: number) => void | ||
}) => { | ||
return ( | ||
<div className="h-fit"> | ||
<div className="flex rounded-lg border border-solid border-gray0 dark:border-gray0d"> | ||
{options.map((option, index) => ( | ||
<> | ||
{index !== 0 && <div className="h-10 w-[1px] bg-gray0 dark:bg-gray0d" />} | ||
<div | ||
key={option.value} | ||
className={clsx( | ||
'cursor-pointer p-2 hover:bg-gray0 hover:dark:bg-gray0d', | ||
'first:rounded-l-md last:rounded-r-md', | ||
activeIndex === index ? 'bg-gray0 dark:bg-gray0d' : 'bg-transparent' | ||
)} | ||
onClick={() => onChange(index)}> | ||
{option.label} | ||
</div> | ||
</> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './RadioGroup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
import { AnyAsset } from '@xchainjs/xchain-util' | ||
import * as A from 'fp-ts/lib/Array' | ||
import * as FP from 'fp-ts/lib/function' | ||
import * as O from 'fp-ts/lib/Option' | ||
import * as Rx from 'rxjs' | ||
import * as RxOp from 'rxjs/operators' | ||
|
||
import { WalletType } from '../../shared/wallet/types' | ||
import { useChainContext } from '../contexts/ChainContext' | ||
import { useThorchainContext } from '../contexts/ThorchainContext' | ||
import { useWalletContext } from '../contexts/WalletContext' | ||
import { isMayaChain, isThorChain } from '../helpers/chainHelper' | ||
import { userChains$ } from '../services/storage/userChains' | ||
import { SaverProviderRD } from '../services/thorchain/types' | ||
import { ledgerAddressToWalletAddress } from '../services/wallet/util' | ||
|
||
export const useAllSaverProviders = (poolAsset: AnyAsset[]) => { | ||
const { getSaverProvider$ } = useThorchainContext() | ||
const { addressByChain$ } = useChainContext() | ||
const { getLedgerAddress$ } = useWalletContext() | ||
|
||
const [allSaverProviders, setAllSaverProviders] = useState<Record<string, SaverProviderRD>>({}) | ||
|
||
useEffect(() => { | ||
if (poolAsset) { | ||
const userChainsSubscription = userChains$.subscribe((enabledChains) => { | ||
const keystoreAddresses$ = FP.pipe( | ||
enabledChains, | ||
A.filter((chain) => !isThorChain(chain)), | ||
A.map(addressByChain$) | ||
) | ||
|
||
const ledgerAddresses$ = (): Rx.Observable<O.Option<{ chain: string; address: string; type: WalletType }>>[] => | ||
FP.pipe( | ||
enabledChains, | ||
A.filter((chain) => !isThorChain(chain) || isMayaChain(chain)), | ||
A.map((chain) => getLedgerAddress$(chain)), | ||
A.map(RxOp.map(FP.flow(O.map(ledgerAddressToWalletAddress)))) | ||
) | ||
|
||
const combinedAddresses$ = Rx.combineLatest([...keystoreAddresses$, ...ledgerAddresses$()]).pipe( | ||
RxOp.map((addressOptionsArray) => FP.pipe(addressOptionsArray, A.filterMap(FP.identity))), | ||
RxOp.map((walletAddresses) => | ||
walletAddresses.map((walletAddress) => ({ | ||
chain: walletAddress.chain, | ||
address: walletAddress.address, | ||
type: walletAddress.type | ||
})) | ||
) | ||
) | ||
|
||
const subscriptions = poolAsset.map((asset) => { | ||
return combinedAddresses$ | ||
.pipe( | ||
RxOp.switchMap((walletAddresses) => { | ||
const addressesForAssetChain = walletAddresses.filter((wa) => wa.chain === asset.chain) | ||
if (addressesForAssetChain.length > 0) { | ||
return Rx.combineLatest( | ||
addressesForAssetChain.map((walletAddress) => | ||
getSaverProvider$(asset, walletAddress.address, walletAddress.type) | ||
) | ||
) | ||
} | ||
return Rx.of(null) | ||
}) | ||
) | ||
.subscribe((saverProviders) => { | ||
if (saverProviders !== null) { | ||
saverProviders.forEach((saverProvider) => { | ||
if ( | ||
saverProvider !== null && | ||
saverProvider._tag === 'RemoteSuccess' && | ||
saverProvider.value.depositValue.amount().gt(0) | ||
) { | ||
const key = `${asset.chain}.${asset.symbol}` | ||
setAllSaverProviders((prev) => ({ ...prev, [key]: saverProvider })) | ||
} | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
return () => { | ||
subscriptions.forEach((sub) => sub.unsubscribe()) | ||
userChainsSubscription.unsubscribe() | ||
} | ||
}) | ||
} | ||
}, [addressByChain$, getLedgerAddress$, getSaverProvider$, poolAsset]) | ||
|
||
return { allSaverProviders, setAllSaverProviders } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useCallback, useEffect, useMemo, useState } from 'react' | ||
|
||
import * as RD from '@devexperts/remote-data-ts' | ||
import { THORChain } from '@xchainjs/xchain-thorchain' | ||
import * as A from 'fp-ts/Array' | ||
import * as FP from 'fp-ts/function' | ||
import * as O from 'fp-ts/Option' | ||
import * as Rx from 'rxjs' | ||
import * as RxOp from 'rxjs/operators' | ||
|
||
import { getChainsForDex } from '../../shared/utils/chain' | ||
import { useChainContext } from '../contexts/ChainContext' | ||
import { useMidgardContext } from '../contexts/MidgardContext' | ||
import { useMidgardMayaContext } from '../contexts/MidgardMayaContext' | ||
import { useWalletContext } from '../contexts/WalletContext' | ||
import { addressFromWalletAddress } from '../helpers/walletHelper' | ||
import { WalletAddress$ } from '../services/clients' | ||
import { PoolShares } from '../services/midgard/types' | ||
import { userChains$ } from '../services/storage/userChains' | ||
import { ledgerAddressToWalletAddress } from '../services/wallet/util' | ||
import { useDex } from './useDex' | ||
|
||
export const usePoolShares = () => { | ||
const { dex } = useDex() | ||
|
||
const { | ||
service: { | ||
pools: { reloadAllPools }, | ||
shares: { allSharesByAddresses$, reloadAllSharesByAddresses } | ||
} | ||
} = useMidgardContext() | ||
|
||
const { | ||
service: { | ||
pools: { reloadAllPools: reloadAllMayaPools }, | ||
shares: { | ||
allSharesByAddresses$: allSharesByAddressesMaya$, | ||
reloadAllSharesByAddresses: reloadAllSharesByAddressesMaya | ||
} | ||
} | ||
} = useMidgardMayaContext() | ||
|
||
const { addressByChain$ } = useChainContext() | ||
const { getLedgerAddress$ } = useWalletContext() | ||
|
||
const INCLUDED_CHAINS = useMemo(() => getChainsForDex(dex.chain), [dex.chain]) | ||
|
||
const [allSharesRD, setAllSharesRD] = useState<RD.RemoteData<Error, PoolShares>>(RD.initial) | ||
|
||
useEffect(() => { | ||
const subscription = userChains$ | ||
.pipe( | ||
RxOp.switchMap((enabledChains) => { | ||
const addresses$: WalletAddress$[] = FP.pipe( | ||
enabledChains, | ||
A.filter((chain) => INCLUDED_CHAINS.includes(chain)), | ||
A.map(addressByChain$) | ||
) | ||
const ledgerAddresses$ = (): WalletAddress$[] => | ||
FP.pipe( | ||
enabledChains, | ||
A.filter((chain) => INCLUDED_CHAINS.includes(chain)), | ||
A.map((chain) => getLedgerAddress$(chain)), | ||
A.map(RxOp.map(FP.flow(O.map(ledgerAddressToWalletAddress)))) | ||
) | ||
const combinedAddresses$ = Rx.combineLatest([...addresses$, ...ledgerAddresses$()]) | ||
|
||
return FP.pipe( | ||
combinedAddresses$, | ||
RxOp.switchMap( | ||
FP.flow(A.filterMap(FP.identity), A.map(addressFromWalletAddress), (addresses) => | ||
dex.chain === THORChain ? allSharesByAddresses$(addresses) : allSharesByAddressesMaya$(addresses) | ||
) | ||
), | ||
RxOp.startWith(RD.pending) | ||
) | ||
}) | ||
) | ||
.subscribe(setAllSharesRD) | ||
|
||
return () => subscription.unsubscribe() | ||
}, [dex, allSharesByAddresses$, allSharesByAddressesMaya$, addressByChain$, INCLUDED_CHAINS, getLedgerAddress$]) | ||
|
||
const reload = useCallback(() => { | ||
if (dex.chain === THORChain) { | ||
reloadAllPools() | ||
reloadAllSharesByAddresses() | ||
} else { | ||
reloadAllMayaPools() | ||
reloadAllSharesByAddressesMaya() | ||
} | ||
}, [dex, reloadAllMayaPools, reloadAllPools, reloadAllSharesByAddresses, reloadAllSharesByAddressesMaya]) | ||
|
||
return { | ||
allSharesRD, | ||
reload | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.