Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWN-6097] autoselect token from URL on reload #260

Open
wants to merge 1 commit into
base: mvvm
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/web/src/new/scenes/Main/Send/Send.ViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class SendViewModel
this.chooseTokenAndAmountViewModel.initialize();
this.selectAddressViewModel.initialize();
this.choosePayingWalletViewModel.initialize();
this.walletsRepository.reload();

this._bind();
this.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class SwapViewModel extends ViewModel implements SwapViewModelType {
this.chooseSourceWalletViewModel.initialize();
this.chooseDestinationWalletViewModel.initialize();
this.swapSettingsViewModel.initialize();
this._walletsRepository.reload();

// TODO: really wait until wallets load?
this.addReaction(
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/new/services/Repositories/WalletsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class WalletsRepository extends SDListViewModel<Wallet> {
// Properties

private _timer?: NodeJS.Timeout;
private _wasRequested = false;

// Getters

Expand Down Expand Up @@ -67,6 +68,12 @@ export class WalletsRepository extends SDListViewModel<Wallet> {
this._stopObserving();
}

override reload(): void {
if (!this._wasRequested) {
Copy link
Collaborator

@beautyfree beautyfree Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reload never calls twice because of this condition, and because _wasRequested never become false. do you think its right?

super.reload();
}
}

// Binding
private _bind(): void {
// observe prices
Expand Down Expand Up @@ -129,6 +136,8 @@ export class WalletsRepository extends SDListViewModel<Wallet> {
override createRequest = flow<Wallet[], []>(function* (
this: WalletsRepository,
): Generator<Promise<Wallet[]>> {
this._wasRequested = true;

return yield Promise.all([
// TODO: encapsulate address to service
this._solanaService.provider.connection.getBalance(
Expand Down Expand Up @@ -171,6 +180,8 @@ export class WalletsRepository extends SDListViewModel<Wallet> {
});

private _getNewWallets(): Promise<void> {
this._wasRequested = true;

return this._solanaService
.getTokenWallets(this._solanaService.provider.wallet.publicKey.toString())
.then((wallets) => {
Expand Down