Skip to content
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
14 changes: 8 additions & 6 deletions packages/dag4-wallet/src/dag-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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."
Expand All @@ -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 {
Expand All @@ -697,7 +699,7 @@ export class DagAccount {

try {
// Generate signed token lock body
const tokenLockBody = {
const tokenLockBody: TokenLockWithParent = {
source,
amount,
parent: tokenLockLastRef,
Expand Down Expand Up @@ -739,15 +741,15 @@ export class DagAccount {
return tokenLockResponse;
}

async createTokenLock(body: TokenLock, params?: Record<string, any>) {
async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record<string, any>) {
this.assertAccountIsActive();
this.assertValidPrivateKey();

if (!body || typeof body !== "object") {
throw new Error("body must be a valid object");
}

const bodyWithCurrencyId: TokenLockWithCurrencyId = {
const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = {
...body,
currencyId: null,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/dag4-wallet/src/metagraph-token-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ class MetagraphTokenClient {
return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params);
}

async createTokenLock(body: TokenLock, params?: Record<string, any>) {
async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record<string, any>) {
this.account.assertAccountIsActive();
this.account.assertValidPrivateKey();

if (!body || typeof body !== "object") {
throw new Error("body must be a valid object");
}

const bodyWithCurrencyId: TokenLockWithCurrencyId = {
const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = {
...body,
currencyId: this.networkInfo.metagraphId,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/dag4-wallet/src/shared/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>
Expand Down
3 changes: 2 additions & 1 deletion packages/dag4-wallet/src/validationSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

/**
Expand Down