2021-08-12 09:58:13 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
2021-08-19 07:57:32 +00:00
|
|
|
import Decimal from 'decimal.js';
|
|
|
|
import { ValueTransformer } from 'typeorm';
|
|
|
|
|
2021-08-04 13:12:59 +00:00
|
|
|
/**
|
|
|
|
* Method to wait for specified time.
|
|
|
|
* @param time Time to wait in milliseconds
|
|
|
|
*/
|
|
|
|
export const wait = async (time: number): Promise<void> => new Promise(resolve => setTimeout(resolve, time));
|
2021-08-19 07:57:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transformer used by typeorm entity for Decimal type fields
|
|
|
|
*/
|
|
|
|
export const decimalTransformer: ValueTransformer = {
|
|
|
|
to: (value?: Decimal) => {
|
|
|
|
if (value) {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
from: (value?: string) => {
|
|
|
|
if (value) {
|
|
|
|
return new Decimal(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|