emit url event when recreating Activity with link

Co-authored-by: Churikova Tetiana <churikova.tm@gmail.com>
Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-08-04 15:27:25 +02:00
parent 11cfb894a4
commit 85fcabe249
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
8 changed files with 36 additions and 8 deletions

View File

@ -23,6 +23,9 @@ import android.provider.Settings;
import android.os.Bundle;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import com.facebook.react.ReactFragmentActivity;
@ -32,6 +35,7 @@ import org.devio.rn.splashscreen.SplashScreen;
import java.util.Properties;
import im.status.ethereum.module.StatusThreadPoolExecutor;
import im.status.ethereum.MainApplication;
public class MainActivity extends NavigationActivity
implements ActivityCompat.OnRequestPermissionsResultCallback{
@ -97,6 +101,16 @@ public class MainActivity extends NavigationActivity
return intent;
}
private void tryToEmit(String eventName, WritableMap event) {
try {
((MainApplication) getApplication()).getReactNativeHost()
.getReactInstanceManager()
.getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("url", event);
} catch(Exception e) {/* we expect NPE on first start, which is OK because we have a fallback */}
}
@Override
public void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
@ -167,6 +181,16 @@ public class MainActivity extends NavigationActivity
@Override
public void run() {
System.loadLibrary("status-logs");
// when app is started but the Activity has been destroyed, the deep linking url event is
// not emitted when coming back to foreground. This is a workaround. If the problem is
// resolved in react-native this code should be removed
if (getIntent().getData() != null) {
WritableMap event = Arguments.createMap();
event.putString("url", getIntent().getDataString());
// on first start emit will (silently) fail, but the regular deep linking handler will work
tryToEmit("url", event);
}
}
};
@ -178,7 +202,7 @@ public class MainActivity extends NavigationActivity
super.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {

View File

@ -17,6 +17,7 @@
[status-im.utils.utils :as utils]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.anon-metrics.core :as anon-metrics]
[status-im.utils.universal-links.core :as universal-links]
clojure.set
status-im.currency.core
status-im.navigation
@ -144,6 +145,7 @@
(assoc :app-active-since now))}
(mailserver/process-next-messages-request)
(wallet/restart-wallet-service-after-background app-in-background-since)
(universal-links/process-stored-event)
#(when requires-bio-auth
(biometric/authenticate % on-biometric-auth-result authentication-options)))))

View File

@ -152,8 +152,8 @@
"Store url in the database if the user is not logged in, to be processed
on login, otherwise just handle it"
{:events [:universal-links/handle-url]}
[cofx url]
(if (multiaccounts.model/logged-in? cofx)
[{:keys [db] :as cofx} url]
(if (and (multiaccounts.model/logged-in? cofx) (= (:app-state db) "active"))
(route-url cofx url)
(store-url-for-later cofx url)))

View File

@ -14,7 +14,8 @@
(is (= {:db {:universal-links/url "some-url"}}
(links/handle-url {:db {}} "some-url")))))
(testing "the user is logged in"
(let [db {:multiaccount {:public-key "pk"}
(let [db {:multiaccount {:public-key "pk"}
:app-state "active"
:universal-links/url "some-url"}]
(testing "it clears the url"
(is (nil? (get-in (links/handle-url {:db db} "some-url")

View File

@ -700,7 +700,7 @@ class TestChatManagementMultipleDevice(MultipleDeviceTestCase):
device_1.open_notification_bar()
if device_1.element_by_text_part(message_after_block_2).is_element_displayed():
self.errors.append("Push notification is received from blocked user")
device_1.element_by_text_part("Background notification service").click()
device_1.element_by_text_part("Background service for notifications").click()
if public_chat_after_block_1.chat_element_by_text(message_after_block_2).is_element_displayed():
self.errors.append("Message from blocked user '%s' is received" % device_2.driver.number)

View File

@ -199,6 +199,7 @@ class TestCommandsMultipleDevices(MultipleDeviceTestCase):
home_1.just_fyi('Decline transaction request and check that state is changed')
request_amount = chat_1.get_unique_amount()
chat_1.commands_button.click()
request_transaction = chat_1.request_command.click()
request_transaction.amount_edit_box.set_value(request_amount)
request_transaction.confirm()

View File

@ -31,6 +31,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
@marks.testrail_id(6290)
@marks.high
@marks.flaky
def test_keycard_fetching_balance_after_offline(self):
sender = transaction_senders['F']
sign_in = SignInView(self.driver)
@ -42,7 +43,6 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
sign_in.just_fyi('Go back to online and check that balance is updated')
sign_in.set_network_to_cellular_only()
home.continue_syncing_button.wait_and_click()
home.connection_offline_icon.wait_for_invisibility_of_element(100)
wallet = home.wallet_button.click()
wallet.wait_balance_is_changed('ETH')

View File

@ -53,6 +53,7 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
@marks.testrail_id(6237)
@marks.high
@marks.flaky
def test_fetching_balance_after_offline(self):
sender = wallet_users['E']
sign_in = SignInView(self.driver)
@ -61,13 +62,12 @@ class TestTransactionWalletSingleDevice(SingleDeviceTestCase):
sign_in.set_device_to_offline()
sign_in.recover_access(sender['passphrase'])
home = sign_in.get_home_view()
wallet = home.wallet_button.click()
wallet.set_up_wallet()
sign_in.just_fyi('Go back to online and check that balance is updated')
sign_in.set_network_to_cellular_only()
home.continue_syncing_button.wait_and_click()
home.connection_offline_icon.wait_for_invisibility_of_element(100)
wallet = home.wallet_button.click()
wallet.wait_balance_is_changed('ETH')
wallet.scan_tokens('STT')
initial_amount_STT = wallet.get_asset_amount_by_name('STT')