Skip to content

Commit

Permalink
Custom metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Aug 7, 2024
1 parent b0bf22c commit a78ac02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/requests/split-swap-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class SplitSwapRequest {
private _swapInToken: Token;
private _swapOutToken: Token;
private _slippagePercent: number = 1.0;
private _metadata: string = '';

constructor(dexter: Dexter) {
this._dexter = dexter;
Expand Down Expand Up @@ -52,6 +53,12 @@ export class SplitSwapRequest {
return this;
}

public withMetadata(metadata: string): SplitSwapRequest {
this._metadata = metadata;

return this;
}

public withSwapInToken(swapInToken: Token): SplitSwapRequest {
this._swapInToken = swapInToken;

Expand Down Expand Up @@ -190,7 +197,7 @@ export class SplitSwapRequest {
const swapOutTokenName: string = this._swapOutToken === 'lovelace' ? 'ADA' : this._swapOutToken.assetName;
splitSwapTransaction.attachMetadata(MetadataKey.Message, {
msg: [
`[${this._dexter.config.metadataMsgBranding}] Split ${swapInTokenName} -> ${swapOutTokenName} Swap`
this._metadata ?? `[${this._dexter.config.metadataMsgBranding}] Split ${swapInTokenName} -> ${swapOutTokenName} Swap`
]
});

Expand Down
9 changes: 8 additions & 1 deletion src/requests/swap-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SwapRequest {
private _swapInAmount: bigint = 0n;
private _slippagePercent: number = 1.0;
private _withUtxos: UTxO[] = [];
private _metadata: string = '';

constructor(dexter: Dexter) {
this._dexter = dexter;
Expand Down Expand Up @@ -59,6 +60,12 @@ export class SwapRequest {
return this;
}

public withMetadata(metadata: string): SwapRequest {
this._metadata = metadata;

return this;
}

public withSwapInToken(swapInToken: Token): SwapRequest {
if (! this._liquidityPool) {
throw new Error('Liquidity pool must be set before providing an input token.');
Expand Down Expand Up @@ -272,7 +279,7 @@ export class SwapRequest {
const swapOutTokenName: string = this._swapOutToken === 'lovelace' ? 'ADA' : this._swapOutToken.assetName;
swapTransaction.attachMetadata(MetadataKey.Message, {
msg: [
`[${this._dexter.config.metadataMsgBranding}] ${this._liquidityPool.dex} ${swapInTokenName} -> ${swapOutTokenName} Swap`
this._metadata ?? `[${this._dexter.config.metadataMsgBranding}] ${this._liquidityPool.dex} ${swapInTokenName} -> ${swapOutTokenName} Swap`
]
});

Expand Down

0 comments on commit a78ac02

Please sign in to comment.