@@ -37,6 +37,16 @@ import {
3737 TransactionMetadataUpdateNFT ,
3838 TransactionMetadataUpdateProfile ,
3939 TransactionSpendingLimit ,
40+ TransactionMetadataRegisterAsValidator ,
41+ TransactionMetadataUnregisterAsValidator ,
42+ TransactionMetadataStake ,
43+ TransactionMetadataUnstake ,
44+ TransactionMetadataUnlockStake ,
45+ TransactionMetadataUnjailValidator ,
46+ TransactionMetadataCoinLockup ,
47+ TransactionMetadataUpdateCoinLockupParams ,
48+ TransactionMetadataCoinLockupTransfer ,
49+ TransactionMetadataCoinUnlock ,
4050} from '../../lib/deso/transaction' ;
4151import { ExtraData } from '../../types/identity' ;
4252import { AccountService } from '../account.service' ;
@@ -304,12 +314,12 @@ export class ApproveComponent implements OnInit {
304314 ) ;
305315 publicKeys = [ daoCoinPublicKey ] ;
306316 if ( daoCoinMetadata . operationType === 0 ) {
307- const mintAmount = this . hexNanosToUnitString (
317+ const mintAmount = this . hexBaseUnitsToUnitString (
308318 daoCoinMetadata . coinsToMintNanos
309319 ) ;
310320 description = `mint ${ mintAmount } ${ daoCoinPublicKey } DAO coins` ;
311321 } else if ( daoCoinMetadata . operationType === 1 ) {
312- const burnAmount = this . hexNanosToUnitString (
322+ const burnAmount = this . hexBaseUnitsToUnitString (
313323 daoCoinMetadata . coinsToBurnNanos
314324 ) ;
315325 description = `burn ${ burnAmount } ${ daoCoinPublicKey } DAO coins` ;
@@ -322,7 +332,7 @@ export class ApproveComponent implements OnInit {
322332 case TransactionMetadataTransferDAOCoin :
323333 const daoCoinTransferMetadata = this . transaction
324334 . metadata as TransactionMetadataTransferDAOCoin ;
325- const daoCoinTransferAmount = this . hexNanosToUnitString (
335+ const daoCoinTransferAmount = this . hexBaseUnitsToUnitString (
326336 daoCoinTransferMetadata . daoCoinToTransferNanos
327337 ) ;
328338 const daoCoinTransferPublicKey = this . base58KeyCheck (
@@ -388,6 +398,7 @@ export class ApproveComponent implements OnInit {
388398 this . hexScaledExchangeRateToFloat (
389399 daoCoinLimitOrderMetadata . scaledExchangeRateCoinsToSellPerCoinToBuy
390400 ) ;
401+ // TODO: figure out if we need to use hexBaseUnitsToUnitString here.
391402 const quantityToFill = this . hexNanosToUnitString (
392403 daoCoinLimitOrderMetadata . quantityToFillInBaseUnits
393404 ) ;
@@ -588,6 +599,120 @@ export class ApproveComponent implements OnInit {
588599 description = `unknown messaging action on ${ messageType } to ${ recipient } ` ;
589600 }
590601 break ;
602+ case TransactionMetadataRegisterAsValidator :
603+ // TODO: Do we want any additional details in the approve component?
604+ description = 'register as a validator' ;
605+ break ;
606+ case TransactionMetadataUnregisterAsValidator :
607+ description = 'unregister as a validator' ;
608+ break ;
609+ case TransactionMetadataStake :
610+ const stakeMetadata = this . transaction
611+ . metadata as TransactionMetadataStake ;
612+ const stakeValidatorPublicKey = this . base58KeyCheck (
613+ stakeMetadata . validatorPublicKey
614+ ) ;
615+ publicKeys = [ stakeValidatorPublicKey ] ;
616+ const stakeAmountNanos = this . hexNanosToUnitString (
617+ stakeMetadata . stakeAmountNanos
618+ ) ;
619+ description = `stake ${ stakeAmountNanos } $DESO to ${ stakeValidatorPublicKey } ` ;
620+ break ;
621+ case TransactionMetadataUnstake :
622+ const unstakeMetadata = this . transaction
623+ . metadata as TransactionMetadataUnstake ;
624+ const unstakeValidatorPublicKey = this . base58KeyCheck (
625+ unstakeMetadata . validatorPublicKey
626+ ) ;
627+ publicKeys = [ unstakeValidatorPublicKey ] ;
628+ const unstakeAmountNanos = this . hexNanosToUnitString (
629+ unstakeMetadata . unstakeAmountNanos
630+ ) ;
631+ description = `unstake ${ unstakeAmountNanos } $DESO from ${ unstakeValidatorPublicKey } ` ;
632+ break ;
633+ case TransactionMetadataUnlockStake :
634+ const unlockStakeMetadata = this . transaction
635+ . metadata as TransactionMetadataUnlockStake ;
636+ const unlockStakeValidatorPublicKey = this . base58KeyCheck (
637+ unlockStakeMetadata . validatorPublicKey
638+ ) ;
639+ publicKeys = [ unlockStakeValidatorPublicKey ] ;
640+ description =
641+ `unlock stake from ${ unlockStakeValidatorPublicKey } , ` +
642+ `starting from epochs ${ unlockStakeMetadata . startEpochNumber } to ${ unlockStakeMetadata . endEpochNumber } ` ;
643+ break ;
644+ case TransactionMetadataUnjailValidator :
645+ description = 'unjail your validator' ;
646+ break ;
647+ case TransactionMetadataCoinLockup :
648+ // NOTE: we don't need a special case for DESO right now
649+ // as lockups are not allowed for DESO at this time.
650+ const coinLockupMetadata = this . transaction
651+ . metadata as TransactionMetadataCoinLockup ;
652+ const lockupAmount = this . hexBaseUnitsToUnitString (
653+ coinLockupMetadata . lockupAmountBaseUnits
654+ ) ;
655+ const lockupProfilePubKey = this . base58KeyCheck (
656+ coinLockupMetadata . profilePublicKey
657+ ) ;
658+ const lockUpRecipientPubKey = this . base58KeyCheck (
659+ coinLockupMetadata . recipientPublicKey
660+ ) ;
661+ publicKeys = [ lockupProfilePubKey , lockUpRecipientPubKey ] ;
662+ description = `lockup ${ lockupAmount } of your ${ lockupProfilePubKey } coins` ;
663+ break ;
664+ case TransactionMetadataUpdateCoinLockupParams :
665+ const updateCoinLockupParamsMetadata = this . transaction
666+ . metadata as TransactionMetadataUpdateCoinLockupParams ;
667+ description =
668+ `update your coin lockup params\n` +
669+ `${
670+ updateCoinLockupParamsMetadata . removeYieldCurvePoint
671+ ? 'Remove'
672+ : 'Add'
673+ } yield curve point with
674+ ${
675+ updateCoinLockupParamsMetadata . lockupYieldAPYBasisPoints / 100
676+ } % APY for a lockup of
677+ ${
678+ updateCoinLockupParamsMetadata . lockupYieldDurationNanoSecs
679+ } nanoseconds
680+ ${
681+ ! updateCoinLockupParamsMetadata . newLockupTransferRestrictions
682+ ? ''
683+ : 'and update your lockup transfer restrictions'
684+ } `;
685+
686+ break ;
687+ case TransactionMetadataCoinLockupTransfer :
688+ // NOTE: we don't need a special case for DESO right now
689+ // as lockups are not allowed for DESO at this time.
690+ const coinLockupTransferMetadata = this . transaction
691+ . metadata as TransactionMetadataCoinLockupTransfer ;
692+ const lockupTransferAmount = this . hexBaseUnitsToUnitString (
693+ coinLockupTransferMetadata . lockedCoinsToTransferBaseUnits
694+ ) ;
695+ const lockupTransferProfilePubKey = this . base58KeyCheck (
696+ coinLockupTransferMetadata . profilePublicKey
697+ ) ;
698+ const lockupTransferRecipientPubKey = this . base58KeyCheck (
699+ coinLockupTransferMetadata . recipientPublicKey
700+ ) ;
701+ publicKeys = [
702+ lockupTransferProfilePubKey ,
703+ lockupTransferRecipientPubKey ,
704+ ] ;
705+ description = `transfer ${ lockupTransferAmount } of your locked ${ lockupTransferProfilePubKey } coins to ${ lockupTransferRecipientPubKey } ` ;
706+ break ;
707+ case TransactionMetadataCoinUnlock :
708+ const coinUnlockMetadata = this . transaction
709+ . metadata as TransactionMetadataCoinUnlock ;
710+ const unlockProfilePubKey = this . base58KeyCheck (
711+ coinUnlockMetadata . profilePublicKey
712+ ) ;
713+ publicKeys = [ unlockProfilePubKey ] ;
714+ description = `unlock your locked ${ unlockProfilePubKey } coins` ;
715+ break ;
591716 }
592717
593718 // Set the transaction description based on the description populated with public keys.
@@ -608,14 +733,24 @@ export class ApproveComponent implements OnInit {
608733 return bs58check . encode ( Buffer . from ( [ ...prefix , ...keyBytes ] ) ) ;
609734 }
610735
736+ // uint256 to DESO nano conversions.
611737 hexNanosToUnitString ( nanos : Buffer ) : string {
612738 return this . nanosToUnitString ( parseInt ( nanos . toString ( 'hex' ) , 16 ) ) ;
613739 }
614740
741+ // unit256 to base unit conversions.
742+ hexBaseUnitsToUnitString ( baseUnits : Buffer ) : string {
743+ return this . baseUnitsToUnitString ( parseInt ( baseUnits . toString ( 'hex' ) , 16 ) ) ;
744+ }
745+
615746 nanosToUnitString ( nanos : number ) : string {
616747 return this . toFixedLengthDecimalString ( nanos / 1e9 ) ;
617748 }
618749
750+ baseUnitsToUnitString ( baseUnits : number ) : string {
751+ return this . toFixedLengthDecimalString ( baseUnits / 1e18 ) ;
752+ }
753+
619754 hexScaledExchangeRateToFloat ( hex : Buffer ) : number {
620755 return parseInt ( hex . toString ( 'hex' ) , 16 ) / 1e38 ;
621756 }
0 commit comments