Skip to content

Commit

Permalink
fixed secureStorage await write to avoid crash on web
Browse files Browse the repository at this point in the history
  • Loading branch information
Fmar committed Sep 12, 2023
1 parent 4b00f5a commit a1b78e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/provider/setting_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SettingProvider extends ChangeNotifier {
return _keyIsPrivateMap[_settingData!.privateKeyIndex.toString()] ?? false;
}

int addAndChangeKey(String key, bool isPrivate, {bool updateUI = false}) {
Future<int> addAndChangeKey(String key, bool isPrivate, {bool updateUI = false}) async {
int? findIndex;
var entries = _keyMap.entries;
for (var entry in entries) {
Expand All @@ -125,8 +125,8 @@ class SettingProvider extends ChangeNotifier {

_settingData!.privateKeyIndex = i;

secureStorage.write(key: KEYS_MAP,value: json.encode(_keyMap));
secureStorage.write(key: IS_PRIVATE_MAP,value: json.encode(_keyIsPrivateMap));
await secureStorage.write(key: KEYS_MAP,value: json.encode(_keyMap));
await secureStorage.write(key: IS_PRIVATE_MAP,value: json.encode(_keyIsPrivateMap));
saveAndNotifyListeners(updateUI: updateUI);

return i;
Expand Down
2 changes: 1 addition & 1 deletion lib/router/index/account_manager_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class AccountsState extends State<AccountsComponent> {
}
// logout current and login new
var oldIndex = settingProvider.privateKeyIndex;
var newIndex = settingProvider.addAndChangeKey(key, !isPublic);
var newIndex = await settingProvider.addAndChangeKey(key, !isPublic);
if (oldIndex != newIndex) {
clearCurrentMemInfo();
doLogin();
Expand Down
14 changes: 7 additions & 7 deletions lib/router/login/login_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class _LoginRouter extends State<LoginRouter>
list.add(Container(
margin: const EdgeInsets.all(Base.BASE_PADDING),
child: InkWell(
onTap: () {
doLogin(controller.text, false, false);
onTap: () async {
await doLogin(controller.text, false, false);
},
child: Container(
height: 36,
Expand Down Expand Up @@ -168,7 +168,7 @@ class _LoginRouter extends State<LoginRouter>
BotToast.showText(text: pubKey);
print("PUBLIC KEY: " + pubKey);
}
doLogin(pubKey, true, false);
await doLogin(pubKey, true, false);
} else {
BotToast.showText(text: "Invalid public key");
}
Expand All @@ -195,9 +195,9 @@ class _LoginRouter extends State<LoginRouter>
list.add(Container(
margin: const EdgeInsets.all(Base.BASE_PADDING),
child: InkWell(
onTap: () {
onTap: () async {
generatePK();
doLogin(controller.text, false, true);
await doLogin(controller.text, false, true);
},
child: Container(
height: 40,
Expand Down Expand Up @@ -310,7 +310,7 @@ class _LoginRouter extends State<LoginRouter>
);
}

void doLogin(String key,bool pubOnly, bool newKey) {
Future<void> doLogin(String key,bool pubOnly, bool newKey) async {
if (StringUtil.isBlank(key)) {
BotToast.showText(text: I18n.of(context).Private_key_is_null);
return;
Expand All @@ -322,7 +322,7 @@ class _LoginRouter extends State<LoginRouter>
if (Nip19.isPubkey(key) || Nip19.isPrivateKey(key)) {
key = Nip19.decode(key);
}
settingProvider.addAndChangeKey(key, !isPublic, updateUI: false);
await settingProvider.addAndChangeKey(key, !isPublic, updateUI: false);
if (!newKey) {
var tempNostr = Nostr(privateKey: !isPublic?key:null, publicKey: isPublic?key:null);

Expand Down

0 comments on commit a1b78e4

Please sign in to comment.