@monygroupcorp/micro-web3 1.2.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/micro-web3.cjs +2 -2
- package/dist/micro-web3.cjs.map +1 -1
- package/dist/micro-web3.esm.js +2 -2
- package/dist/micro-web3.esm.js.map +1 -1
- package/dist/micro-web3.umd.js +2 -2
- package/dist/micro-web3.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/components/BondingCurve/BondingCurve.js +80 -116
- package/src/components/Display/BalanceDisplay.js +37 -61
- package/src/components/Display/PriceDisplay.js +43 -71
- package/src/components/FloatingWalletButton/FloatingWalletButton.js +106 -151
- package/src/components/Ipfs/IpfsImage.js +83 -107
- package/src/components/Modal/ApprovalModal.js +92 -149
- package/src/components/SettingsModal/SettingsModal.js +364 -341
- package/src/components/Swap/SwapButton.js +9 -45
- package/src/components/Swap/SwapInputs.js +46 -108
- package/src/components/Swap/SwapInterface.js +216 -597
- package/src/components/Swap/TransactionOptions.js +70 -179
- package/src/components/SyncProgressBar/SyncProgressBar.js +183 -215
- package/src/components/Util/MessagePopup.js +26 -24
- package/src/components/Wallet/WalletModal.js +45 -44
- package/src/components/WalletButton/WalletButton.js +193 -185
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Component } from '@monygroupcorp/microact';
|
|
1
|
+
import { Component, h } from '@monygroupcorp/microact';
|
|
2
2
|
|
|
3
3
|
export class TransactionOptions extends Component {
|
|
4
4
|
constructor(props) {
|
|
5
5
|
super(props);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
this.state = {
|
|
9
8
|
nftMintingEnabled: props.nftMintingEnabled || false,
|
|
10
9
|
message: props.message || '',
|
|
@@ -15,79 +14,30 @@ export class TransactionOptions extends Component {
|
|
|
15
14
|
isPhase2: props.isPhase2 === null ? null : props.isPhase2
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
this.handleMessageInput = this.handleMessageInput.bind(this);
|
|
19
|
-
this.handleNFTToggle = this.handleNFTToggle.bind(this);
|
|
20
|
-
this.handleStoreUpdate = this.handleStoreUpdate.bind(this);
|
|
21
|
-
|
|
22
17
|
this.updateTimer = null;
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
20
|
+
didMount() {
|
|
21
|
+
this.subscribe('contractData:updated', (data) => {
|
|
22
|
+
const isPhase2 = data.liquidityPool && data.liquidityPool !== '0x0000000000000000000000000000000000000000';
|
|
23
|
+
if (this.state.isPhase2 !== isPhase2) {
|
|
24
|
+
this.setState({ isPhase2 });
|
|
25
|
+
}
|
|
28
26
|
});
|
|
29
|
-
|
|
30
|
-
this.addEventListeners();
|
|
31
|
-
this.updateElements();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
onUnmount() {
|
|
35
|
-
if (this.contractDataUnsubscribe) this.contractDataUnsubscribe();
|
|
36
|
-
this.removeEventListeners();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
updateProps(newProps) {
|
|
40
|
-
const newState = { ...this.state, ...newProps };
|
|
41
|
-
const shouldUpdate = this.state.isPhase2 !== newState.isPhase2 ||
|
|
42
|
-
this.state.swapDirection !== newState.swapDirection ||
|
|
43
|
-
this.state.nftBalance !== newState.nftBalance;
|
|
44
|
-
|
|
45
|
-
this.setState(newState);
|
|
46
|
-
|
|
47
|
-
if (shouldUpdate) {
|
|
48
|
-
this.validateTransaction();
|
|
49
|
-
this.update(); // Re-render if phase or other critical props change
|
|
50
|
-
} else {
|
|
51
|
-
this.updateElements(); // Just update dynamic parts
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
addEventListeners() {
|
|
56
|
-
const messageInput = this.element.querySelector('#messageInput');
|
|
57
|
-
const nftToggle = this.element.querySelector('#nftToggle');
|
|
58
|
-
|
|
59
|
-
if (messageInput) {
|
|
60
|
-
this._messageInput = messageInput;
|
|
61
|
-
messageInput.addEventListener('input', this.handleMessageInput);
|
|
62
|
-
}
|
|
63
|
-
if (nftToggle) {
|
|
64
|
-
this._nftToggle = nftToggle;
|
|
65
|
-
nftToggle.addEventListener('change', this.handleNFTToggle);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
removeEventListeners() {
|
|
70
|
-
|
|
71
|
-
if (this._messageInput) {
|
|
72
|
-
this._messageInput.removeEventListener('input', this.handleMessageInput);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (this._nftToggle) {
|
|
76
|
-
this._nftToggle.removeEventListener('change', this.handleNFTToggle);
|
|
77
|
-
}
|
|
78
27
|
}
|
|
79
28
|
|
|
80
29
|
validateTransaction() {
|
|
81
30
|
const isMessageValid = this.state.message.length <= 140;
|
|
82
31
|
const isNFTValid = !this.state.nftMintingEnabled || this.state.nftBalance < 10;
|
|
83
32
|
const newIsValid = isMessageValid && isNFTValid;
|
|
84
|
-
|
|
85
|
-
// Only emit if validation state has changed
|
|
33
|
+
|
|
86
34
|
if (this.state.lastValidationState !== newIsValid) {
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
35
|
+
this.setState({
|
|
36
|
+
lastValidationState: newIsValid,
|
|
37
|
+
isValid: newIsValid
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.props.eventBus?.emit('transactionValidation', {
|
|
91
41
|
isValid: newIsValid,
|
|
92
42
|
errors: this.getValidationErrors()
|
|
93
43
|
});
|
|
@@ -96,11 +46,11 @@ export class TransactionOptions extends Component {
|
|
|
96
46
|
|
|
97
47
|
getValidationErrors() {
|
|
98
48
|
const errors = [];
|
|
99
|
-
|
|
49
|
+
|
|
100
50
|
if (this.state.message.length > 140) {
|
|
101
51
|
errors.push('Message must be 140 characters or less');
|
|
102
52
|
}
|
|
103
|
-
|
|
53
|
+
|
|
104
54
|
if (this.state.nftMintingEnabled && this.state.nftBalance >= 10) {
|
|
105
55
|
errors.push('Cannot mint more than 10 NFTs');
|
|
106
56
|
}
|
|
@@ -108,131 +58,72 @@ export class TransactionOptions extends Component {
|
|
|
108
58
|
return errors;
|
|
109
59
|
}
|
|
110
60
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const nftToggle = this.element.querySelector('#nftToggle');
|
|
116
|
-
|
|
117
|
-
if (messageInput && !messageInput.matches(':focus')) {
|
|
118
|
-
messageInput.value = this.state.message;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (nftToggle) {
|
|
122
|
-
nftToggle.checked = this.state.nftMintingEnabled;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Re-attach event listeners after updating elements
|
|
126
|
-
this.removeEventListeners();
|
|
127
|
-
this.addEventListeners();
|
|
128
|
-
|
|
129
|
-
// Update character count
|
|
130
|
-
const characterCount = this.element.querySelector('.character-count');
|
|
131
|
-
if (characterCount) {
|
|
132
|
-
characterCount.textContent = `${this.state.message.length}/140`;
|
|
133
|
-
characterCount.className = `character-count ${this.state.message.length > 140 ? 'error' : ''}`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Update validation status
|
|
137
|
-
const validationStatus = this.element.querySelector('.validation-status');
|
|
138
|
-
if (validationStatus) {
|
|
139
|
-
validationStatus.className = `validation-status ${this.state.isValid ? 'valid' : 'invalid'}`;
|
|
140
|
-
validationStatus.innerHTML = this.getValidationErrors()
|
|
141
|
-
.map(error => `<p class="error">${error}</p>`)
|
|
142
|
-
.join('');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
handleMessageInput(event) {
|
|
147
|
-
const newMessage = event.target.value || '';
|
|
148
|
-
|
|
149
|
-
// Update state without triggering a re-render
|
|
150
|
-
this.state = {
|
|
151
|
-
...this.state,
|
|
152
|
-
message: newMessage
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Update elements and ensure listeners
|
|
156
|
-
this.updateElements();
|
|
157
|
-
|
|
61
|
+
handleMessageInput(e) {
|
|
62
|
+
const newMessage = e.target.value || '';
|
|
63
|
+
this.setState({ message: newMessage });
|
|
64
|
+
this.validateTransaction();
|
|
158
65
|
this.emitStateUpdate();
|
|
159
66
|
}
|
|
160
67
|
|
|
161
|
-
handleNFTToggle(
|
|
162
|
-
const isEnabled =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.state = {
|
|
166
|
-
...this.state,
|
|
167
|
-
nftMintingEnabled: isEnabled
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// Update elements and ensure listeners
|
|
171
|
-
this.updateElements();
|
|
172
|
-
|
|
68
|
+
handleNFTToggle(e) {
|
|
69
|
+
const isEnabled = e.target.checked;
|
|
70
|
+
this.setState({ nftMintingEnabled: isEnabled });
|
|
71
|
+
this.validateTransaction();
|
|
173
72
|
this.emitStateUpdate();
|
|
174
73
|
}
|
|
175
74
|
|
|
176
|
-
// New method to emit state updates
|
|
177
75
|
emitStateUpdate() {
|
|
178
76
|
const updatePayload = {
|
|
179
77
|
message: this.state.message,
|
|
180
78
|
nftMintingEnabled: this.state.nftMintingEnabled
|
|
181
79
|
};
|
|
182
|
-
this.eventBus
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
checkPhase2Status() {
|
|
186
|
-
const { isPhase2 } = this.state;
|
|
187
|
-
if (isPhase2 === null) {
|
|
188
|
-
// Phase not yet determined
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if (this.state.isPhase2 !== isPhase2) {
|
|
192
|
-
this.setState({ isPhase2 });
|
|
193
|
-
}
|
|
80
|
+
this.props.eventBus?.emit('transactionOptions:update', updatePayload);
|
|
194
81
|
}
|
|
195
82
|
|
|
196
|
-
|
|
83
|
+
render() {
|
|
197
84
|
const { nftMintingEnabled, message, isValid, isPhase2, swapDirection } = this.state;
|
|
198
85
|
|
|
199
|
-
if (isPhase2 === null) {
|
|
200
|
-
return '';
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
${
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
86
|
+
if (isPhase2 === null || isPhase2) {
|
|
87
|
+
return h('div', { className: 'transaction-options empty' });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const errors = this.getValidationErrors();
|
|
91
|
+
|
|
92
|
+
return h('div', { className: 'transaction-options' },
|
|
93
|
+
h('div', {
|
|
94
|
+
className: `option-group ${swapDirection === 'sell' ? 'hidden' : ''}`
|
|
95
|
+
},
|
|
96
|
+
h('label', { className: 'nft-toggle' },
|
|
97
|
+
h('input', {
|
|
98
|
+
type: 'checkbox',
|
|
99
|
+
checked: nftMintingEnabled,
|
|
100
|
+
onChange: this.bind(this.handleNFTToggle)
|
|
101
|
+
}),
|
|
102
|
+
'Mint NFT with transaction'
|
|
103
|
+
)
|
|
104
|
+
),
|
|
105
|
+
|
|
106
|
+
h('div', { className: 'option-group' },
|
|
107
|
+
h('label', { htmlFor: 'messageInput' }, 'Transaction Message'),
|
|
108
|
+
h('textarea', {
|
|
109
|
+
id: 'messageInput',
|
|
110
|
+
maxLength: 140,
|
|
111
|
+
placeholder: 'Enter optional message...',
|
|
112
|
+
value: message,
|
|
113
|
+
onInput: this.bind(this.handleMessageInput)
|
|
114
|
+
}),
|
|
115
|
+
h('span', {
|
|
116
|
+
className: `character-count ${message.length > 140 ? 'error' : ''}`
|
|
117
|
+
}, `${message.length}/140`)
|
|
118
|
+
),
|
|
119
|
+
|
|
120
|
+
h('div', {
|
|
121
|
+
className: `validation-status ${isValid ? 'valid' : 'invalid'}`
|
|
122
|
+
},
|
|
123
|
+
errors.map((error, index) =>
|
|
124
|
+
h('p', { key: index, className: 'error' }, error)
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
);
|
|
237
128
|
}
|
|
238
|
-
}
|
|
129
|
+
}
|