Skip to content

Commit

Permalink
Merge branch 'feature/pre-release' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jul 26, 2024
2 parents 1324aff + 40272cc commit e0b3671
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
34 changes: 17 additions & 17 deletions Kukai Mobile/Modules/Home/Base.lproj/Home.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</connections>
</button>
<barButtonItem key="rightBarButtonItem" id="VdP-cC-k4T">
<button key="customView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" id="MfA-yg-iS7">
<button key="customView" opaque="NO" tag="17" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" id="MfA-yg-iS7">
<rect key="frame" x="288" y="3" width="86" height="38"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="tintColor" name="BG12"/>
Expand Down Expand Up @@ -212,13 +212,13 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="&lt;heading&gt;" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fxm-nU-LyP">
<rect key="frame" x="39.999999999999993" y="12.666666666666664" width="79.333333333333314" height="30"/>
<rect key="frame" x="40.000000000000007" y="18.333333333333329" width="76.666666666666686" height="18.666666666666671"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="16"/>
<color key="textColor" name="Txt10"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XEg-Fn-9q8" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="119.33333333333331" y="12.666666666666664" width="50" height="30"/>
<rect key="frame" x="116.66666666666669" y="18.333333333333329" width="50" height="18.666666666666671"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="NPg-Hh-oA7"/>
</constraints>
Expand Down Expand Up @@ -282,23 +282,23 @@
<rect key="frame" x="16" y="2" width="358" height="61"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="5Ye-Sl-4hC">
<rect key="frame" x="12" y="10.333333333333336" width="22" height="22"/>
<rect key="frame" x="12" y="11" width="22" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="JsF-FC-M3v"/>
<constraint firstAttribute="width" constant="22" id="Qfh-ad-6A0"/>
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="bCf-Ky-9Ha">
<rect key="frame" x="44" y="10.333333333333332" width="246" height="40.333333333333343"/>
<rect key="frame" x="44" y="11" width="246" height="39"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="&lt;title&gt;" textAlignment="natural" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eXR-AY-uAm">
<rect key="frame" x="0.0" y="0.0" width="246" height="19.333333333333332"/>
<rect key="frame" x="0.0" y="0.0" width="246" height="18.666666666666668"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="16"/>
<color key="textColor" name="Txt2"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="&lt;subtitle&gt;" textAlignment="natural" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dqA-p2-tZv">
<rect key="frame" x="0.0" y="23.333333333333329" width="246" height="17"/>
<rect key="frame" x="0.0" y="22.666666666666664" width="246" height="16.333333333333336"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="textColor" name="Txt10"/>
<nil key="highlightedColor"/>
Expand All @@ -321,10 +321,10 @@
</constraints>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TQu-WQ-O8r">
<rect key="frame" x="267.33333333333331" y="22.666666666666668" width="30.666666666666686" height="16.000000000000004"/>
<rect key="frame" x="268.66666666666669" y="22.666666666666668" width="29.333333333333314" height="15.666666666666668"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="NEW!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xVA-bH-wuC">
<rect key="frame" x="2" y="2" width="26.666666666666668" height="12"/>
<rect key="frame" x="2" y="2" width="25.333333333333332" height="11.666666666666666"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="10"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -396,7 +396,7 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="More (1)" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d1O-lW-vwG">
<rect key="frame" x="36" y="11" width="317" height="17"/>
<rect key="frame" x="36" y="11.333333333333334" width="317" height="16.333333333333329"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="textColor" name="TxtB6"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -1183,7 +1183,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4bK-1b-rfc">
<rect key="frame" x="16" y="77" width="358" height="690.33333333333337"/>
<rect key="frame" x="16" y="78" width="358" height="688.33333333333337"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Alert" translatesAutoresizingMaskIntoConstraints="NO" id="NU3-fB-cJx">
<rect key="frame" x="140" y="50" width="78" height="78"/>
Expand All @@ -1194,13 +1194,13 @@
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Remove Wallet?" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Y2v-fe-LwF">
<rect key="frame" x="16" y="144" width="326" height="26.666666666666657"/>
<rect key="frame" x="16" y="144" width="326" height="25.666666666666657"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="22"/>
<color key="textColor" name="Txt2"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="24" translatesAutoresizingMaskIntoConstraints="NO" id="CX8-pJ-Ude">
<rect key="frame" x="16" y="194.66666666666666" width="326" height="471.66666666666674"/>
<rect key="frame" x="16" y="193.66666666666666" width="326" height="470.66666666666674"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="w5y-lD-Fo2">
<rect key="frame" x="0.0" y="0.0" width="326" height="334"/>
Expand Down Expand Up @@ -1313,13 +1313,13 @@
</constraints>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Message that if you remove this wallet the accounts contained and all content will be removed" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rwk-gp-69K">
<rect key="frame" x="0.0" y="357.99999999999994" width="326" height="33.666666666666686"/>
<rect key="frame" x="0.0" y="357.99999999999994" width="326" height="32.666666666666686"/>
<fontDescription key="fontDescription" name="Figtree-Medium" family="Figtree" pointSize="14"/>
<color key="textColor" name="Txt6"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="LR0-GJ-gJA">
<rect key="frame" x="0.0" y="415.66666666666669" width="326" height="56"/>
<rect key="frame" x="0.0" y="414.66666666666669" width="326" height="56"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1un-2s-Olb" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="155" height="56"/>
Expand Down Expand Up @@ -1772,7 +1772,7 @@
<size key="intrinsicContentSize" width="44" height="34"/>
</designable>
<designable name="1un-2s-Olb">
<size key="intrinsicContentSize" width="76" height="36"/>
<size key="intrinsicContentSize" width="74" height="36"/>
</designable>
<designable name="5wT-IG-lLN">
<size key="intrinsicContentSize" width="63" height="36"/>
Expand Down Expand Up @@ -1805,7 +1805,7 @@
<size key="intrinsicContentSize" width="136.66666666666666" height="37.333333333333336"/>
</designable>
<designable name="j1h-E1-Rkf">
<size key="intrinsicContentSize" width="64" height="36"/>
<size key="intrinsicContentSize" width="63" height="36"/>
</designable>
<designable name="jXG-tZ-HG4">
<size key="intrinsicContentSize" width="45" height="36"/>
Expand Down
35 changes: 26 additions & 9 deletions Kukai Mobile/Modules/Home/HomeTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
self?.refreshType = .refreshEverything
self?.refresh(addresses: nil)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.recheckWalletConnectAnimation()
// When returning from a long background, WC2 can sometimes be stuck in a disconnected state.
// Give it a few seconds to try connect by itself, and then try manual intervention
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
self?.recheckWalletConnectAnimation(tryManualReconnect: true)
}
}.store(in: &bag)

Expand Down Expand Up @@ -242,9 +244,16 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
recheckWalletConnectAnimation()
}

public func recheckWalletConnectAnimation() {
// Seems to get stuck sometimes, unsure why, adding an extra check to ensure it gets checked
connectionStatusChanged(status: WalletConnectService.shared.isConnected ? .connected : .disconnected)
// When returning from background, WC2 socket can get stuck sometimes.
// First we double check that no event was missed by running the logic again
// Second we have an optional request to attempt to reconnect the socket by re-initalising the WC2 singletons
public func recheckWalletConnectAnimation(tryManualReconnect: Bool = false) {
let isConnected = WalletConnectService.shared.isConnected
connectionStatusChanged(status: isConnected ? .connected : .disconnected)

if !isConnected && tryManualReconnect {
attemptWC2Reconnect()
}
}

public override func viewDidLayoutSubviews() {
Expand Down Expand Up @@ -488,21 +497,29 @@ extension HomeTabBarController: WalletConnectServiceDelegate {

public func connectionStatusChanged(status: SocketConnectionStatus) {
if status == .disconnected {
self.walletConnectActivity.frame = self.scanButton.frame
self.scanButton.addSubview(self.walletConnectActivity)

self.scanButton.setImage(nil, for: .normal)
if walletConnectActivity.superview == nil {
self.walletConnectActivity.frame = self.scanButton.frame
self.walletConnectActivity.isUserInteractionEnabled = true
self.walletConnectActivity.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(attemptWC2Reconnect)))
self.scanButton.addSubview(self.walletConnectActivity)
}

self.scanButton.setImage(UIImage(), for: .normal) // passing in nil doesn't work sometimes, needs to be an empty image
self.walletConnectActivity.color = ThemeManager.shared.currentInterfaceStyle() == .dark ? .white : .black
self.walletConnectActivity.startAnimating()

} else {
self.scanButton.isEnabled = true
self.scanButton.setImage(UIImage(named: "ScanQR"), for: .normal)
self.walletConnectActivity.stopAnimating()
self.walletConnectActivity.removeFromSuperview()
}
}

@objc private func attemptWC2Reconnect() {
WalletConnectService.shared.setup(force: true)
}

/*
public func walletConnectSocketFailedToReconnect3Times() {
DispatchQueue.main.async {
Expand Down
8 changes: 4 additions & 4 deletions Kukai Mobile/Services/WalletConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public class WalletConnectService {
public var isConnected = false

private var bag = [AnyCancellable]()
private var connectionManagmentBag = [AnyCancellable]()
private var tempConnectionSubscription: AnyCancellable? = nil
private static let projectId = "97f804b46f0db632c52af0556586a5f3"
private static let metadata = AppMetadata(name: "Kukai iOS",
description: "Kukai iOS",
Expand All @@ -96,11 +94,13 @@ public class WalletConnectService {

private init() {}

public func setup() {
guard !hasBeenSetup else {
public func setup(force: Bool = false) {
guard !hasBeenSetup || force else {
return
}

bag.removeAll()

// Objects and metadata
Networking.configure(groupIdentifier: "group.app.kukai.mobile", projectId: WalletConnectService.projectId, socketFactory: DefaultSocketFactory(), socketConnectionType: .automatic)
Pair.configure(metadata: WalletConnectService.metadata)
Expand Down

0 comments on commit e0b3671

Please sign in to comment.