@monygroupcorp/micro-web3 1.2.3 → 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.
@@ -1,10 +1,10 @@
1
- import { Component } from '@monygroupcorp/microact';
1
+ import { Component, h } from '@monygroupcorp/microact';
2
2
 
3
3
  /**
4
4
  * SwapButton Component
5
- *
5
+ *
6
6
  * Main swap action button with state management.
7
- *
7
+ *
8
8
  * @class SwapButton
9
9
  * @extends Component
10
10
  */
@@ -16,36 +16,7 @@ export class SwapButton extends Component {
16
16
  * @param {Function} props.onClick - Callback when button is clicked
17
17
  */
18
18
  constructor(props = {}) {
19
- super();
20
- this.props = props;
21
- }
22
-
23
- /**
24
- * Update component props
25
- * @param {Object} newProps - New props to merge
26
- */
27
- updateProps(newProps) {
28
- const oldProps = { ...this.props };
29
- this.props = { ...this.props, ...newProps };
30
-
31
- // Only update if the button text would actually change
32
- const oldText = oldProps.direction === 'buy' ? 'Buy $EXEC' : 'Sell $EXEC';
33
- const newText = this.props.direction === 'buy' ? 'Buy $EXEC' : 'Sell $EXEC';
34
-
35
- if (oldText !== newText || oldProps.disabled !== this.props.disabled) {
36
- // Only update if something actually changed
37
- if (this.element) {
38
- const button = this.element.querySelector('.swap-button');
39
- if (button) {
40
- button.textContent = newText;
41
- if (this.props.disabled) {
42
- button.disabled = true;
43
- } else {
44
- button.disabled = false;
45
- }
46
- }
47
- }
48
- }
19
+ super(props);
49
20
  }
50
21
 
51
22
  /**
@@ -59,23 +30,16 @@ export class SwapButton extends Component {
59
30
  }
60
31
  }
61
32
 
62
- events() {
63
- return {
64
- 'click .swap-button': (e) => this.handleClick(e)
65
- };
66
- }
67
-
68
33
  render() {
69
34
  const { direction, disabled } = this.props;
70
35
  const buttonText = direction === 'buy' ? 'Buy $EXEC' : 'Sell $EXEC';
71
36
 
72
- return `
73
- <button class="swap-button" ${disabled ? 'disabled' : ''}>
74
- ${buttonText}
75
- </button>
76
- `;
37
+ return h('button', {
38
+ className: 'swap-button',
39
+ disabled: disabled,
40
+ onClick: this.bind(this.handleClick)
41
+ }, buttonText);
77
42
  }
78
43
  }
79
44
 
80
45
  export default SwapButton;
81
-
@@ -1,77 +1,8 @@
1
- import { Component } from '@monygroupcorp/microact';
1
+ import { Component, h } from '@monygroupcorp/microact';
2
2
 
3
3
  export class SwapInputs extends Component {
4
4
  constructor(props = {}) {
5
5
  super(props);
6
- this.props = {
7
- balances: { eth: '0', exec: '0' },
8
- ...props
9
- };
10
- }
11
-
12
- /**
13
- * Update component props
14
- * @param {Object} newProps - New props to merge
15
- */
16
- updateProps(newProps) {
17
- this.props = { ...this.props, ...newProps };
18
- // Don't call update() directly as it will destroy input elements and lose focus
19
- // Instead, update only the parts that changed
20
- this.updateSelectively(newProps);
21
- }
22
-
23
- /**
24
- * Update only specific parts of the UI without destroying inputs
25
- * @param {Object} changedProps - Props that changed
26
- */
27
- updateSelectively(changedProps) {
28
- if (!this.element) return;
29
-
30
- if (changedProps.direction !== undefined || changedProps.freeMint !== undefined || changedProps.balances !== undefined) {
31
- const { balances, direction, freeMint } = this.props;
32
- const formattedEthBalance = parseFloat(balances.eth || 0).toFixed(6);
33
- const formattedExecBalance = parseInt(balances.exec || 0).toLocaleString();
34
- const availableExecBalance = direction === 'sell' && freeMint
35
- ? `Available: ${(parseInt(balances.exec || 0) - 1000000).toLocaleString()}`
36
- : `Balance: ${formattedExecBalance}`;
37
-
38
- const balanceDisplays = this.element.querySelectorAll('.token-balance');
39
- balanceDisplays.forEach((display, index) => {
40
- const isTopInput = index === 0;
41
- if (direction === 'buy') {
42
- display.textContent = isTopInput ? `Balance: ${formattedEthBalance}` : `Balance: ${formattedExecBalance}`;
43
- } else {
44
- display.textContent = isTopInput ? availableExecBalance : `Balance: ${formattedEthBalance}`;
45
- }
46
- });
47
-
48
- const tokenSymbols = this.element.querySelectorAll('.token-symbol');
49
- tokenSymbols.forEach((symbol, index) => {
50
- const isTopInput = index === 0;
51
- if (direction === 'buy') {
52
- symbol.textContent = isTopInput ? 'ETH' : '$EXEC';
53
- } else {
54
- symbol.textContent = isTopInput ? '$EXEC' : 'ETH';
55
- }
56
- });
57
- }
58
-
59
- const topInput = this.element.querySelector('.top-input');
60
- const bottomInput = this.element.querySelector('.bottom-input');
61
-
62
- if (changedProps.calculatingAmount !== undefined || changedProps.execAmount !== undefined || changedProps.ethAmount !== undefined) {
63
- const { direction, ethAmount, execAmount, calculatingAmount } = this.props;
64
-
65
- if (topInput && !topInput.matches(':focus')) {
66
- topInput.value = direction === 'buy' ? ethAmount : execAmount;
67
- }
68
-
69
- if (bottomInput && !bottomInput.matches(':focus')) {
70
- bottomInput.value = direction === 'buy'
71
- ? (calculatingAmount ? 'Loading...' : execAmount)
72
- : (calculatingAmount ? 'Loading...' : ethAmount);
73
- }
74
- }
75
6
  }
76
7
 
77
8
  /**
@@ -86,52 +17,59 @@ export class SwapInputs extends Component {
86
17
  }
87
18
  }
88
19
 
89
- events() {
90
- return {
91
- 'input .top-input': (e) => this.handleInput(e, 'top'),
92
- 'input .bottom-input': (e) => this.handleInput(e, 'bottom')
93
- };
94
- }
95
-
96
20
  render() {
97
- const { direction, ethAmount, execAmount, calculatingAmount, freeMint, balances } = this.props;
98
-
21
+ const { direction, ethAmount, execAmount, calculatingAmount, freeMint, balances = { eth: '0', exec: '0' } } = this.props;
22
+
99
23
  const formattedEthBalance = parseFloat(balances.eth || 0).toFixed(6);
100
24
  const formattedExecBalance = parseInt(balances.exec || 0).toLocaleString();
101
-
25
+
102
26
  const availableExecBalance = direction === 'sell' && freeMint
103
27
  ? `Available: ${(parseInt(balances.exec || 0) - 1000000).toLocaleString()}`
104
28
  : `Balance: ${formattedExecBalance}`;
105
29
 
106
- return `
107
- <div class="swap-inputs">
108
- <div class="input-container">
109
- <input type="text"
110
- class="top-input"
111
- value="${direction === 'buy' ? ethAmount : execAmount}"
112
- placeholder="0.0"
113
- pattern="^[0-9]*[.]?[0-9]*$">
114
- <div class="token-info">
115
- <span class="token-symbol">${direction === 'buy' ? 'ETH' : '$EXEC'}</span>
116
- <span class="token-balance">Balance: ${direction === 'buy' ? formattedEthBalance : availableExecBalance}</span>
117
- </div>
118
- </div>
119
- <div class="direction-switch-slot"></div>
120
- <div class="input-container">
121
- <input type="text"
122
- class="bottom-input"
123
- value="${direction === 'buy' ? (calculatingAmount ? 'Loading...' : execAmount) : (calculatingAmount ? 'Loading...' : ethAmount)}"
124
- placeholder="0.0"
125
- pattern="^[0-9]*[.]?[0-9]*$">
126
- <div class="token-info">
127
- <span class="token-symbol">${direction === 'buy' ? '$EXEC' : 'ETH'}</span>
128
- <span class="token-balance">Balance: ${direction === 'buy' ? formattedExecBalance : formattedEthBalance}</span>
129
- </div>
130
- </div>
131
- </div>
132
- `;
30
+ const topValue = direction === 'buy' ? ethAmount : execAmount;
31
+ const bottomValue = direction === 'buy'
32
+ ? (calculatingAmount ? 'Loading...' : execAmount)
33
+ : (calculatingAmount ? 'Loading...' : ethAmount);
34
+
35
+ const topSymbol = direction === 'buy' ? 'ETH' : '$EXEC';
36
+ const bottomSymbol = direction === 'buy' ? '$EXEC' : 'ETH';
37
+
38
+ const topBalance = direction === 'buy' ? `Balance: ${formattedEthBalance}` : availableExecBalance;
39
+ const bottomBalance = direction === 'buy' ? `Balance: ${formattedExecBalance}` : `Balance: ${formattedEthBalance}`;
40
+
41
+ return h('div', { className: 'swap-inputs' },
42
+ h('div', { className: 'input-container' },
43
+ h('input', {
44
+ type: 'text',
45
+ className: 'top-input',
46
+ value: topValue,
47
+ placeholder: '0.0',
48
+ pattern: '^[0-9]*[.]?[0-9]*$',
49
+ onInput: (e) => this.handleInput(e, 'top')
50
+ }),
51
+ h('div', { className: 'token-info' },
52
+ h('span', { className: 'token-symbol' }, topSymbol),
53
+ h('span', { className: 'token-balance' }, topBalance)
54
+ )
55
+ ),
56
+ h('div', { className: 'direction-switch-slot' }),
57
+ h('div', { className: 'input-container' },
58
+ h('input', {
59
+ type: 'text',
60
+ className: 'bottom-input',
61
+ value: bottomValue,
62
+ placeholder: '0.0',
63
+ pattern: '^[0-9]*[.]?[0-9]*$',
64
+ onInput: (e) => this.handleInput(e, 'bottom')
65
+ }),
66
+ h('div', { className: 'token-info' },
67
+ h('span', { className: 'token-symbol' }, bottomSymbol),
68
+ h('span', { className: 'token-balance' }, bottomBalance)
69
+ )
70
+ )
71
+ );
133
72
  }
134
73
  }
135
74
 
136
75
  export default SwapInputs;
137
-