-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathindex.ts
109 lines (92 loc) · 3.33 KB
/
index.ts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
import { LitElement, html } from 'lit'
import { state } from 'lit/decorators.js'
import { ifDefined } from 'lit/directives/if-defined.js'
import {
AssetController,
ModalController,
OnRampController,
OptionsController
} from '@reown/appkit-controllers'
import type { PurchaseCurrency } from '@reown/appkit-controllers'
import { customElement } from '@reown/appkit-ui'
import styles from './styles.js'
@customElement('w3m-onramp-token-select-view')
export class W3mOnrampTokensView extends LitElement {
public static override styles = styles
// -- Members ------------------------------------------- //
private unsubscribe: (() => void)[] = []
// -- State & Properties -------------------------------- //
@state() public selectedCurrency = OnRampController.state.purchaseCurrencies
@state() public tokens = OnRampController.state.purchaseCurrencies
@state() private tokenImages = AssetController.state.tokenImages
@state() private checked = false
public constructor() {
super()
this.unsubscribe.push(
...[
OnRampController.subscribe(val => {
this.selectedCurrency = val.purchaseCurrencies
this.tokens = val.purchaseCurrencies
}),
AssetController.subscribeKey('tokenImages', val => (this.tokenImages = val))
]
)
}
public override disconnectedCallback() {
this.unsubscribe.forEach(unsubscribe => unsubscribe())
}
// -- Render -------------------------------------------- //
public override render() {
const { termsConditionsUrl, privacyPolicyUrl } = OptionsController.state
const legalCheckbox = OptionsController.state.features?.legalCheckbox
const legalUrl = termsConditionsUrl || privacyPolicyUrl
const showLegalCheckbox = Boolean(legalUrl) && Boolean(legalCheckbox)
const disabled = showLegalCheckbox && !this.checked
return html`
<w3m-legal-checkbox @checkboxChange=${this.onCheckboxChange.bind(this)}></w3m-legal-checkbox>
<wui-flex
flexDirection="column"
.padding=${['0', 's', 's', 's']}
gap="xs"
class=${ifDefined(disabled ? 'disabled' : undefined)}
>
${this.currenciesTemplate(disabled)}
</wui-flex>
<w3m-legal-footer></w3m-legal-footer>
`
}
// -- Private ------------------------------------------- //
private currenciesTemplate(disabled = false) {
return this.tokens.map(
token => html`
<wui-list-item
imageSrc=${ifDefined(this.tokenImages?.[token.symbol])}
@click=${() => this.selectToken(token)}
variant="image"
tabIdx=${ifDefined(disabled ? -1 : undefined)}
>
<wui-flex gap="3xs" alignItems="center">
<wui-text variant="paragraph-500" color="fg-100">${token.name}</wui-text>
<wui-text variant="small-400" color="fg-200">${token.symbol}</wui-text>
</wui-flex>
</wui-list-item>
`
)
}
private selectToken(currency: PurchaseCurrency) {
if (!currency) {
return
}
OnRampController.setPurchaseCurrency(currency)
ModalController.close()
}
// -- Private Methods ----------------------------------- //
private onCheckboxChange(event: CustomEvent<string>) {
this.checked = Boolean(event.detail)
}
}
declare global {
interface HTMLElementTagNameMap {
'w3m-onramp-token-select-view': W3mOnrampTokensView
}
}