Skip to content
Draft
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
224 changes: 177 additions & 47 deletions src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class BackendRoutes {
static RoutePathSubmitPost = '/api/v0/submit-post';
static RoutePathUploadImage = '/api/v0/upload-image';
static RoutePathSubmitTransaction = '/api/v0/submit-transaction';
static RoutePathSubmitAtomicTransaction = '/api/v0/submit-atomic-transaction';
static RoutePathUpdateProfile = '/api/v0/update-profile';
static RoutePathSubsidizedUpdateProfile = '/api/v0/subsidized-update-profile';
static RoutePathGetPostsStateless = '/api/v0/get-posts-stateless';
static RoutePathGetHotFeed = '/api/v0/get-hot-feed';
static RoutePathGetProfiles = '/api/v0/get-profiles';
Expand Down Expand Up @@ -747,6 +749,58 @@ export class BackendApiService {
this.identityService.identityServicePublicKeyAdded = publicKeyAdded;
}

signAndSubmitSubsidizedUpdateProfileTransaction(
endpoint: string,
request: Observable<any>,
PublicKeyBase58Check: string
): Observable<any> {
let incompleteAtomicTransactionHex: string = '';
return request
.pipe(
// Collect the signature for the unsigned update profile transaction.
switchMap((res) => {
// Capture the incomplete atomic transaction.
incompleteAtomicTransactionHex = res.IncompleteAtomicTransactionHex;

// Continue processing without the incomplete atomic transaction.
// Hit the identity service to sign the update profile transaction.
return this.identityService
.sign({
transactionHex: res.UpdateProfileTransactionHex,
...this.identityService.identityServiceParamsForKey(
PublicKeyBase58Check
),
})
.pipe(
switchMap((signed) => {
return this.identityService
.launch('/approve', {
tx: res.UpdateProfileTransactionHex,
})
.pipe(
map((approved) => {
this.setIdentityServiceUsers(approved.users);
return { ...res, ...approved };
})
);
})
);
})
)
.pipe(
// Construct the atomic transaction and submit.
// Submit the incomplete atomic transaction along with the new transaction.
switchMap((res) =>
this.SubmitAtomicTransaction(
endpoint,
incompleteAtomicTransactionHex,
[res.signedTransactionHex]
).pipe(map((broadcasted) => ({ ...res, ...broadcasted })))
)
)
.pipe(catchError(this._handleError));
}

signAndSubmitTransaction(
endpoint: string,
request: Observable<any>,
Expand All @@ -765,16 +819,16 @@ export class BackendApiService {
.pipe(
switchMap((signed) => {
//if (signed.approvalRequired) {
return this.identityService
.launch('/approve', {
tx: res.TransactionHex,
return this.identityService
.launch('/approve', {
tx: res.TransactionHex,
})
.pipe(
map((approved) => {
this.setIdentityServiceUsers(approved.users);
return { ...res, ...approved };
})
.pipe(
map((approved) => {
this.setIdentityServiceUsers(approved.users);
return { ...res, ...approved };
})
);
);
//} else {
// return of({ ...res, ...signed });
//}
Expand Down Expand Up @@ -1004,6 +1058,17 @@ export class BackendApiService {
});
}

SubmitAtomicTransaction(
endpoint: string,
IncompleteAtomicTransactionHex: string,
SignedInnerTransactionsHex: string[]
): Observable<any> {
return this.post(endpoint, BackendRoutes.RoutePathSubmitAtomicTransaction, {
IncompleteAtomicTransactionHex,
SignedInnerTransactionsHex,
});
}

SendMessage(
endpoint: string,
SenderPublicKeyBase58Check: string,
Expand Down Expand Up @@ -1967,6 +2032,51 @@ export class BackendApiService {
});
}

SubsidizedUpdateProfile(
endpoint: string,
// Specific fields
UpdaterPublicKeyBase58Check: string,
// Optional: Only needed when updater public key != profile public key
ProfilePublicKeyBase58Check: string,
NewUsername: string,
NewDescription: string,
NewProfilePic: string,
NewCreatorBasisPoints: number,
NewStakeMultipleBasisPoints: number,
IsHidden: boolean,
// End specific fields
MinFeeRateNanosPerKB: number
): Observable<any> {
NewCreatorBasisPoints = Math.floor(NewCreatorBasisPoints);
NewStakeMultipleBasisPoints = Math.floor(NewStakeMultipleBasisPoints);

const request = this.post(
endpoint,
BackendRoutes.RoutePathSubsidizedUpdateProfile,
{
UpdaterPublicKeyBase58Check,
ProfilePublicKeyBase58Check,
NewUsername,
NewDescription,
NewProfilePic,
NewCreatorBasisPoints,
NewStakeMultipleBasisPoints,
IsHidden,
MinFeeRateNanosPerKB,
}
);

// NOTE: Unlike the traditional UpdateProfile endpoint, there's
// no need to wait for a subsidization transaction to be broadcast
// across the network as the subsidization transaction is bundled
// together in the returned atomic transaction.
return this.signAndSubmitSubsidizedUpdateProfileTransaction(
endpoint,
request,
UpdaterPublicKeyBase58Check
);
}

UpdateProfile(
endpoint: string,
// Specific fields
Expand Down Expand Up @@ -2950,7 +3060,7 @@ export class BackendApiService {

Username: string,
IsBlacklistUpdate: boolean,
AddUserToList: boolean,
AddUserToList: boolean
): Observable<any> {
return this.jwtPost(
endpoint,
Expand Down Expand Up @@ -3895,12 +4005,24 @@ export class BackendApiService {
return this.get(endpoint, BackendRoutes.RoutePathGetCountKeysWithDESO);
}

GetLockupYieldCurvePoints(endpoint: string, publicKey: string): Observable<LockupYieldCurvePointResponse[]> {
return this.get(endpoint, BackendRoutes.RoutePathLockupYieldCurvePoints + "/" + publicKey);
GetLockupYieldCurvePoints(
endpoint: string,
publicKey: string
): Observable<LockupYieldCurvePointResponse[]> {
return this.get(
endpoint,
BackendRoutes.RoutePathLockupYieldCurvePoints + '/' + publicKey
);
}

GetLockedBalanceEntries(endpoint: string, publicKey: string): Observable<CumulativeLockedBalanceEntryResponse[]> {
return this.get(endpoint, BackendRoutes.RoutePathLockedBalanceEntries + "/" + publicKey);
GetLockedBalanceEntries(
endpoint: string,
publicKey: string
): Observable<CumulativeLockedBalanceEntryResponse[]> {
return this.get(
endpoint,
BackendRoutes.RoutePathLockedBalanceEntries + '/' + publicKey
);
}

CoinLockup(
Expand All @@ -3922,14 +4044,14 @@ export class BackendApiService {
VestingEndTimestampNanoSecs,
LockupAmountBaseUnits,
ExtraData,
MinFeeRateNanosPerKB,
});
MinFeeRateNanosPerKB,
});
return this.signAndSubmitTransaction(
endpoint,
request,
TransactorPublicKeyBase58Check,
)
};
TransactorPublicKeyBase58Check
);
}

UpdateCoinLockupParams(
endpoint: string,
Expand All @@ -3942,22 +4064,26 @@ export class BackendApiService {
ExtraData: { [k: string]: string },
MinFeeRateNanosPerKB: number
): Observable<any> {
const request = this.post(endpoint, BackendRoutes.RoutePathUpdateCoinLockupParams, {
TransactorPublicKeyBase58Check,
LockupYieldDurationNanoSecs,
LockupYieldAPYBasisPoints,
RemoveYieldCurvePoint,
NewLockupTransferRestrictions,
LockupTransferRestrictionStatus,
ExtraData,
MinFeeRateNanosPerKB,
});
const request = this.post(
endpoint,
BackendRoutes.RoutePathUpdateCoinLockupParams,
{
TransactorPublicKeyBase58Check,
LockupYieldDurationNanoSecs,
LockupYieldAPYBasisPoints,
RemoveYieldCurvePoint,
NewLockupTransferRestrictions,
LockupTransferRestrictionStatus,
ExtraData,
MinFeeRateNanosPerKB,
}
);
return this.signAndSubmitTransaction(
endpoint,
request,
TransactorPublicKeyBase58Check,
)
};
TransactorPublicKeyBase58Check
);
}

CoinLockupTransfer(
endpoint: string,
Expand All @@ -3969,21 +4095,25 @@ export class BackendApiService {
ExtraData: { [k: string]: string },
MinFeeRateNanosPerKB: number
): Observable<any> {
const request = this.post(endpoint, BackendRoutes.RoutePathCoinLockupTransfer, {
TransactorPublicKeyBase58Check,
ProfilePublicKeyBase58Check,
RecipientPublicKeyBase58Check,
UnlockTimestampNanoSecs,
LockedCoinsToTransferBaseUnits,
ExtraData,
MinFeeRateNanosPerKB,
});
const request = this.post(
endpoint,
BackendRoutes.RoutePathCoinLockupTransfer,
{
TransactorPublicKeyBase58Check,
ProfilePublicKeyBase58Check,
RecipientPublicKeyBase58Check,
UnlockTimestampNanoSecs,
LockedCoinsToTransferBaseUnits,
ExtraData,
MinFeeRateNanosPerKB,
}
);
return this.signAndSubmitTransaction(
endpoint,
request,
TransactorPublicKeyBase58Check,
)
};
TransactorPublicKeyBase58Check
);
}

CoinUnlock(
endpoint: string,
Expand All @@ -4001,9 +4131,9 @@ export class BackendApiService {
return this.signAndSubmitTransaction(
endpoint,
request,
TransactorPublicKeyBase58Check,
)
};
TransactorPublicKeyBase58Check
);
}

// Error parsing
stringifyError(err): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ <h5 class="fs-15px">Everyone needs a profile. Let's update yours!</h5>
<div class="w-100 my-30px d-flex">
<div>
<a
(click)="_updateProfile()"
(click)="_subsidizedUpdateProfile()"
[ngClass]="{ 'btn-loading': updateProfileBeingCalled }"
class="btn btn-primary btn-lg font-weight-bold fs-15px mt-5px"
>
Expand Down
Loading