Skip to content

Commit

Permalink
Create helpers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 24, 2024
1 parent fc55c78 commit 4112064
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { WALLET_TYPES } from './constants';

export function formatCurrency(amount, currency) {
const symbol = CURRENCY_SYMBOLS[currency];
return `${symbol}${amount.toFixed(2)}`;
}

export function formatDateTime(date, format) {
const moment = require('moment');
return moment(date).format(format);
}

export function getWalletTypeLabel(type) {
switch (type) {
case WALLET_TYPES.BTC:
return 'Bitcoin';
case WALLET_TYPES.ETH:
return 'Ethereum';
case WALLET_TYPES.LTC:
return 'Litecoin';
default:
return 'Unknown';
}
}

export function generateRandomId() {
return Math.random().toString(36).substr(2, 9);
}

export function debounce(func, wait) {
let timeout;
return function(...args) {
const context = this;
const later = function() {
timeout = null;
func.apply(context, args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}

export function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

0 comments on commit 4112064

Please sign in to comment.