diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index 0ded810..6d6feb3 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -26,7 +26,9 @@ import { TokenLockResponse, TokenLockWithCurrencyId, TransactionReference, - WithdrawDelegatedStake + WithdrawDelegatedStake, + TokenLockWithParent, + SignedTokenLock } from "@stardust-collective/dag4-network"; import { BigNumber } from "bignumber.js"; import { Subject } from "rxjs"; @@ -660,7 +662,7 @@ export class DagAccount { unlockEpoch: number | null; currencyId: string | null; fee?: number; - replaceTokenLockRef: string | null; + replaceTokenLockRef?: string | null; }) { console.warn( "postTokenLock() is deprecated. Use createTokenLock() instead." @@ -677,7 +679,7 @@ export class DagAccount { } let tokenLockLastRef: TransactionReference | null = null; - let signedTokenLock: any | null = null; + let signedTokenLock: SignedTokenLock | null = null; let tokenLockResponse: { hash: string } | null = null; try { @@ -697,7 +699,7 @@ export class DagAccount { try { // Generate signed token lock body - const tokenLockBody = { + const tokenLockBody: TokenLockWithParent = { source, amount, parent: tokenLockLastRef, @@ -739,7 +741,7 @@ export class DagAccount { return tokenLockResponse; } - async createTokenLock(body: TokenLock, params?: Record) { + async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -747,7 +749,7 @@ export class DagAccount { throw new Error("body must be a valid object"); } - const bodyWithCurrencyId: TokenLockWithCurrencyId = { + const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = { ...body, currencyId: null, }; diff --git a/packages/dag4-wallet/src/metagraph-token-client.ts b/packages/dag4-wallet/src/metagraph-token-client.ts index 813580a..ae6d611 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -266,7 +266,7 @@ class MetagraphTokenClient { return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params); } - async createTokenLock(body: TokenLock, params?: Record) { + async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -274,7 +274,7 @@ class MetagraphTokenClient { throw new Error("body must be a valid object"); } - const bodyWithCurrencyId: TokenLockWithCurrencyId = { + const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = { ...body, currencyId: this.networkInfo.metagraphId, }; diff --git a/packages/dag4-wallet/src/shared/operations.ts b/packages/dag4-wallet/src/shared/operations.ts index 8cfca5c..189818f 100644 --- a/packages/dag4-wallet/src/shared/operations.ts +++ b/packages/dag4-wallet/src/shared/operations.ts @@ -97,7 +97,7 @@ export const allowSpend = async ( }; export const tokenLock = async ( - body: TokenLockWithCurrencyId, + body: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null }, network: SharedNetwork, keyTrio: KeyTrio, params?: Record diff --git a/packages/dag4-wallet/src/validationSchemas.ts b/packages/dag4-wallet/src/validationSchemas.ts index 6ab3306..7bea8b5 100644 --- a/packages/dag4-wallet/src/validationSchemas.ts +++ b/packages/dag4-wallet/src/validationSchemas.ts @@ -77,7 +77,8 @@ export const tokenLockSchema = z.object({ .union([z.string(), z.null()]) .refine((value) => value === null || value !== "", { message: "Must be a valid hash or null", - }), + }) + .nullish(), }); /**