-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpending-transactions-panel.tsx
More file actions
96 lines (84 loc) · 3.12 KB
/
pending-transactions-panel.tsx
File metadata and controls
96 lines (84 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Component, h, Method, State } from '@stencil/core';
import { ProviderIdleScreen } from 'common/ProviderIdleScreen/ProviderIdleScreen';
import { ANIMATION_DELAY_PROMISE } from 'components/visual/SidePanel/sidePanel.constants';
import { SidePanel } from 'components/visual/SidePanel/SidePanel';
import type { IProviderBase } from 'types/provider.types';
import { ProviderTypeEnum } from 'types/provider.types';
import { ConnectionMonitor } from 'utils/ConnectionMonitor';
import type { IEventBus } from 'utils/EventBus';
import { EventBus } from 'utils/EventBus';
import { PendingTransactionsEventsEnum } from './pending-transactions-panel.types';
const getProviderIntroText = (providerType?: IProviderBase['type']) => {
switch (providerType) {
case ProviderTypeEnum.extension:
return 'Check the MultiversX Browser Extension to connect to your wallet.';
case ProviderTypeEnum.metamask:
return 'Open the MetaMask Browser Extension to connect to your wallet.';
case ProviderTypeEnum.passkey:
return 'Use your predefined passkey to connect to your wallet.';
case ProviderTypeEnum.crossWindow:
return 'Follow the steps on MultiversX Web Wallet to connect to your wallet.';
default:
return 'Follow the steps on your selected provider to connect to your wallet.';
}
};
@Component({
tag: 'mvx-pending-transactions-panel',
styleUrl: 'pending-transactions-panel.scss',
shadow: true,
})
export class PendingTransactionsPanel {
private readonly eventBus: IEventBus = new EventBus();
private unsubscribeFunctions: (() => void)[] = [];
private readonly connectionMonitor = new ConnectionMonitor();
@State() provider: IProviderBase = null;
@State() isOpen: boolean = false;
@Method() async getEventBus() {
await this.connectionMonitor.waitForConnection();
return this.eventBus;
}
@Method() async closeWithAnimation() {
this.isOpen = false;
const animationDelay = await ANIMATION_DELAY_PROMISE;
return animationDelay;
}
componentDidLoad() {
const unsubDataUpdate = this.eventBus.subscribe(PendingTransactionsEventsEnum.DATA_UPDATE, this.dataUpdate);
this.unsubscribeFunctions.push(unsubDataUpdate);
this.connectionMonitor.connect();
}
disconnectedCallback() {
this.resetState();
this.unsubscribeFunctions.forEach(unsub => unsub());
this.unsubscribeFunctions = [];
}
private resetState() {
this.provider = null;
this.isOpen = false;
}
private readonly handleClose = () => {
this.eventBus.publish(PendingTransactionsEventsEnum.CLOSE);
};
private readonly dataUpdate = (newData: IProviderBase) => {
this.provider = newData;
this.isOpen = true;
};
render() {
return (
<SidePanel
isOpen={this.isOpen}
panelTitle={this?.provider?.name}
showHeader={false}
>
<ProviderIdleScreen
provider={this.provider}
onClose={this.handleClose}
introTitle="Signing Transaction"
introText={getProviderIntroText(this.provider?.type)}
>
<button onClick={this.handleClose}>Close</button>
</ProviderIdleScreen>
</SidePanel>
);
}
}