-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): #2053: implement
PositionClose
action view
- Loading branch information
Showing
17 changed files
with
159 additions
and
115 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { PositionClose } from '@penumbra-zone/protobuf/penumbra/core/component/dex/v1/dex_pb'; | ||
import { ActionViewBaseProps, GetMetadataByAssetId } from '../types'; | ||
import { ActionWrapper } from '../shared/wrapper'; | ||
import { ActionRow } from '../shared/action-row'; | ||
import { bech32mPositionId } from '@penumbra-zone/bech32m/plpid'; | ||
import { shorten } from '@penumbra-zone/types/string'; | ||
|
||
export interface PositionCloseActionProps extends ActionViewBaseProps { | ||
value: PositionClose; | ||
getMetadataByAssetId?: GetMetadataByAssetId; | ||
} | ||
|
||
export const PositionCloseAction = ({ value }: PositionCloseActionProps) => { | ||
return ( | ||
<ActionWrapper | ||
title='Position Close' | ||
infoRows={ | ||
<> | ||
{value.positionId && ( | ||
<ActionRow | ||
label='Position ID' | ||
info={shorten(bech32mPositionId(value.positionId), 8)} | ||
copyText={bech32mPositionId(value.positionId)} | ||
/> | ||
)} | ||
</> | ||
} | ||
/> | ||
); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
...ionView/actions/position-reward-claim.tsx → ...onView/position/position-reward-claim.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
2 changes: 1 addition & 1 deletion
2
.../ActionView/actions/position-withdraw.tsx → ...ActionView/position/position-withdraw.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ges/ui/src/ActionView/actions/wrapper.tsx → ...ages/ui/src/ActionView/shared/wrapper.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
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
78 changes: 6 additions & 72 deletions
78
packages/ui/src/ActionView/actions/swap.tsx → packages/ui/src/ActionView/swap/swap.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
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,67 @@ | ||
import { getMetadata } from '@penumbra-zone/getters/value-view'; | ||
import { getFormattedAmtFromValueView } from '@penumbra-zone/types/value-view'; | ||
import { Metadata, ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
import { Fee } from '@penumbra-zone/protobuf/penumbra/core/component/fee/v1/fee_pb'; | ||
import type { SwapActionProps } from './swap'; | ||
|
||
export const renderAmount = (value?: ValueView) => { | ||
if (!value) { | ||
return undefined; | ||
} | ||
const symbol = getMetadata.optional(value)?.symbol; | ||
return symbol ? `${getFormattedAmtFromValueView(value)} ${symbol}` : undefined; | ||
}; | ||
|
||
/** | ||
* For Swap and SwapClaim actions, fees contain only the assetId and amount. This function | ||
* calculates a Metadata from this assetId. It firstly tries to get the info from the action itself, | ||
* and if it fails, it takes the Metadata from the registry (or ViewService, if passed). | ||
*/ | ||
export const parseSwapFees = ( | ||
fee?: Fee, | ||
asset1?: Metadata, | ||
asset2?: Metadata, | ||
getMetadataByAssetId?: SwapActionProps['getMetadataByAssetId'], | ||
): string | undefined => { | ||
if (!fee) { | ||
return undefined; | ||
} | ||
|
||
let metadata: Metadata | undefined = undefined; | ||
if (fee.assetId?.equals(asset1?.penumbraAssetId)) { | ||
metadata = asset1; | ||
} | ||
if (fee.assetId?.equals(asset2?.penumbraAssetId)) { | ||
metadata = asset1; | ||
} | ||
|
||
if (!metadata && fee.assetId && getMetadataByAssetId) { | ||
metadata = getMetadataByAssetId(fee.assetId); | ||
} | ||
|
||
if (metadata) { | ||
return renderAmount( | ||
new ValueView({ | ||
valueView: { | ||
case: 'knownAssetId', | ||
value: { | ||
metadata, | ||
amount: fee.amount, | ||
}, | ||
}, | ||
}), | ||
); | ||
} | ||
|
||
return renderAmount( | ||
new ValueView({ | ||
valueView: { | ||
case: 'unknownAssetId', | ||
value: { | ||
assetId: fee.assetId, | ||
amount: fee.amount, | ||
}, | ||
}, | ||
}), | ||
); | ||
}; |
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.