Merge pull request #2620 from BlueWallet/fixes

This commit is contained in:
Marcos Rodriguez Vélez 2021-02-16 07:43:23 -05:00 committed by GitHub
commit 6bae92dee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 191 additions and 117 deletions

View File

@ -1,5 +1,11 @@
import { useContext, useEffect } from 'react';
import { updateApplicationContext, watchEvents, useReachability, useInstalled } from 'react-native-watch-connectivity';
import {
updateApplicationContext,
watchEvents,
useReachability,
useInstalled,
transferCurrentComplicationUserInfo,
} from 'react-native-watch-connectivity';
import { InteractionManager } from 'react-native';
import { Chain } from './models/bitcoinUnits';
import loc, { formatBalance, transactionTimeToReadable } from './loc';
@ -19,14 +25,13 @@ function WatchConnectivity() {
watchEvents.on('message', handleMessages);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized, wallets, isReachable, isInstalled]);
}, [walletsInitialized, wallets, preferredFiatCurrency, isReachable, isInstalled]);
useEffect(() => {
if (walletsInitialized) {
if (walletsInitialized && preferredFiatCurrency) {
try {
updateApplicationContext({
transferCurrentComplicationUserInfo({
preferredFiatCurrency: JSON.parse(preferredFiatCurrency).endPointKey,
randomID: Math.floor(Math.random() * 11),
});
} catch (e) {
console.log('WatchConnectivity useEffect preferredFiatCurrency error');

View File

@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { View } from 'react-native';
const ToolTipMenu = (props, ref) => {
const toolTip = useRef(null);
const toolTip = useRef();
const showMenu = () => {
console.log('Showing ToolTip');
@ -15,7 +15,11 @@ const ToolTipMenu = (props, ref) => {
ref.current.showMenu = showMenu;
}, [ref]);
return <View ref={ref}>{ref.current && <ToolTip ref={toolTip} actions={props.actions} />}</View>;
return (
<View ref={ref}>
<ToolTip ref={toolTip} actions={props.actions} />
</View>
);
};
export default forwardRef(ToolTipMenu);

View File

@ -128,94 +128,154 @@ class ComplicationController: NSObject, CLKComplicationDataSource {
} else {
handler(nil)
}
default:
preconditionFailure("Complication family not supported")
}
}
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}
// MARK: - Placeholder Templates
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
let line1Text = CLKSimpleTextProvider(text:"46 K")
let line2Text = CLKSimpleTextProvider(text:"$")
switch complication.family {
case .circularSmall:
let template = CLKComplicationTemplateCircularSmallStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
case .utilitarianSmallFlat:
let template = CLKComplicationTemplateUtilitarianSmallFlat()
case .modularLarge:
let template = CLKComplicationTemplateModularLargeStandardBody()
if #available(watchOSApplicationExtension 6.0, *) {
template.textProvider = CLKTextProvider(format: "%@", "$46,134")
template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price")
template.body1TextProvider = CLKTextProvider(format: "%@%@", currencySymbol, valueLabel)
entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
handler(entry)
} else {
handler(nil)
}
handler(template)
case .utilitarianSmall:
let template = CLKComplicationTemplateUtilitarianSmallRingImage()
template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Utilitarian")!)
handler(template)
case .graphicCircular:
case .extraLarge:
handler(nil)
case .graphicRectangular:
let template = CLKComplicationTemplateGraphicRectangularStandardBody()
if #available(watchOSApplicationExtension 6.0, *) {
let template = CLKComplicationTemplateGraphicCircularStackText()
template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price")
template.body1TextProvider = CLKTextProvider(format: "%@%@", currencySymbol, valueLabel)
entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
handler(entry)
} else {
handler(nil)
}
case .graphicExtraLarge:
if #available(watchOSApplicationExtension 7.0, *) {
let template = CLKComplicationTemplateGraphicExtraLargeCircularStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
handler(entry)
} else {
handler(nil)
}
case .graphicCorner:
let template = CLKComplicationTemplateGraphicCornerStackText()
if #available(watchOSApplicationExtension 6.0, *) {
template.outerTextProvider = CLKTextProvider(format: "46,134")
template.innerTextProvider = CLKTextProvider(format: "$")
} else {
handler(nil)
}
handler(template)
case .modularSmall:
let template = CLKComplicationTemplateModularSmallStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
case .utilitarianLarge:
if #available(watchOSApplicationExtension 7.0, *) {
let textProvider = CLKTextProvider(format: "%@%@", "$", "46,000")
let template = CLKComplicationTemplateUtilitarianLargeFlat(textProvider: textProvider)
handler(template)
} else {
handler(nil)
}
case .graphicBezel:
let template = CLKComplicationTemplateGraphicBezelCircularText()
if #available(watchOSApplicationExtension 6.0, *) {
template.textProvider = CLKTextProvider(format: "%@%@", "$S", "46,000")
let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "Complication/Graphic Bezel")!)
let circularTemplate = CLKComplicationTemplateGraphicCircularImage()
circularTemplate.imageProvider = imageProvider
template.circularTemplate = circularTemplate
handler(template)
} else {
handler(nil)
}
default:
handler(nil)
@unknown default:
fatalError()
}
}
}
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}
// MARK: - Placeholder Templates
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
let line1Text = CLKSimpleTextProvider(text:"46 K")
let line2Text = CLKSimpleTextProvider(text:"$")
switch complication.family {
case .circularSmall:
let template = CLKComplicationTemplateCircularSmallStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
case .utilitarianSmallFlat:
let template = CLKComplicationTemplateUtilitarianSmallFlat()
if #available(watchOSApplicationExtension 6.0, *) {
template.textProvider = CLKTextProvider(format: "%@", "$46,134")
} else {
handler(nil)
}
handler(template)
case .utilitarianSmall:
let template = CLKComplicationTemplateUtilitarianSmallRingImage()
template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "Complication/Utilitarian")!)
handler(template)
case .graphicCircular:
if #available(watchOSApplicationExtension 6.0, *) {
let template = CLKComplicationTemplateGraphicCircularStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
} else {
handler(nil)
}
case .graphicCorner:
let template = CLKComplicationTemplateGraphicCornerStackText()
if #available(watchOSApplicationExtension 6.0, *) {
template.outerTextProvider = CLKTextProvider(format: "46,134")
template.innerTextProvider = CLKTextProvider(format: "$")
} else {
handler(nil)
}
handler(template)
case .modularSmall:
let template = CLKComplicationTemplateModularSmallStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
case .utilitarianLarge:
if #available(watchOSApplicationExtension 7.0, *) {
let textProvider = CLKTextProvider(format: "%@%@", "$", "46,000")
let template = CLKComplicationTemplateUtilitarianLargeFlat(textProvider: textProvider)
handler(template)
} else {
handler(nil)
}
case .graphicBezel:
let template = CLKComplicationTemplateGraphicBezelCircularText()
if #available(watchOSApplicationExtension 6.0, *) {
template.textProvider = CLKTextProvider(format: "%@%@", "$S", "46,000")
let imageProvider = CLKFullColorImageProvider(fullColorImage: UIImage(named: "Complication/Graphic Bezel")!)
let circularTemplate = CLKComplicationTemplateGraphicCircularImage()
circularTemplate.imageProvider = imageProvider
template.circularTemplate = circularTemplate
handler(template)
} else {
handler(nil)
}
case .modularLarge:
let template = CLKComplicationTemplateModularLargeStandardBody()
if #available(watchOSApplicationExtension 6.0, *) {
template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price")
template.body1TextProvider = CLKTextProvider(format: "%@%@", "$S", "46,000")
handler(template)
} else {
handler(nil)
}
case .extraLarge:
handler(nil)
case .graphicRectangular:
let template = CLKComplicationTemplateGraphicRectangularStandardBody()
if #available(watchOSApplicationExtension 6.0, *) {
template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price")
template.body1TextProvider = CLKTextProvider(format: "%@%@", "$S", "46,000")
handler(template)
} else {
handler(nil)
}
case .graphicExtraLarge:
if #available(watchOSApplicationExtension 7.0, *) {
let template = CLKComplicationTemplateGraphicExtraLargeCircularStackText()
template.line1TextProvider = line1Text
template.line2TextProvider = line2Text
handler(template)
} else {
handler(nil)
}
default:
handler(nil)
}
}

View File

@ -25,7 +25,6 @@
<key>CLKComplicationSupportedFamilies</key>
<array>
<string>CLKComplicationFamilyCircularSmall</string>
<string>CLKComplicationFamilyExtraLarge</string>
<string>CLKComplicationFamilyGraphicBezel</string>
<string>CLKComplicationFamilyGraphicCircular</string>
<string>CLKComplicationFamilyGraphicCorner</string>

View File

@ -96,25 +96,27 @@ class WatchDataSource: NSObject, WCSessionDelegate {
}
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
if let preferredFiatCurrency = applicationContext["preferredFiatCurrency"] as? String, let preferredFiatCurrencyUnit = fiatUnit(currency: preferredFiatCurrency) {
UserDefaults.standard.set(preferredFiatCurrencyUnit.endPointKey, forKey: "preferredFiatCurrency")
UserDefaults.standard.synchronize()
ExtensionDelegate.preferredFiatCurrencyChanged()
} else {
WatchDataSource.shared.processWalletsData(walletsInfo: applicationContext)
}
processData(data: applicationContext)
}
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
if let preferredFiatCurrency = applicationContext["preferredFiatCurrency"] as? String, let preferredFiatCurrencyUnit = fiatUnit(currency: preferredFiatCurrency) {
processData(data: applicationContext)
}
func processData(data: [String: Any]) {
if let preferredFiatCurrency = data["preferredFiatCurrency"] as? String, let preferredFiatCurrencyUnit = fiatUnit(currency: preferredFiatCurrency) {
UserDefaults.standard.set(preferredFiatCurrencyUnit.endPointKey, forKey: "preferredFiatCurrency")
UserDefaults.standard.synchronize()
ExtensionDelegate.preferredFiatCurrencyChanged()
ExtensionDelegate.preferredFiatCurrencyChanged()
} else {
WatchDataSource.shared.processWalletsData(walletsInfo: applicationContext)
WatchDataSource.shared.processWalletsData(walletsInfo: data)
}
}
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
processData(data: userInfo)
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
if activationState == .activated {
if let existingData = keychain.getData(Wallet.identifier), let walletData = ((try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(existingData) as? [Wallet]) as [Wallet]??) {

View File

@ -2,31 +2,35 @@
"images" : [
{
"filename" : "extra-large38mm@2x.png",
"screen-width" : "<=145",
"idiom" : "watch",
"scale" : "2x"
},
{
"screen-width" : ">161",
"filename" : "extra-large40mm@2x.png",
"idiom" : "watch",
"scale" : "2x"
},
{
"screen-width" : ">145",
"idiom" : "watch",
"filename" : "extra-large42mm@2x.png",
"scale" : "2x"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183",
"filename" : "extra-large44mm@2x.png"
"screen-width" : "<=145"
},
{
"filename" : "extra-large40mm@2x.png",
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"filename" : "extra-large42mm@2x.png",
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
},
{
"filename" : "extra-large44mm@2x.png",
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"auto-scaling" : "auto",
"template-rendering-intent" : "template"
}
}
}