Merge branch 'wownero' of https://github.com/cake-tech/cake_wallet into wownero_breez

This commit is contained in:
OmarHatem 2024-06-30 14:59:29 +03:00
commit 03e25b4adc
7 changed files with 69 additions and 21 deletions

View file

@ -53,15 +53,28 @@ void restoreWalletFromSeedSync(
required String seed, required String seed,
int nettype = 0, int nettype = 0,
int restoreHeight = 0}) { int restoreHeight = 0}) {
wptr = wownero.WalletManager_recoveryWallet( if (seed.split(" ").length == 14) {
wmPtr, wptr = wownero.WOWNERO_deprecated_restore14WordSeed(
path: path, path: path,
password: password, password: password,
mnemonic: seed, language: seed, // I KNOW - this is supposed to be called seed
restoreHeight: restoreHeight, networkType: 0,
seedOffset: '', );
networkType: 0,
); setRefreshFromBlockHeight(
height: wownero.WOWNERO_deprecated_14WordSeedHeight(seed: seed),
);
} else {
wptr = wownero.WalletManager_recoveryWallet(
wmPtr,
path: path,
password: password,
mnemonic: seed,
restoreHeight: restoreHeight,
seedOffset: '',
networkType: 0,
);
}
final status = wownero.Wallet_status(wptr!); final status = wownero.Wallet_status(wptr!);

View file

@ -10,6 +10,7 @@ class SeedType extends EnumerableItem<int> with Serializable<int> {
static const legacy = SeedType(raw: 0, title: 'Legacy (25 words)'); static const legacy = SeedType(raw: 0, title: 'Legacy (25 words)');
static const polyseed = SeedType(raw: 1, title: 'Polyseed (16 words)'); static const polyseed = SeedType(raw: 1, title: 'Polyseed (16 words)');
static const wowneroSeed = SeedType(raw: 1, title: 'Wownero (14 words)');
static SeedType deserialize({required int raw}) { static SeedType deserialize({required int raw}) {
switch (raw) { switch (raw) {
@ -17,6 +18,8 @@ class SeedType extends EnumerableItem<int> with Serializable<int> {
return legacy; return legacy;
case 1: case 1:
return polyseed; return polyseed;
case 2:
return wowneroSeed;
default: default:
throw Exception('Unexpected token: $raw for SeedType deserialize'); throw Exception('Unexpected token: $raw for SeedType deserialize');
} }
@ -29,6 +32,8 @@ class SeedType extends EnumerableItem<int> with Serializable<int> {
return S.current.seedtype_legacy; return S.current.seedtype_legacy;
case SeedType.polyseed: case SeedType.polyseed:
return S.current.seedtype_polyseed; return S.current.seedtype_polyseed;
case SeedType.wowneroSeed:
return S.current.seedtype_wownero;
default: default:
return ''; return '';
} }

View file

@ -90,6 +90,10 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
_changeSeedType(SeedType.polyseed); _changeSeedType(SeedType.polyseed);
_changeLanguage(lang.nameEnglish); _changeLanguage(lang.nameEnglish);
} }
if (widget.type == WalletType.wownero && seed.split(" ").length == 14) {
_changeSeedType(SeedType.wowneroSeed);
_changeLanguage("English");
}
widget.onSeedChange?.call(seed); widget.onSeedChange?.call(seed);
} }
@ -149,8 +153,20 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
await showPopUp<void>( await showPopUp<void>(
context: context, context: context,
builder: (_) => Picker( builder: (_) => Picker(
items: SeedType.all, items: switch (widget.type) {
selectedAtIndex: isPolyseed ? 1 : 0, WalletType.monero => [SeedType.legacy, SeedType.polyseed],
WalletType.wownero => [
SeedType.legacy,
SeedType.polyseed,
SeedType.wowneroSeed
],
_ => [SeedType.legacy]
},
selectedAtIndex: isPolyseed
? 1
: seedTypeController.value.text.contains("14")
? 2
: 0,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
onItemSelected: _changeSeedType, onItemSelected: _changeSeedType,
isSeparated: false, isSeparated: false,
@ -169,7 +185,7 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
), ),
), ),
), ),
if (widget.displayLanguageSelector) if (!seedTypeController.value.text.contains("14") && widget.displayLanguageSelector)
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
await showPopUp<void>( await showPopUp<void>(
@ -193,7 +209,9 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
), ),
), ),
), ),
if (!isPolyseed && widget.displayBlockHeightSelector) if ((!isPolyseed) &&
widget.displayBlockHeightSelector &&
(widget.type == WalletType.wownero && !seedTypeController.value.text.contains("14")))
BlockchainHeightWidget( BlockchainHeightWidget(
focusNode: widget.blockHeightFocusNode, focusNode: widget.blockHeightFocusNode,
key: blockchainHeightKey, key: blockchainHeightKey,
@ -228,7 +246,11 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
); );
void _changeLanguage(String language) { void _changeLanguage(String language) {
final setLang = isPolyseed ? "POLYSEED_$language" : language; final setLang = isPolyseed
? "POLYSEED_$language"
: seedTypeController.value.text.contains("14")
? "WOWSEED_" + language
: language;
setState(() { setState(() {
this.language = setLang; this.language = setLang;
seedWidgetStateKey.currentState!.changeSeedLanguage(setLang); seedWidgetStateKey.currentState!.changeSeedLanguage(setLang);

View file

@ -255,6 +255,8 @@ class WalletRestorePage extends BasePage {
final seedWords = seedPhrase.split(' '); final seedWords = seedPhrase.split(' ');
if (seedWords.length == 14 && walletRestoreViewModel.type == WalletType.wownero) return true;
if ((walletRestoreViewModel.type == WalletType.monero || if ((walletRestoreViewModel.type == WalletType.monero ||
walletRestoreViewModel.type == WalletType.wownero || walletRestoreViewModel.type == WalletType.wownero ||
walletRestoreViewModel.type == WalletType.haven) && walletRestoreViewModel.type == WalletType.haven) &&

View file

@ -44,7 +44,8 @@ abstract class WalletCreationVMBase with Store {
final AppStore _appStore; final AppStore _appStore;
bool isPolyseed(String seed) => bool isPolyseed(String seed) =>
(type == WalletType.monero || type == WalletType.wownero) && Polyseed.isValidSeed(seed); (type == WalletType.monero || type == WalletType.wownero) &&
(Polyseed.isValidSeed(seed) || (seed.split(" ").length == 14));
bool nameExists(String name) => walletCreationService.exists(name); bool nameExists(String name) => walletCreationService.exists(name);

View file

@ -170,6 +170,10 @@ class CWWownero extends Wownero {
final lang = language.replaceAll("POLYSEED_", ""); final lang = language.replaceAll("POLYSEED_", "");
return PolyseedLang.getByEnglishName(lang).words; return PolyseedLang.getByEnglishName(lang).words;
} }
if (language.startsWith("WOWSEED_")) {
final lang = language.replaceAll("WOWSEED_", "");
return PolyseedLang.getByEnglishName(lang).words;
}
switch (language.toLowerCase()) { switch (language.toLowerCase()) {
case 'english': case 'english':
return EnglishMnemonics.words; return EnglishMnemonics.words;
@ -224,13 +228,13 @@ class CWWownero extends Wownero {
name: name, password: password, height: height, mnemonic: mnemonic); name: name, password: password, height: height, mnemonic: mnemonic);
@override @override
WalletCredentials createWowneroNewWalletCredentials({ WalletCredentials createWowneroNewWalletCredentials(
required String name, {required String name,
required String language, required String language,
required bool isPolyseed, required bool isPolyseed,
String? password}) => String? password}) =>
WowneroNewWalletCredentials( WowneroNewWalletCredentials(
name: name, password: password, language: language, isPolyseed: isPolyseed); name: name, password: password, language: language, isPolyseed: isPolyseed);
@override @override
Map<String, String> getKeys(Object wallet) { Map<String, String> getKeys(Object wallet) {

View file

@ -594,6 +594,7 @@
"seedtype": "Seedtype", "seedtype": "Seedtype",
"seedtype_legacy": "Legacy (25 words)", "seedtype_legacy": "Legacy (25 words)",
"seedtype_polyseed": "Polyseed (16 words)", "seedtype_polyseed": "Polyseed (16 words)",
"seedtype_wownero": "Wownero (14 words)",
"select_backup_file": "Select backup file", "select_backup_file": "Select backup file",
"select_buy_provider_notice": "Select a buy provider above. You can skip this screen by setting your default buy provider in app settings.", "select_buy_provider_notice": "Select a buy provider above. You can skip this screen by setting your default buy provider in app settings.",
"select_destination": "Please select destination for the backup file.", "select_destination": "Please select destination for the backup file.",