Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use 'unstakeAndClaim' for visuals #4530

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions src/components/scenes/Staking/StakeModifyScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EdgeSceneProps } from '../../../types/routerTypes'
import { getCurrencyIconUris } from '../../../util/CdnUris'
import { getTokenId } from '../../../util/CurrencyInfoHelpers'
import { getWalletName } from '../../../util/CurrencyWalletHelpers'
import { getPolicyIconUris, getPolicyTitleName, getPositionAllocations } from '../../../util/stakeUtils'
import { getPolicyIconUris, getPositionAllocations } from '../../../util/stakeUtils'
import { toBigNumberString } from '../../../util/toBigNumberString'
import { zeroString } from '../../../util/utils'
import { SceneWrapper } from '../../common/SceneWrapper'
Expand All @@ -40,7 +40,7 @@ interface Props extends EdgeSceneProps<'stakeModify'> {

const StakeModifySceneComponent = (props: Props) => {
const { navigation, route, wallet } = props
const { modification, stakePlugin, stakePolicy, stakePosition } = route.params
const { modification, title, stakePlugin, stakePolicy, stakePosition } = route.params
const { stakeWarning, unstakeWarning, claimWarning, disableMaxStake, mustMaxUnstake } = stakePolicy
const existingAllocations = React.useMemo(() => getPositionAllocations(stakePosition), [stakePosition])

Expand Down Expand Up @@ -165,7 +165,6 @@ const StakeModifySceneComponent = (props: Props) => {
const message = {
stake: lstrings.stake_change_stake_success,
unstake: lstrings.stake_change_unstake_success,
unstakeAndClaim: lstrings.stake_change_claim_success,
claim: lstrings.stake_change_claim_success,
unstakeExact: ''
}
Expand Down Expand Up @@ -283,20 +282,21 @@ const StakeModifySceneComponent = (props: Props) => {
const quoteCurrencyCode = currencyCode
const quoteDenom = getExchangeDenominationFromAccount(account, pluginId, quoteCurrencyCode)

const isClaim = allocationType === 'claim'

const title =
allocationType === 'stake'
? sprintf(lstrings.stake_amount_s_stake, quoteCurrencyCode)
: allocationType === 'unstake'
? sprintf(lstrings.stake_amount_s_unstake, quoteCurrencyCode)
: sprintf(lstrings.stake_amount_claim, quoteCurrencyCode)
: isClaim
? sprintf(lstrings.stake_amount_claim, quoteCurrencyCode)
: sprintf(lstrings.stake_amount_s_unstake, quoteCurrencyCode)

const nativeAmount = zeroString(quoteAllocation?.nativeAmount) ? '' : quoteAllocation?.nativeAmount ?? ''
const { nativeAmount: earnedAmount = '0', locktime } = existingAllocations.earned[0] ?? {}
if (allocationType === 'claim' && locktime != null && Date.now() < new Date(locktime).valueOf()) {
if (isClaim && locktime != null && Date.now() < new Date(locktime).valueOf()) {
return null
}

const isClaim = allocationType === 'claim'
return (
<EditableAmountTile
title={title}
Expand Down Expand Up @@ -457,16 +457,6 @@ const StakeModifySceneComponent = (props: Props) => {
)
}

const sceneTitleMap = React.useMemo(() => {
return {
stake: getPolicyTitleName(stakePolicy),
claim: lstrings.stake_claim_rewards,
unstake: lstrings.stake_unstake,
unstakeAndClaim: lstrings.stake_unstake_claim,
unstakeExact: '' // Only for internal use
}
}, [stakePolicy])

const policyIcons = getPolicyIconUris(wallet.currencyInfo, stakePolicy)
const icon = React.useMemo(
() => (modification === 'stake' ? null : <Image style={styles.icon} source={{ uri: policyIcons.rewardAssetUris[0] }} />),
Expand All @@ -486,7 +476,7 @@ const StakeModifySceneComponent = (props: Props) => {
return (
<SceneWrapper scroll background="theme">
<ScrollView>
<SceneHeader style={styles.sceneHeader} title={sceneTitleMap[modification]} underline withTopMargin>
<SceneHeader style={styles.sceneHeader} title={title} underline withTopMargin>
{icon}
</SceneHeader>
{renderChangeQuoteAmountTiles(modification)}
Expand Down
16 changes: 15 additions & 1 deletion src/components/scenes/Staking/StakeOverviewScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,27 @@ const StakeOverviewSceneComponent = (props: Props) => {
}, [account, stakePlugin, stakePolicyId, updateCounter, wallet])

// Handlers
const handleModifyPress = (modification: ChangeQuoteRequest['action']) => () => {
const handleModifyPress = (modification: ChangeQuoteRequest['action'] | 'unstakeAndClaim') => () => {
const sceneTitleMap = {
stake: getPolicyTitleName(stakePolicy),
claim: lstrings.stake_claim_rewards,
unstake: lstrings.stake_unstake,
unstakeAndClaim: lstrings.stake_unstake_claim,
unstakeExact: '' // Only for internal use
}
const title = sceneTitleMap[modification]

if (modification === 'unstakeAndClaim') {
modification = 'unstake'
}

if (stakePosition != null && stakeAllocations != null && rewardAllocations != null) {
navigation.navigate('stakeModify', {
modification,
stakePlugin,
stakePolicy,
stakePosition,
title,
walletId: wallet.id
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/stake-plugins/thorchainSavers/tcSaversPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu
// Only unstake the exact amount specified in the request.nativeAmount
totalUnstakeNativeAmount = nativeAmount
} else {
// If action === claim || action === unstakeAndClaim
// If action === claim
// The user will be explicitly unstaking the earned amount
totalUnstakeNativeAmount = earnedAmount
}
Expand Down Expand Up @@ -789,7 +789,6 @@ const unstakeRequestInner = async (opts: EdgeGuiPluginOptions, request: ChangeQu
const changeQuoteFuncs = {
stake: stakeRequest,
unstake: unstakeRequest,
unstakeAndClaim: unstakeRequest,
claim: unstakeRequest,
unstakeExact: unstakeRequest
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/stake-plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface StakePolicy {
// Change Quote
// -----------------------------------------------------------------------------
export interface ChangeQuoteRequest {
action: 'stake' | 'unstake' | 'unstakeAndClaim' | 'claim' | 'unstakeExact'
action: 'stake' | 'unstake' | 'claim' | 'unstakeExact'
stakePolicyId: string
currencyCode: string
nativeAmount: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,16 +700,16 @@ export const makeVelodromeV2StakePolicy = (options: UniswapV2LpPolicyOptions): S
const canStake = !disableStake && ((gt(tokenABalance, '0') && gt(tokenBBalance, '0')) || gt(lpTokenBalance, '0'))

// You can unstake so long as there is some staked LP-Token balance (there are no timelocks)
const canUnstake = !disableUnstake && gt(stakedLpTokenBalance, '0')
const canUnstakeAndClaim = !disableUnstake && gt(stakedLpTokenBalance, '0')

// You can claim so long as there is some reward balance (there are no timelocks)
const canClaim = !disableClaim && gt(rewardNativeAmount, '0')

return {
allocations: [...stakedAllocations, ...earnedAllocations],
canStake,
canUnstake,
canUnstakeAndClaim: false,
canUnstake: false,
canUnstakeAndClaim,
canClaim
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/routerTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export interface RouteParamList {
settingsOverviewTab: {}
spendingLimits: {}
stakeModify: {
title: string
stakePlugin: StakePlugin
walletId: string
stakePolicy: StakePolicy
Expand Down
Loading