Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Nov 11, 2024
2 parents bef9e0c + b2daa7c commit b175304
Show file tree
Hide file tree
Showing 121 changed files with 3,185 additions and 1,526 deletions.
34 changes: 19 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ GEM
base64
nkf
rexml
activesupport (7.2.1.2)
activesupport (7.2.2)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
Expand All @@ -24,29 +25,30 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.996.0)
aws-sdk-core (3.211.0)
aws-partitions (1.1002.0)
aws-sdk-core (3.212.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.95.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.169.0)
aws-sdk-s3 (1.170.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.10.1)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.8)
claide (1.1.0)
cocoapods (1.15.2)
cocoapods (1.16.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.15.2)
cocoapods-core (= 1.16.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -60,8 +62,8 @@ GEM
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.15.2)
xcodeproj (>= 1.27.0, < 2.0)
cocoapods-core (1.16.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand Down Expand Up @@ -170,6 +172,7 @@ GEM
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-plugin-browserstack (0.3.3)
rest-client (~> 2.0, >= 2.0.2)
fastlane-plugin-bugsnag_sourcemaps_upload (0.2.0)
fastlane-sirp (1.0.0)
sysrandom (~> 1.0)
ffi (1.17.0)
Expand Down Expand Up @@ -220,21 +223,21 @@ GEM
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.7.4)
json (2.8.1)
jwt (2.9.3)
base64
logger (1.6.1)
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2024.1001)
mime-types-data (3.2024.1105)
mini_magick (4.13.2)
mini_mime (1.1.5)
minitest (5.25.1)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.4.1)
nanaimo (0.3.0)
nanaimo (0.4.0)
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
Expand Down Expand Up @@ -285,12 +288,12 @@ GEM
uber (0.1.0)
unicode-display_width (2.6.0)
word_wrap (1.0.0)
xcodeproj (1.25.1)
xcodeproj (1.27.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
Expand All @@ -305,10 +308,11 @@ DEPENDENCIES
cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
fastlane (>= 2.225.0)
fastlane-plugin-browserstack
fastlane-plugin-bugsnag_sourcemaps_upload
rubyzip (= 2.3.2)

RUBY VERSION
ruby 3.1.6p260
ruby 3.3.5p100

BUNDLED WITH
2.5.13
2.5.18
63 changes: 30 additions & 33 deletions blue_modules/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Clipboard from '@react-native-clipboard/clipboard';

const BlueClipboard = () => {
const STORAGE_KEY = 'ClipboardReadAllowed';
const { getItem, setItem } = useAsyncStorage(STORAGE_KEY);
const STORAGE_KEY: string = 'ClipboardReadAllowed';

const isReadClipboardAllowed = async () => {
try {
const clipboardAccessAllowed = await getItem();
if (clipboardAccessAllowed === null) {
await setItem(JSON.stringify(true));
return true;
}
return !!JSON.parse(clipboardAccessAllowed);
} catch {
await setItem(JSON.stringify(true));
export const isReadClipboardAllowed = async (): Promise<boolean> => {
try {
const clipboardAccessAllowed = await AsyncStorage.getItem(STORAGE_KEY);
if (clipboardAccessAllowed === null) {
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(true));
return true;
}
};
return !!JSON.parse(clipboardAccessAllowed);
} catch {
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(true));
return true;
}
};

const setReadClipboardAllowed = (value: boolean) => {
setItem(JSON.stringify(!!value));
};
export const setReadClipboardAllowed = async (value: boolean): Promise<void> => {
try {
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(Boolean(value)));
} catch (error) {
console.error('Failed to set clipboard permission:', error);
throw error;
}
};

const getClipboardContent = async () => {
export const getClipboardContent = async (): Promise<string | undefined> => {
try {
const isAllowed = await isReadClipboardAllowed();
const hasString = (await Clipboard.hasString()) || false;
if (isAllowed && hasString) {
return Clipboard.getString();
} else {
return '';
}
};
if (!isAllowed) return undefined;

return {
isReadClipboardAllowed,
setReadClipboardAllowed,
getClipboardContent,
};
const hasString = await Clipboard.hasString();
return hasString ? await Clipboard.getString() : undefined;
} catch (error) {
console.error('Error accessing clipboard:', error);
return undefined;
}
};

export default BlueClipboard;
71 changes: 55 additions & 16 deletions blue_modules/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,48 @@ let exchangeRates: ExchangeRates = { LAST_UPDATED_ERROR: false };
let lastTimeUpdateExchangeRateWasCalled: number = 0;
let skipUpdateExchangeRate: boolean = false;

let currencyFormatter: Intl.NumberFormat | null = null;
let btcFormatter: Intl.NumberFormat | null = null;

function getCurrencyFormatter(): Intl.NumberFormat {
if (
!currencyFormatter ||
currencyFormatter.resolvedOptions().locale !== preferredFiatCurrency.locale ||
currencyFormatter.resolvedOptions().currency !== preferredFiatCurrency.endPointKey
) {
currencyFormatter = new Intl.NumberFormat(preferredFiatCurrency.locale, {
style: 'currency',
currency: preferredFiatCurrency.endPointKey,
minimumFractionDigits: 2,
maximumFractionDigits: 8,
});
console.debug('Created new currency formatter');
} else {
console.debug('Using cached currency formatter');
}
return currencyFormatter;
}

function getBTCFormatter(): Intl.NumberFormat {
if (!btcFormatter || btcFormatter.resolvedOptions().locale !== preferredFiatCurrency.locale) {
btcFormatter = new Intl.NumberFormat(preferredFiatCurrency.locale, {
minimumFractionDigits: 8,
maximumFractionDigits: 8,
});
console.debug('Created new BTC formatter');
} else {
console.debug('Using cached BTC formatter');
}
return btcFormatter;
}

async function setPreferredCurrency(item: FiatUnitType): Promise<void> {
await AsyncStorage.setItem(PREFERRED_CURRENCY_STORAGE_KEY, JSON.stringify(item));
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set(PREFERRED_CURRENCY_STORAGE_KEY, item.endPointKey);
await DefaultPreference.set(PREFERRED_CURRENCY_LOCALE_STORAGE_KEY, item.locale.replace('-', '_'));
currencyFormatter = null;
btcFormatter = null;
}

async function updateExchangeRate(): Promise<void> {
Expand Down Expand Up @@ -79,7 +116,10 @@ async function updateExchangeRate(): Promise<void> {
rate.LAST_UPDATED_ERROR = true;
exchangeRates.LAST_UPDATED_ERROR = true;
await AsyncStorage.setItem(EXCHANGE_RATES_STORAGE_KEY, JSON.stringify(rate));
} catch (storageError) {}
} catch (storageError) {
exchangeRates = { LAST_UPDATED_ERROR: true };
throw storageError;
}
}
}

Expand Down Expand Up @@ -233,15 +273,9 @@ function satoshiToLocalCurrency(satoshi: number, format: boolean = true): string
if (format === false) return formattedAmount;

try {
const formatter = new Intl.NumberFormat(preferredFiatCurrency.locale, {
style: 'currency',
currency: preferredFiatCurrency.endPointKey,
minimumFractionDigits: 2,
maximumFractionDigits: 8,
});
return formatter.format(Number(formattedAmount));
return getCurrencyFormatter().format(Number(formattedAmount));
} catch (error) {
console.warn(error);
console.error(error);
return formattedAmount;
}
}
Expand All @@ -267,15 +301,10 @@ async function mostRecentFetchedRate(): Promise<CurrencyRate> {
currencyInformation = {};
}

const formatter = new Intl.NumberFormat(preferredFiatCurrency.locale, {
style: 'currency',
currency: preferredFiatCurrency.endPointKey,
});

const rate = currencyInformation[BTC_PREFIX + preferredFiatCurrency.endPointKey];
return {
LastUpdated: currencyInformation[LAST_UPDATED],
Rate: rate ? formatter.format(rate) : '...',
LastUpdated: currencyInformation[LAST_UPDATED] ? new Date(currencyInformation[LAST_UPDATED]) : null,
Rate: rate ? getCurrencyFormatter().format(rate) : '...',
};
} catch {
return {
Expand Down Expand Up @@ -309,6 +338,15 @@ function getCurrencySymbol(): string {
return preferredFiatCurrency.symbol;
}

function formatBTC(btc: BigNumber.Value): string {
try {
return getBTCFormatter().format(Number(btc));
} catch (error) {
console.error(error);
return new BigNumber(btc).toFixed(8);
}
}

function _setPreferredFiatCurrency(currency: FiatUnitType): void {
preferredFiatCurrency = currency;
}
Expand Down Expand Up @@ -341,4 +379,5 @@ export {
satoshiToLocalCurrency,
setPreferredCurrency,
updateExchangeRate,
formatBTC,
};
Loading

0 comments on commit b175304

Please sign in to comment.