forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstellar-payload.service.ts
More file actions
40 lines (34 loc) · 1.14 KB
/
Copy pathstellar-payload.service.ts
File metadata and controls
40 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Injectable } from "@nestjs/common";
import { StellarService } from "../stellar/stellar.service";
@Injectable()
export class StellarPayloadService {
constructor(private readonly stellarService: StellarService) {}
/**
* Generates a SEP-0007 compliant web+stellar URI
* Format: web+stellar:pay?destination=GC...&amount=10&memo=...
*/
generatePaymentUri(params: {
destination: string;
amount: string;
assetCode?: string;
memo?: string;
}): string {
// Ensure transaction generation uses the currently configured Stellar network
this.stellarService.getNetworkPassphrase();
const baseUrl = "web+stellar:pay";
const query = new URLSearchParams({
destination: params.destination,
amount: params.amount,
});
if (params.assetCode && params.assetCode !== "XLM") {
// For custom assets, format is CODE:ISSUER
const [code, issuer] = params.assetCode.split(":");
query.append("asset_code", code);
if (issuer) query.append("asset_issuer", issuer);
}
if (params.memo) {
query.append("memo", params.memo);
}
return `${baseUrl}?${query.toString()}`;
}
}