Skip to content

Commit

Permalink
chore(portfolio): exporting helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Apr 29, 2024
1 parent 073c801 commit 199b892
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {useStrings} from '../../../common/strings'
import {useSelectedSecondaryAmountsCounter} from '../../../common/useSelectedSecondaryAmountsCounter'
import {useTokenQuantities} from '../../../common/useTokenQuantities'
import {MaxAmountsPerTx} from './Show/MaxAmountsPerTx'
import {usePortfolioPrimaryBreakdown} from '../../../../Portfolio/common/hooks/usePortfolioPrimaryBreakdown'
import {isPrimary, isPrimaryToken} from '@yoroi/portfolio'

export const SelectTokenFromListScreen = () => {
const strings = useStrings()
Expand Down Expand Up @@ -212,25 +214,26 @@ const Tab = <T,>({onPress, active, tab, label}: TabProps<T>) => {
)
}

type SelectableAssetItemProps = {disabled?: boolean; tokenInfo: Balance.TokenInfo; wallet: YoroiWallet}
const SelectableAssetItem = ({tokenInfo, disabled, wallet}: SelectableAssetItemProps) => {
type SelectableAssetItemProps = {disabled?: boolean; amount: Portfolio.Token.Amount; wallet: YoroiWallet}
const SelectableAssetItem = ({amount, disabled, wallet}: SelectableAssetItemProps) => {
const {styles} = useStyles()
const navigation = useNavigation<TxHistoryRouteNavigation>()
const {closeSearch} = useSearch()
const {targets, tokenSelectedChanged, amountChanged, selectedTargetIndex, selectedTokenId} = useTransfer()
const {records: balances} = usePortfolioBalances({wallet})
const primaryBreakdown = usePortfolioPrimaryBreakdown({wallet})
const {spendable} = targetGetTokenBalanceBreakdown({
balances,
primaryBreakdown,
selectedTargetIndex,
selectedTokenId,
targets,
})
const navigation = useNavigation<TxHistoryRouteNavigation>()
const balances = useBalances(wallet)

const isPrimary = tokenInfo.id === wallet.primaryTokenInfo.id
const isPrimary = isPrimaryToken(amount.info)

const onSelect = () => {
tokenSelectedChanged(tokenInfo.id)
tokenSelectedChanged(amount.info.id)
closeSearch()

// if the balance is atomic there is no need to edit the amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t
this.portfolioPrimaryTokenInfo = portfolioPrimaryTokenInfo
}

// portfoliio
// portfolio - here to get snapshots only, avoid using it directly
get balances() {
return this.balanceManager.getBalances()
}
Expand All @@ -420,6 +420,7 @@ export const makeShelleyWallet = (constants: typeof MAINNET | typeof TESTNET | t
get primaryBreakdown() {
return this.balanceManager.getPrimaryBreakdown()
}
// end of portfolio

get receiveAddresses(): Addresses {
return this.externalAddresses.slice(0, this.numReceiveAddresses)
Expand Down
5 changes: 3 additions & 2 deletions packages/portfolio/src/helpers/is-ft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Portfolio} from '@yoroi/types'

export const isFt = (tokenInfo: Portfolio.Token.Info): boolean =>
tokenInfo.type === Portfolio.Token.Type.FT
export function isFt(tokenInfo: Portfolio.Token.Info) {
return tokenInfo.type === Portfolio.Token.Type.FT
}
5 changes: 3 additions & 2 deletions packages/portfolio/src/helpers/is-nft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Portfolio} from '@yoroi/types'

export const isNft = (tokenInfo: Portfolio.Token.Info): boolean =>
tokenInfo.type === Portfolio.Token.Type.NFT
export function isNft(tokenInfo: Portfolio.Token.Info) {
return tokenInfo.type === Portfolio.Token.Type.NFT
}
3 changes: 3 additions & 0 deletions packages/portfolio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export * from './helpers/create-primary-token-info'
export * from './helpers/sorting'
export * from './helpers/info-extract-name'
export * from './helpers/is-primary-token'
export * from './helpers/is-ft'
export * from './helpers/is-nft'
export * from './helpers/info-filter-by-name'

export * from './adapters/amount.mocks'
export * from './adapters/dullahan-api/api-maker.mocks'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Portfolio, Transfer} from '@yoroi/types'
import {targetGetTokenTotalUsedByOthers} from './target-get-token-total-used-by-others'
import {isPrimary} from '@yoroi/portfolio'
import {isPrimaryToken} from '@yoroi/portfolio'

export function targetGetTokenBalanceBreakdown({
balances,
Expand Down Expand Up @@ -38,7 +38,7 @@ export function targetGetTokenBalanceBreakdown({
if (amount) {
balance = amount.quantity
available = balance - used
locked = isPrimary(amount.info)
locked = isPrimaryToken(amount.info)
? primaryBreakdown.lockedAsStorageCost
: 0n
spendable = available - locked
Expand Down

0 comments on commit 199b892

Please sign in to comment.