saveMnemonic method

  1. @override
Future<Either<WalletKeyException, Unit>> saveMnemonic(
  1. List<String> mnemonic,
  2. String mnemonicName
)

Persists the mnemonic to disk.

mnemonic is the mnemonic to persist. mnemonicName is the filepath to persist the mnemonic to.

Returns nothing if successful. If persisting fails due to an underlying cause, returns a WalletKeyException.

Implementation

@override
Future<Either<WalletKeyException, Unit>> saveMnemonic(
    List<String> mnemonic, String mnemonicName) async {
  if (await _storage.containsKey(key: mnemonicName)) {
    await _storage.write(key: mnemonicName, value: jsonEncode(mnemonic));
    return Either.unit();
  } else {
    return Either.left(
        WalletKeyException.mnemonicDoesNotExist(context: mnemonicName));
  }
}