Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 762e95a

Browse files
authored
feat: reset fields after transfer is complete (#163)
closes #133
1 parent d29771e commit 762e95a

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

packages/widget/src/components/common/dropdown/dropdown.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { when } from 'lit/directives/when.js';
66

77
import { chevronIcon, networkIconsMap } from '../../../assets';
88
import { capitalize } from '../../../utils';
9-
import { BaseComponent } from '../base-component/base-component';
9+
import { BaseComponent } from '../base-component';
1010

1111
import { styles } from './styles';
1212

@@ -36,14 +36,30 @@ export class Dropdown extends BaseComponent {
3636
@property({ type: Array })
3737
options: DropdownOption[] = [];
3838

39+
@property({ type: String })
40+
preSelectedOption = '';
41+
3942
@state()
4043
selectedOption: DropdownOption | null = null;
4144

4245
@property({ attribute: false })
4346
onOptionSelected: (option?: DropdownOption) => void = () => {};
4447

48+
_setPreselectedOption = (): void => {
49+
if (this.preSelectedOption) {
50+
const newOption =
51+
this.options.find((o) => o.name === this.preSelectedOption) || null;
52+
53+
if (newOption) {
54+
this.selectedOption = newOption;
55+
this.onOptionSelected(newOption);
56+
}
57+
}
58+
};
59+
4560
connectedCallback(): void {
4661
super.connectedCallback();
62+
this._setPreselectedOption();
4763
addEventListener('click', this._handleOutsideClick);
4864
}
4965

@@ -54,13 +70,27 @@ export class Dropdown extends BaseComponent {
5470

5571
updated(changedProperties: PropertyValues<typeof this>): void {
5672
super.updated(changedProperties);
73+
74+
// Set pre-selected option after transfer is completed
75+
if (
76+
changedProperties.has('options') &&
77+
this.preSelectedOption &&
78+
this.selectedOption?.name !== this.preSelectedOption
79+
) {
80+
this._setPreselectedOption();
81+
}
82+
5783
//if options changed, check if we have selected option that doesn't exist
5884
if (changedProperties.has('options') && this.selectedOption) {
5985
if (
6086
!this.options.map((o) => o.value).includes(this.selectedOption.value)
6187
) {
62-
this.selectedOption = null;
63-
this.onOptionSelected(undefined);
88+
if (this.preSelectedOption) {
89+
this._setPreselectedOption();
90+
} else {
91+
this.selectedOption = null;
92+
this.onOptionSelected(undefined);
93+
}
6494
}
6595
}
6696
}

packages/widget/src/components/network-selector/network-selector.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { customElement, property } from 'lit/decorators.js';
55
import { when } from 'lit/directives/when.js';
66

77
import { networkIconsMap } from '../../assets';
8-
import { BaseComponent } from '../common/base-component/base-component';
8+
import { BaseComponent } from '../common';
99
import type { DropdownOption } from '../common/dropdown/dropdown';
1010

1111
import { styles } from './styles';
@@ -28,6 +28,9 @@ export class NetworkSelector extends BaseComponent {
2828
@property({ type: String })
2929
direction?: Direction;
3030

31+
@property({ type: String })
32+
selectedNetwork?: string;
33+
3134
@property({ attribute: false })
3235
onNetworkSelected: (option?: Domain) => void = () => {};
3336

@@ -55,6 +58,7 @@ export class NetworkSelector extends BaseComponent {
5558
render(): HTMLTemplateResult {
5659
return html`<div class="selectorContainer">
5760
<dropdown-component
61+
.preSelectedOption=${this.selectedNetwork}
5862
.disabled=${this.disabled}
5963
.placeholder=${'Select the network'}
6064
.label=${this.direction}

packages/widget/src/components/transfer/fungible/fungible-token-transfer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class FungibleTokenTransfer extends BaseComponent {
7373
}
7474

7575
if (state === FungibleTransferState.COMPLETED) {
76-
this.transferController.reset();
76+
this.transferController.reset({ omitSourceNetworkReset: true });
7777
}
7878
};
7979

@@ -100,6 +100,7 @@ export class FungibleTokenTransfer extends BaseComponent {
100100
return html` <form @submit=${() => {}}>
101101
<section class="networkSelectionWrapper">
102102
<sygma-network-selector
103+
.selectedNetwork=${this.transferController.sourceNetwork?.name}
103104
.direction=${Directions.FROM}
104105
.icons=${true}
105106
.onNetworkSelected=${(network?: Domain) => {

packages/widget/src/components/transfer/fungible/transfer-status/styles.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const styles = css`
1717
align-items: center;
1818
border-radius: 1.5rem;
1919
border: 1px solid var(--zinc-200);
20+
margin-bottom: 1rem;
2021
}
2122
2223
.destinationMessage {
@@ -36,7 +37,7 @@ export const styles = css`
3637
display: flex;
3738
flex-direction: row;
3839
align-items: center;
39-
padding: 0rem 4.78125rem 0.9375rem 4.78125rem;
40+
padding: 0 4.78125rem 0.9375rem 4.78125rem;
4041
4142
color: var(--zinc-600);
4243
text-align: center;
@@ -53,9 +54,7 @@ export const styles = css`
5354
align-items: center;
5455
justify-content: center;
5556
text-align: center;
56-
5757
color: var(--zinc-500);
58-
text-align: center;
5958
font-size: 0.75rem;
6059
font-style: normal;
6160
font-weight: 400;

packages/widget/src/controllers/transfers/fungible-token-transfer.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ export class FungibleTokenTransferController implements ReactiveController {
105105
this.host.requestUpdate();
106106
}
107107

108-
reset(): void {
109-
this.sourceNetwork = undefined;
108+
reset({ omitSourceNetworkReset } = { omitSourceNetworkReset: false }): void {
109+
if (!omitSourceNetworkReset) {
110+
this.sourceNetwork = undefined;
111+
}
110112
this.destinationNetwork = undefined;
111113
this.pendingEvmApprovalTransactions = [];
112114
this.pendingEvmTransferTransaction = undefined;

0 commit comments

Comments
 (0)