Skip to content

Commit

Permalink
Rename to rateOfPay
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Apr 15, 2024
1 parent e01c8c9 commit c4f6abd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,29 +224,29 @@ export class OpenPaymentsService {
const walletAddress = await getWalletInformation(walletAddressUrl)
const exchangeRates = await getExchangeRates()

let defaultRateOfPay = DEFAULT_RATE_OF_PAY
let rateOfPay = DEFAULT_RATE_OF_PAY
let minRateOfPay = MIN_RATE_OF_PAY
let maxRateOfPay = MAX_RATE_OF_PAY

if (!exchangeRates.rates[walletAddress.assetCode]) {
throw new Error(`Exchange rate for ${walletAddress.assetCode} not found.`)
}

const rate = exchangeRates.rates[walletAddress.assetCode]
if (rate < 0.8 || rate > 1.5) {
defaultRateOfPay = getRateOfPay({
defaultRate: DEFAULT_RATE_OF_PAY,
rate,
const exchangeRate = exchangeRates.rates[walletAddress.assetCode]
if (exchangeRate < 0.8 || exchangeRate > 1.5) {
rateOfPay = getRateOfPay({
rate: DEFAULT_RATE_OF_PAY,
exchangeRate,
assetScale: walletAddress.assetScale
})
minRateOfPay = getRateOfPay({
defaultRate: MIN_RATE_OF_PAY,
rate,
rate: MIN_RATE_OF_PAY,
exchangeRate,
assetScale: walletAddress.assetScale
})
maxRateOfPay = getRateOfPay({
defaultRate: MAX_RATE_OF_PAY,
rate,
rate: MAX_RATE_OF_PAY,
exchangeRate,
assetScale: walletAddress.assetScale
})
}
Expand Down Expand Up @@ -296,7 +296,7 @@ export class OpenPaymentsService {

this.storage.set({
walletAddress,
defaultRateOfPay,
rateOfPay,
minRateOfPay,
maxRateOfPay,
amount: transformedAmount,
Expand Down
2 changes: 1 addition & 1 deletion src/background/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const defaultStorage = {
amount: null,
token: null,
grant: null,
defaultRateOfPay: null,
rateOfPay: null,
minRateOfPay: null,
maxRateOfPay: null
} satisfies Omit<Storage, 'publicKey' | 'privateKey' | 'keyId'>
Expand Down
10 changes: 5 additions & 5 deletions src/background/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ export const OPEN_PAYMENTS_ERRORS: Record<string, string> = {
}

export interface GetRateOfPayParams {
defaultRate: string
rate: number
rate: string
exchangeRate: number
assetScale: number
}

export const getRateOfPay = ({
defaultRate,
rate,
exchangeRate,
assetScale
}: GetRateOfPayParams) => {
const scaleDiff = assetScale - DEFAULT_SCALE
const scaledExchangeRate = (1 / rate) * 10 ** scaleDiff
const scaledExchangeRate = (1 / exchangeRate) * 10 ** scaleDiff

return BigInt(Math.round(Number(defaultRate) * scaledExchangeRate)).toString()
return BigInt(Math.round(Number(rate) * scaledExchangeRate)).toString()
}
2 changes: 1 addition & 1 deletion src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Storage {
/** If a wallet is connected or not */
connected: boolean

defaultRateOfPay?: string | undefined | null
rateOfPay?: string | undefined | null
minRateOfPay?: string | undefined | null
maxRateOfPay?: string | undefined | null

Expand Down

0 comments on commit c4f6abd

Please sign in to comment.