Skip to content

Commit fbaaa96

Browse files
authored
fix: deposit from exchange not reset (#5240)
1 parent 6b543c3 commit fbaaa96

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

.changeset/ten-showers-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@reown/appkit-scaffold-ui': patch
3+
---
4+
5+
Fixes issue where accessing deposit from exchange view while a deposit is in progress resulted in an automatic redirect to account view

packages/scaffold-ui/src/views/w3m-deposit-from-exchange-view/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class W3mDepositFromExchangeView extends LitElement {
5050

5151
public constructor() {
5252
super()
53+
ExchangeController.reset()
5354
this.unsubscribe.push(
5455
ChainController.subscribeKey('activeCaipNetwork', val => {
5556
this.network = val

packages/scaffold-ui/test/views/w3m-deposit-from-exchange-view.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ describe('W3mDepositFromExchangeView', () => {
5151
vi.clearAllMocks()
5252
})
5353

54+
it('should reset state on constructor', async () => {
55+
vi.spyOn(ExchangeController, 'reset')
56+
const element: W3mDepositFromExchangeView = await fixture(
57+
html`<w3m-deposit-from-exchange-view></w3m-deposit-from-exchange-view>`
58+
)
59+
await elementUpdated(element)
60+
expect(ExchangeController.reset).toHaveBeenCalled()
61+
})
62+
5463
it('should fetch and set default payment asset on first update', async () => {
5564
vi.spyOn(ChainController, 'state', 'get').mockReturnValue({
5665
...ChainController.state,
@@ -113,12 +122,6 @@ describe('W3mDepositFromExchangeView', () => {
113122
}
114123

115124
// Seed controller state for exchanges and amount
116-
ExchangeController.state.exchanges = [
117-
{ id: 'ex1', imageUrl: 'https://img1', name: 'Exchange One' },
118-
{ id: 'ex2', imageUrl: 'https://img2', name: 'Exchange Two' }
119-
] as any
120-
ExchangeController.state.amount = 0
121-
ExchangeController.state.paymentAsset = mockPaymentAsset
122125

123126
// Avoid side effects on firstUpdated
124127
vi.spyOn(ExchangeController, 'getAssetsForNetwork').mockResolvedValue([mockPaymentAsset])
@@ -127,6 +130,12 @@ describe('W3mDepositFromExchangeView', () => {
127130
const element: W3mDepositFromExchangeView = await fixture(
128131
html`<w3m-deposit-from-exchange-view></w3m-deposit-from-exchange-view>`
129132
)
133+
ExchangeController.state.exchanges = [
134+
{ id: 'ex1', imageUrl: 'https://img1', name: 'Exchange One' },
135+
{ id: 'ex2', imageUrl: 'https://img2', name: 'Exchange Two' }
136+
] as any
137+
ExchangeController.state.amount = 0
138+
ExchangeController.state.paymentAsset = mockPaymentAsset
130139
await elementUpdated(element)
131140

132141
// Asset token button should reflect payment asset symbol
@@ -229,7 +238,7 @@ describe('W3mDepositFromExchangeView', () => {
229238

230239
element.disconnectedCallback()
231240

232-
expect(resetSpy).not.toHaveBeenCalled()
241+
expect(resetSpy).toHaveBeenCalledOnce()
233242
})
234243

235244
it('resets when transaction succeeds', async () => {

0 commit comments

Comments
 (0)