diff --git a/package.json b/package.json index ae04c1b..bed484c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mysterium-vpn-js", - "version": "3.0.0", + "version": "3.0.1", "description": "Javascript SDK for Mysterium node", "keywords": [ "mysterium", diff --git a/src/payment/method.ts b/src/payment/method.ts index 74fcb76..b02a813 100644 --- a/src/payment/method.ts +++ b/src/payment/method.ts @@ -24,24 +24,26 @@ export interface PaymentMethod { } } -export const pricePerMinute = (pm: PaymentMethod): Money => { - if (!pm.rate.perSeconds) { - return { amount: 0, currency: pm.price.currency } +export const pricePerMinute = (pm?: PaymentMethod): Money => { + if (!pm || !pm.rate.perSeconds) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return { amount: 0, currency: pm!.price.currency } } return { - amount: (60 / pm.rate.perSeconds) * pm.price.amount, + amount: Math.round((60 / pm.rate.perSeconds) * pm.price.amount), currency: pm.price.currency, } } const bytesInGiB = 1024 * 1024 * 1024 -export const pricePerGiB = (pm: PaymentMethod): Money => { - if (!pm.rate.perBytes) { - return { amount: 0, currency: pm.price.currency } +export const pricePerGiB = (pm?: PaymentMethod): Money => { + if (!pm || !pm.rate.perBytes) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return { amount: 0, currency: pm!.price.currency } } return { - amount: (bytesInGiB / pm.rate.perBytes) * pm.price.amount, + amount: Math.round((bytesInGiB / pm.rate.perBytes) * pm.price.amount), currency: pm.price.currency, } }