Skip to content

Commit

Permalink
wait for txn in metamask flow (#305)
Browse files Browse the repository at this point in the history
* wait for txn in metamask flow

* lint
  • Loading branch information
lazynina authored Nov 1, 2024
1 parent e088c39 commit d4e88a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ export class BackendAPIService {

SendStarterDeSoForMetamaskAccount(
request: MetamaskSignInRequest
): Observable<any> {
): Observable<{ TxnHash: number[] }> {
return this.post('send-starter-deso-for-metamask-account', request).pipe(
catchError((err) => {
console.error(JSON.stringify(err));
Expand Down Expand Up @@ -855,9 +855,13 @@ export class BackendAPIService {
);
}

GetTxn(TxnHashHex: string): Observable<any> {
GetTxn(
TxnHashHex: string,
TxnStatus: 'InMempool' | 'Committed'
): Observable<any> {
return this.post('get-txn', {
TxnHashHex,
...(TxnStatus ? { TxnStatus } : {}),
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/sign-up-metamask/sign-up-metamask.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class SignUpMetamaskComponent implements OnInit {
this.cryptoService.publicKeyToDeSoPublicKey(metamaskKeyPair, network);

try {
await this.backendApi
const { TxnHash } = await this.backendApi
.SendStarterDeSoForMetamaskAccount({
Signer: metamaskKeyPair.getPublic().encode('array', true),
AmountNanos: 1000,
Expand All @@ -171,6 +171,8 @@ export class SignUpMetamaskComponent implements OnInit {
],
})
.toPromise();
const txnHashHex = Buffer.from(TxnHash).toString('hex');
await this.backendApi.GetTxn(txnHashHex, 'Committed').toPromise();
} catch (e) {
// if they received the account, or if they have funds don't error out of the flow,
// just move on to the next step
Expand Down

0 comments on commit d4e88a7

Please sign in to comment.