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
32 changes: 20 additions & 12 deletions apps/frontend/app/services/wallet/albedo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Import albedo correctly

import albedo from '@albedo-link/intent';

export interface AlbedoIntentResult {
signed_envelope_xdr?: string;
Expand All @@ -21,38 +20,47 @@ export class AlbedoService {

async connect(): Promise<string> {
try {
const result = await this.publicKey()
const result = await this.publicKey();
return result;
} catch (error: any) {
if (error.message?.includes('rejected')) {
throw new Error('Albedo connection was rejected by the user.');
}
throw new Error(`Failed to connect with Albedo: ${error.message}`);
}
}

async signTransaction(xdr: string): Promise<string> {
try {
const result = await "await albedo.signTransaction({xdr, network: this.getNetworkParam()});"
if (!result) {
const result = await albedo.tx({ xdr, network: this.getNetworkParam() });

if (!result.signed_envelope_xdr) {
throw new Error('No signed envelope returned from Albedo');
}
return result;

return result.signed_envelope_xdr;
} catch (error: any) {
if (error.message?.includes('rejected')) {
throw new Error('Transaction signing was rejected by the user.');
}
throw new Error(`Failed to sign transaction with Albedo: ${error.message}`);
}
}

private getNetworkParam(): string {
private getNetworkParam(): 'public' | 'testnet' {
const network = process.env.NEXT_PUBLIC_STELLAR_NETWORK || 'testnet';
return network === 'mainnet' ? 'public' : 'testnet';
}

private async publicKey(): Promise<string> {
try {
const result = "await albedo.publicKey({});"
return result;
const result = await albedo.publicKey({});
return result.pubkey;
} catch (error: any) {
if (error.message?.includes('rejected')) {
throw new Error('Albedo connection was rejected by the user.');
}
throw new Error(`Failed to get public key from Albedo: ${error.message}`);
}
}
}
}
7 changes: 7 additions & 0 deletions apps/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "eslint ."
},
"dependencies": {
"@albedo-link/intent": "^0.13.0",
"@hookform/resolvers": "^5.2.2",
"@stellar/freighter-api": "^6.0.1",
"@tanstack/react-query": "^5.90.20",
Expand Down
Loading