-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add check for sender account balance
- Loading branch information
1 parent
ec62c7b
commit 904096e
Showing
15 changed files
with
155 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const GAS_FEE_IN_ATOMIC_UNITS = '30000000000000'; | ||
export const STORAGE_FEE_IN_STANDARD_UNITS = '0.00125'; | ||
export const STORAGE_FEE_IN_ATOMIC_UNITS = '1250000000000000000000'; |
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
33 changes: 33 additions & 0 deletions
33
src/utils/convertNEARToYoctoNEAR/convertNEARToYoctoNEAR.test.ts
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,33 @@ | ||
// utils | ||
import convertNEARToYoctoNEAR from './convertNEARToYoctoNEAR'; | ||
|
||
interface ITestParams { | ||
expected: string; | ||
standardUnit: string; | ||
} | ||
|
||
describe('convertNEARToYoctoNEAR()', () => { | ||
it.each([ | ||
{ | ||
standardUnit: '0.00000000000001', | ||
expected: '10000000000', | ||
}, | ||
{ | ||
standardUnit: '1.000000000000001', | ||
expected: '1000000000000001000000000', | ||
}, | ||
{ | ||
standardUnit: '3.2', | ||
expected: '3200000000000000000000000', | ||
}, | ||
{ | ||
standardUnit: '3.200000000000000001', | ||
expected: '3200000000000000001000000', | ||
}, | ||
])( | ||
`should convert the near unit of "$standardUnit" to yoctonear unit of "$expected"`, | ||
({ expected, standardUnit }: ITestParams) => { | ||
expect(convertNEARToYoctoNEAR(standardUnit)).toBe(expected); | ||
} | ||
); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/utils/convertNEARToYoctoNEAR/convertNEARToYoctoNEAR.ts
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,17 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { utils } from 'near-api-js'; | ||
|
||
/** | ||
* Convenience function that converts a NEAR amount (standard unit) to the yoctoNEAR amount (atomic unit). | ||
* @param {string} standardAmount - the NEAR amount to convert. | ||
* @returns {string} the yoctoNEAR amount. | ||
*/ | ||
export default function convertNEARToYoctoNEAR(standardAmount: string): string { | ||
BigNumber.config({ | ||
ROUNDING_MODE: 0, | ||
}); | ||
|
||
return new BigNumber(standardAmount) | ||
.multipliedBy(new BigNumber('10').pow(utils.format.NEAR_NOMINATION_EXP)) | ||
.toFixed(); | ||
} |
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 @@ | ||
export { default } from './convertNEARToYoctoNEAR'; |
33 changes: 33 additions & 0 deletions
33
src/utils/convertYoctoNEARToNEAR/convertYoctoNEARToNEAR.test.ts
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,33 @@ | ||
// utils | ||
import convertYoctoNEARToNEAR from './convertYoctoNEARToNEAR'; | ||
|
||
interface ITestParams { | ||
atomicUnit: string; | ||
expected: string; | ||
} | ||
|
||
describe('convertYoctoNEARToNEARtest()', () => { | ||
it.each([ | ||
{ | ||
atomicUnit: '10000', | ||
expected: '0.00000000000000000001', | ||
}, | ||
{ | ||
atomicUnit: '1000000000000000000001000', | ||
expected: '1.00000000000000000001', | ||
}, | ||
{ | ||
atomicUnit: '3200000000000000000000000', | ||
expected: '3.2', | ||
}, | ||
{ | ||
atomicUnit: '3200000000000000000000001', | ||
expected: '3.20000000000000000001', | ||
}, | ||
])( | ||
`should convert the yoctonear unit of "$atomicUnit" to near unit of "$expected"`, | ||
({ atomicUnit, expected }: ITestParams) => { | ||
expect(convertYoctoNEARToNEAR(atomicUnit)).toBe(expected); | ||
} | ||
); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/utils/convertYoctoNEARToNEAR/convertYoctoNEARToNEAR.ts
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,17 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { utils } from 'near-api-js'; | ||
|
||
/** | ||
* Convenience function that converts a yoctoNEAR amount (atomic unit) to the NEAR amount (standard unit). | ||
* @param {BigNumber} atomicAmount - the yoctoNEAR amount to convert. | ||
* @returns {BigNumber} the NEAR amount. | ||
*/ | ||
export default function convertYoctoNEARToNEAR(atomicAmount: string): string { | ||
BigNumber.config({ | ||
ROUNDING_MODE: 0, | ||
}); | ||
|
||
return new BigNumber(atomicAmount) | ||
.dividedBy(new BigNumber(10).pow(utils.format.NEAR_NOMINATION_EXP)) | ||
.toFixed(); | ||
} |
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 @@ | ||
export { default } from './convertYoctoNEARToNEAR'; |
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
13 changes: 0 additions & 13 deletions
13
test/helpers/convertNearToYoctoNear/convertNearToYoctoNear.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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