@jetthai/cuora 1.1.281-dev3 → 1.1.281-dev4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.1.281-dev4](https://github.com/jetthai/cuora-module/compare/v1.1.281-dev3...v1.1.281-dev4) (2024-06-20)
6
+
5
7
  ### [1.1.281-dev3](https://github.com/jetthai/cuora-module/compare/v1.1.128-dev-2...v1.1.281-dev3) (2024-06-20)
6
8
 
7
9
  ### [1.1.128-dev-2](https://github.com/jetthai/cuora-module/compare/v1.1.281-dev-1...v1.1.128-dev-2) (2024-06-20)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.281-dev3",
3
+ "version": "1.1.281-dev4",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -110,6 +110,10 @@ export default function (request) {
110
110
  target: '.loaded',
111
111
  actions: ['setAmount', 'clearCalculation'],
112
112
  },
113
+ INPUT_AMOUNT: {
114
+ target: '.loaded',
115
+ actions: ['inputAmount', 'clearCalculation'],
116
+ },
113
117
  CALCULATE: {
114
118
  target: '.debouncing',
115
119
  actions: 'clearCalculation',
@@ -151,6 +155,9 @@ export default function (request) {
151
155
  amount: event.data,
152
156
  }
153
157
  }),
158
+ inputAmount: assign((context, event) => {
159
+ return { amount: preciseAdd(`${parseFloat(context.amount || 0)}`, `${parseFloat(event.data)}`) }
160
+ }),
154
161
  setAddress: assign((context, event) => {
155
162
  return {
156
163
  sourceAddress: event.data,
@@ -218,3 +225,15 @@ export default function (request) {
218
225
  }
219
226
  )
220
227
  }
228
+
229
+ function preciseAdd(a, b) {
230
+ let aStr = a.toString()
231
+ let bStr = b.toString()
232
+
233
+ let aDecimalPlaces = aStr.split('.')[1] ? aStr.split('.')[1].length : 0
234
+ let bDecimalPlaces = bStr.split('.')[1] ? bStr.split('.')[1].length : 0
235
+
236
+ let factor = Math.pow(10, Math.max(aDecimalPlaces, bDecimalPlaces))
237
+
238
+ return (Math.round(a * factor) + Math.round(b * factor)) / factor
239
+ }