Skip to content

Commit

Permalink
Remove 'unstakeAndClaim' as a ChangeQuoteRequest action
Browse files Browse the repository at this point in the history
The 'unstakeAndClaim' option is really just for visuals and text. Since the plugins don't use it as a unique action we should remove it from the ChangeQuoteRequest type and handle the special case where the user would see it.
  • Loading branch information
peachbits committed Oct 19, 2023
1 parent 2997289 commit 2d3291f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
17 changes: 3 additions & 14 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 @@ -458,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 @@ -487,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
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

0 comments on commit 2d3291f

Please sign in to comment.