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

Update computation of expiration block height #300

Merged
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
4 changes: 2 additions & 2 deletions src/app/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ export class AccountService {
const btcDepositAddress = 'Not implemented yet';
const ethDepositAddress = 'Not implemented yet';

// days * (24 hours / day) * (60 minutes / hour) * (1 block / 5 minutes) = blocks
const numBlocksBeforeExpiration = (numDaysBeforeExpiration * 24 * 60) / 5;
// days * (24 hours / day) * (60 minutes / hour) * (60 seconds / minute) * (1 block / second) = blocks
const numBlocksBeforeExpiration = numDaysBeforeExpiration * 24 * 60 * 60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, love to see this. 1 second confirmations!!!!


// By default, we authorize this derived key for 8640 blocks, which is about 30 days.
const expirationBlock = blockHeight + numBlocksBeforeExpiration;
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import { TransactionSpendingLimitDaoCoinLimitOrderComponent } from './transactio
import { TransactionSpendingLimitNftComponent } from './transaction-spending-limit/transaction-spending-limit-nft/transaction-spending-limit-nft.component';
import { TransactionSpendingLimitSectionComponent } from './transaction-spending-limit/transaction-spending-limit-section/transaction-spending-limit-section.component';
import { TransactionSpendingLimitComponent } from './transaction-spending-limit/transaction-spending-limit.component';
import { TransactionSpendingLimitStakeComponent } from './transaction-spending-limit/transaction-spending-limit-stake/transaction-spending-limit-stake.component';
import { TransactionSpendingLimitLockupComponent } from './transaction-spending-limit/transaction-spending-limit-lockup/transaction-spending-limit-lockup.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -107,6 +109,8 @@ import { TransactionSpendingLimitComponent } from './transaction-spending-limit/
RecoverySecretComponent,
BackupSeedDialogComponent,
RemoveAccountDialogComponent,
TransactionSpendingLimitStakeComponent,
TransactionSpendingLimitLockupComponent,
],
imports: [
BrowserModule,
Expand Down
43 changes: 42 additions & 1 deletion src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export type LimitOperationString =
| NFTLimitOperationString
| AssociationOperationString
| AccessGroupOperationString
| AccessGroupMemberOperationString;
| AccessGroupMemberOperationString
| LockupLimitOperationString;
export type CreatorCoinOperationLimitMap =
CoinOperationLimitMap<CreatorCoinLimitOperationString>;
export type DAOCoinOperationLimitMap =
Expand Down Expand Up @@ -236,6 +237,42 @@ export type AccessGroupMemberLimitMapItem = {
OpCount: number;
};

export type StakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
StakeLimit: string; // Hex string
};

export type UnstakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
UnstakeLimit: string; // Hex string
};

export type UnlockStakeLimitMapItem = {
ValidatorPublicKeyBase58Check: string;
OpCount: number;
};

export enum LockupLimitScopeType {
ANY = 'AnyCoins',
SCOPED = 'ScopedCoins',
}

export enum LockupLimitOperationString {
ANY = 'Any',
COIN_LOCKUP = 'CoinLockup',
UPDATE_COIN_LOCKUP_YIELD_CURVE = 'UpdateCoinLockupYieldCurve',
UPDATE_COIN_LOCKUP_TRANSFER_RESTRICTIONS = 'UpdateCoinLockupTransferRestrictions',
COIN_LOCKUP_TRANSFER = 'CoinLockupTransferOperationString',
COIN_UNLOCK = 'CoinLockupUnlock',
}

export type LockupLimitMapItem = {
ProfilePublicKeyBase58Check: string;
ScopeType: LockupLimitScopeType;
Operation: LockupLimitOperationString;
OpCount: number;
};

export interface TransactionSpendingLimitResponse {
GlobalDESOLimit: number;
// TODO: make enum for transaction type string
Expand All @@ -247,6 +284,10 @@ export interface TransactionSpendingLimitResponse {
AssociationLimitMap?: AssociationLimitMapItem[];
AccessGroupLimitMap?: AccessGroupLimitMapItem[];
AccessGroupMemberLimitMap?: AccessGroupMemberLimitMapItem[];
StakeLimitMap?: StakeLimitMapItem[];
UnstakeLimitMap?: UnstakeLimitMapItem[];
UnlockStakeLimitMap?: UnlockStakeLimitMapItem[];
LockupLimitMap?: LockupLimitMapItem[];
IsUnlimited?: boolean;
DerivedKeyMemo?: string;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="display--flex justify--between margin-bottom--small">
<div class="text--left width--25">
<img
class="avatar--medium avatar--rounded margin-right--xsmall"
[appAvatar]="lockupLimitMapItem?.ProfilePublicKeyBase58Check"
*ngIf="
lockupLimitMapItem?.ProfilePublicKeyBase58Check &&
appUser?.ProfileEntryResponse?.Username
"
/>
{{
appUser?.ProfileEntryResponse?.Username ||
lockupLimitMapItem?.ProfilePublicKeyBase58Check ||
(lockupLimitMapItem?.ScopeType === LockupLimitScopeType.ANY
? 'Any Profile'
: 'DESO') | truncateAddressOrUsername
}}
</div>
<div class="display-flex justify--center width--50">
<code>
{{ getOperationString() }}
</code>
</div>
<div class="width--25 text--right">
<code>
{{ globalVars.formatTxCountLimit(lockupLimitMapItem?.OpCount) }}
</code>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, Input, OnInit } from '@angular/core';
import { GlobalVarsService } from 'src/app/global-vars.service';
import {
LockupLimitMapItem,
LockupLimitOperationString,
LockupLimitScopeType,
User,
} from '../../backend-api.service';
import { TransactionSpendingLimitComponent } from '../transaction-spending-limit.component';

@Component({
selector: 'app-transaction-spending-limit-lockup',
templateUrl: './transaction-spending-limit-lockup.component.html',
styleUrls: ['./transaction-spending-limit-lockup.component.scss'],
})
export class TransactionSpendingLimitLockupComponent implements OnInit {
@Input() lockupLimitMapItem: LockupLimitMapItem | undefined;
@Input() appUser: User | undefined;
TransactionSpendingLimitComponent = TransactionSpendingLimitComponent;
LockupLimitScopeType = LockupLimitScopeType;

constructor(public globalVars: GlobalVarsService) {}

ngOnInit(): void {}

getOperationString(): string {
switch (this.lockupLimitMapItem?.Operation) {
case LockupLimitOperationString.ANY:
return 'Any';
case LockupLimitOperationString.COIN_LOCKUP:
return 'Lockup';
case LockupLimitOperationString.COIN_LOCKUP_TRANSFER:
return 'Transfer';
case LockupLimitOperationString.UPDATE_COIN_LOCKUP_YIELD_CURVE:
return 'Update lockup yield curve';
case LockupLimitOperationString.UPDATE_COIN_LOCKUP_TRANSFER_RESTRICTIONS:
return 'Update transfer restriction';
case LockupLimitOperationString.COIN_UNLOCK:
return 'Unlock coins';
default:
return '';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,135 @@
></app-transaction-spending-limit-access-group-member>
</div>
</ng-container>
<ng-container
*ngIf="sectionTitle === TransactionSpendingLimitComponent.StakeSection"
>
<div class="display--flex justify--between items--center">
<div class="text--text-lightest">Validator</div>
<div class="text--text-lightest">Amount</div>
</div>
<div
*ngIf="anyValidatorItem"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="anyValidatorItem"
[operationName]="'Stake'"
></app-transaction-spending-limit-stake>
</div>
<div
*ngFor="
let stakeLimitMapItem of stakeLimitMap
| slice : 0 : (showAll ? stakeLimitMap.length : defaultNumShown)
"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="stakeLimitMapItem"
[appUser]="userMap[stakeLimitMapItem.ValidatorPublicKeyBase58Check]"
[operationName]="'Stake'"
></app-transaction-spending-limit-stake>
</div>
</ng-container>
<ng-container
*ngIf="
sectionTitle === TransactionSpendingLimitComponent.UnstakeSection
"
>
<div class="display--flex justify--between items--center">
<div class="text--text-lightest">Validator</div>
<div class="text--text-lightest">Amount</div>
</div>
<div
*ngIf="anyValidatorItem"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="anyValidatorItem"
[operationName]="'Unstake'"
></app-transaction-spending-limit-stake>
</div>
<div
*ngFor="
let unstakeLimitMapItem of unstakeLimitMap
| slice : 0 : (showAll ? unstakeLimitMap.length : defaultNumShown)
"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="unstakeLimitMapItem"
[appUser]="
userMap[unstakeLimitMapItem.ValidatorPublicKeyBase58Check]
"
[operationName]="'Unstake'"
></app-transaction-spending-limit-stake>
</div>
</ng-container>
<ng-container
*ngIf="
sectionTitle === TransactionSpendingLimitComponent.UnlockStakeSection
"
>
<div class="display--flex justify--between items--center">
<div class="text--text-lightest">Validator</div>
<div class="text--text-lightest">Txn Limit</div>
</div>
<div
*ngIf="anyValidatorItem"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="anyValidatorItem"
[operationName]="'Unlock Stake'"
></app-transaction-spending-limit-stake>
</div>
<div
*ngFor="
let unlockStakeLimitMapItem of unlockStakeLimitMap
| slice
: 0
: (showAll ? unlockStakeLimitMap.length : defaultNumShown)
"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-stake
[stakeLimitMapItem]="unlockStakeLimitMapItem"
[appUser]="
userMap[unlockStakeLimitMapItem.ValidatorPublicKeyBase58Check]
"
[operationName]="'Unlock Stake'"
></app-transaction-spending-limit-stake>
</div>
</ng-container>
<ng-container
*ngIf="sectionTitle === TransactionSpendingLimitComponent.LockupSection"
>
<div class="display--flex justify--between items--center">
<div class="text--text-lightest">Profile</div>
<div class="text--text-lightest">Operation</div>
<div class="text--text-lightest">Txn Limit</div>
</div>
<div
*ngFor="let lockupLimitItem of anyLockupLimitItems"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-lockup
[lockupLimitMapItem]="lockupLimitItem"
></app-transaction-spending-limit-lockup>
</div>
<div
*ngFor="
let lockupLimitMapItem of lockupLimitMap
| slice : 0 : (showAll ? lockupLimitMap.length : defaultNumShown)
"
class="display--flex flex--column padding-top--small justify--between"
>
<app-transaction-spending-limit-lockup
[lockupLimitMapItem]="lockupLimitMapItem"
[appUser]="userMap[lockupLimitMapItem.ProfilePublicKeyBase58Check]"
></app-transaction-spending-limit-lockup>
</div>
</ng-container>
</div>
</div>

Expand Down
Loading
Loading