-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41ff638
commit 2a67f14
Showing
8 changed files
with
958 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// unused atm | ||
export const divWorklet = (a, b) => { | ||
'worklet'; | ||
return a / b; | ||
}; | ||
|
||
export const floorWorklet = value => { | ||
'worklet'; | ||
return Math.floor(value); | ||
}; | ||
|
||
export const log10Worklet = value => { | ||
'worklet'; | ||
return Math.log10(value); | ||
}; | ||
|
||
export const powWorklet = (base, exponent) => { | ||
'worklet'; | ||
return Math.pow(base, exponent); | ||
}; | ||
|
||
export const mulWorklet = (a, b) => { | ||
'worklet'; | ||
return a * b; | ||
}; | ||
|
||
export const lessThanOrEqualToWorklet = (a, b) => { | ||
'worklet'; | ||
return a <= b; | ||
}; | ||
|
||
export const findNiceIncrement = availableBalance => { | ||
'worklet'; | ||
|
||
const niceFactors = [1, 2, 10]; | ||
const exactIncrement = divWorklet(availableBalance, 100); | ||
const orderOfMagnitude = floorWorklet(log10Worklet(exactIncrement)); | ||
const baseIncrement = powWorklet(10, orderOfMagnitude); | ||
|
||
let adjustedIncrement = baseIncrement; | ||
|
||
for (let i = niceFactors.length - 1; i >= 0; i--) { | ||
const potentialIncrement = mulWorklet(baseIncrement, niceFactors[i]); | ||
if (lessThanOrEqualToWorklet(potentialIncrement, exactIncrement)) { | ||
adjustedIncrement = potentialIncrement; | ||
break; | ||
} | ||
} | ||
|
||
return adjustedIncrement; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/__swaps__/screens/Swap/providers/__mocks__/swap-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const SwapProvider = jest.createMockFromModule('@/__swaps__/screens/Swap/providers/swap-provider'); | ||
|
||
SwapProvider.prototype.executeSwap = jest.fn(() => Promise.resolve()); | ||
|
||
module.exports = SwapProvider; |
Oops, something went wrong.