forked from axiom-team/gecko
Merge branch 'byebyeRust'
This commit is contained in:
commit
0b3f082447
|
@ -1,3 +0,0 @@
|
|||
[alias]
|
||||
bd = "make android-dev32"
|
||||
br = "make"
|
|
@ -44,18 +44,14 @@ android/key.properties
|
|||
# Exceptions to above rules.
|
||||
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
|
||||
|
||||
# Autogenerated dart/rust binding code
|
||||
native/dubp_rs/binding.h
|
||||
packages/dubp_rs/lib/ffi.dart
|
||||
|
||||
# Rust compiled libs for android or ios
|
||||
**/*.a
|
||||
**/*.so
|
||||
|
||||
# Rust things
|
||||
/target
|
||||
|
||||
pubkeys.txt
|
||||
|
||||
# Linux builds
|
||||
linux/
|
||||
|
||||
# Custom
|
||||
scripts/private/
|
||||
AppDir/
|
||||
appimage-builder-cache/
|
||||
AppImageBuilder.yml
|
||||
|
|
|
@ -8,9 +8,6 @@ stages:
|
|||
image: axiomteam/gecko-ci:v0.0.8
|
||||
tags:
|
||||
- redshift
|
||||
before_script:
|
||||
- rustup show
|
||||
- rustc --version && cargo --version
|
||||
|
||||
format:
|
||||
extends: .env
|
||||
|
@ -20,10 +17,6 @@ format:
|
|||
- if: $CI_COMMIT_TAG || $CI_MERGE_REQUEST_ID
|
||||
- when: manual
|
||||
stage: format
|
||||
script:
|
||||
- cargo fmt -- --version
|
||||
- cargo fmt -- --check
|
||||
- flutter format --set-exit-if-changed lib packages/dubp_rs/lib/dubp.dart
|
||||
|
||||
build_and_test:
|
||||
extends: .env
|
||||
|
@ -35,11 +28,8 @@ build_and_test:
|
|||
stage: build_and_test
|
||||
tags:
|
||||
- redshift
|
||||
script:
|
||||
- RUSTFLAGS="-D warnings" cargo make
|
||||
- cd packages/dubp_rs && flutter pub get && cd ../..
|
||||
script:
|
||||
- flutter analyze
|
||||
- cargo test
|
||||
# - flutter test
|
||||
|
||||
lint:
|
||||
|
@ -50,9 +40,6 @@ lint:
|
|||
- if: $CI_COMMIT_TAG || $CI_MERGE_REQUEST_ID
|
||||
- when: manual
|
||||
stage: quality
|
||||
script:
|
||||
- cargo clippy -- -V
|
||||
- cargo clippy --all --tests -- -D warnings --verbose
|
||||
|
||||
audit_dependencies:
|
||||
extends: .env
|
||||
|
@ -62,9 +49,6 @@ audit_dependencies:
|
|||
- if: $CI_COMMIT_TAG || $CI_MERGE_REQUEST_ID
|
||||
- when: manual
|
||||
stage: quality
|
||||
script:
|
||||
- cargo deny -V
|
||||
- cargo deny check
|
||||
|
||||
releases:test:
|
||||
extends: .env
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[hooks]
|
||||
pre-commit = "cargo fmt -- --check && flutter format --set-exit-if-changed lib packages/dubp_rs/lib/dubp.dart"
|
||||
|
||||
[logging]
|
||||
verbose = true
|
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
|
@ -1,10 +0,0 @@
|
|||
[workspace]
|
||||
members = ["native/dubp_rs"]
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
debug = true
|
||||
|
||||
[patch.crates-io]
|
||||
#dup-crypto = { path = "/home/elois/dev/duniter/libs/dubp-rs-libs/crypto" }
|
369
Makefile.toml
369
Makefile.toml
|
@ -1,369 +0,0 @@
|
|||
[env]
|
||||
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
|
||||
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["native/dubp_rs"]
|
||||
ANDROID_PLATFORM_VERSION = "21"
|
||||
TARGET_OS = "unknown"
|
||||
RELEASE = true
|
||||
DEV = false
|
||||
LIB_OUT_DIR = "release"
|
||||
|
||||
[env.debug]
|
||||
DEV = true
|
||||
RELEASE = false
|
||||
LIB_OUT_DIR = "debug"
|
||||
|
||||
[tasks.test-flow]
|
||||
disabled = true
|
||||
|
||||
[tasks.android-dev32]
|
||||
description = "development android i686 emulator"
|
||||
category = "Build"
|
||||
dependencies = [
|
||||
"setup-crate-type-android",
|
||||
"pre-android",
|
||||
"android-i686",
|
||||
"android-i686-release",
|
||||
"post-android-i686",
|
||||
"post-android",
|
||||
]
|
||||
|
||||
[tasks.android-dev]
|
||||
description = "development android x86_64 emulator"
|
||||
category = "Build"
|
||||
dependencies = [
|
||||
"setup-crate-type-android",
|
||||
"pre-android",
|
||||
"android-x86_64",
|
||||
"android-x86_64-release",
|
||||
"post-android-x86_64",
|
||||
"post-android",
|
||||
]
|
||||
|
||||
[tasks.android-arm]
|
||||
description = "build android ARM64 for actual device"
|
||||
category = "Build"
|
||||
dependencies = [
|
||||
"setup-crate-type-android",
|
||||
"pre-android",
|
||||
"android-aarch64",
|
||||
"android-aarch64-release",
|
||||
"post-android-aarch64",
|
||||
"post-android",
|
||||
]
|
||||
|
||||
|
||||
[tasks.build]
|
||||
description = "Runs the rust compiler."
|
||||
category = "Build"
|
||||
dependencies = ["android"]
|
||||
|
||||
[tasks.build.mac]
|
||||
description = "Runs the rust compiler."
|
||||
category = "Build"
|
||||
dependencies = ["android", "ios"]
|
||||
|
||||
# ANDROID
|
||||
|
||||
[tasks.android]
|
||||
description = "Build android targets."
|
||||
category = "Build"
|
||||
dependencies = [
|
||||
"setup-crate-type-android",
|
||||
"pre-android",
|
||||
"android-aarch64",
|
||||
"android-aarch64-release",
|
||||
"post-android-aarch64",
|
||||
"android-armv7",
|
||||
"android-armv7-release",
|
||||
"post-android-armv7",
|
||||
#"android-i686",
|
||||
#"android-i686-release",
|
||||
#"post-android-i686",
|
||||
#"android-x86_64",
|
||||
#"android-x86_64-release",
|
||||
#"post-android-x86_64",
|
||||
"post-android"
|
||||
]
|
||||
|
||||
[tasks.android-build]
|
||||
private = true
|
||||
condition = { env_true = ["DEV"], env_set = ["ANDROID_TARGET"] }
|
||||
command = "cargo"
|
||||
args = [
|
||||
"ndk",
|
||||
"--platform",
|
||||
"${ANDROID_PLATFORM_VERSION}",
|
||||
"--target",
|
||||
"${ANDROID_TARGET}",
|
||||
"build",
|
||||
]
|
||||
|
||||
[tasks.android-build-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"], env_set = ["ANDROID_TARGET"] }
|
||||
command = "cargo"
|
||||
args = [
|
||||
"ndk",
|
||||
"--platform",
|
||||
"${ANDROID_PLATFORM_VERSION}",
|
||||
"--target",
|
||||
"${ANDROID_TARGET}",
|
||||
"build",
|
||||
"--release"
|
||||
]
|
||||
|
||||
[tasks.android-aarch64]
|
||||
private = true
|
||||
condition = { env_true = ["DEV"] }
|
||||
env = { ANDROID_TARGET = "aarch64-linux-android" }
|
||||
run_task = "android-build"
|
||||
|
||||
[tasks.android-armv7]
|
||||
private = true
|
||||
condition = { env_true = ["DEV"] }
|
||||
env = { ANDROID_TARGET = "armv7-linux-androideabi" }
|
||||
run_task = "android-build"
|
||||
|
||||
[tasks.android-i686]
|
||||
private = true
|
||||
condition = { env_true = ["DEV"] }
|
||||
env = { ANDROID_TARGET = "i686-linux-android" }
|
||||
run_task = "android-build"
|
||||
|
||||
[tasks.android-x86_64]
|
||||
private = true
|
||||
condition = { env_true = ["DEV"] }
|
||||
env = { ANDROID_TARGET = "x86_64-linux-android" }
|
||||
run_task = "android-build"
|
||||
|
||||
[tasks.android-aarch64-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"] }
|
||||
env = { ANDROID_TARGET = "aarch64-linux-android" }
|
||||
run_task = "android-build-release"
|
||||
|
||||
[tasks.android-armv7-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"] }
|
||||
env = { ANDROID_TARGET = "armv7-linux-androideabi" }
|
||||
run_task = "android-build-release"
|
||||
|
||||
[tasks.android-i686-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"] }
|
||||
env = { ANDROID_TARGET = "i686-linux-android" }
|
||||
run_task = "android-build-release"
|
||||
|
||||
[tasks.android-x86_64-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"] }
|
||||
env = { ANDROID_TARGET = "x86_64-linux-android" }
|
||||
run_task = "android-build-release"
|
||||
|
||||
[tasks.pre-android]
|
||||
private = true
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/arm64-v8a",
|
||||
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/armeabi-v7a",
|
||||
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/x86",
|
||||
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/x86_64",
|
||||
]
|
||||
|
||||
[tasks.android-copy-lib]
|
||||
private = true
|
||||
condition = { env_set = ["ANDROID_TARGET", "JNI_LIB_DIR"] }
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"""
|
||||
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${ANDROID_TARGET}/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.so \
|
||||
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/${JNI_LIB_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.so
|
||||
""",
|
||||
]
|
||||
|
||||
[tasks.post-android-aarch64]
|
||||
private = true
|
||||
env = { ANDROID_TARGET = "aarch64-linux-android", JNI_LIB_DIR = "arm64-v8a" }
|
||||
run_task = "android-copy-lib"
|
||||
|
||||
[tasks.post-android-armv7]
|
||||
private = true
|
||||
env = { ANDROID_TARGET = "armv7-linux-androideabi", JNI_LIB_DIR = "armeabi-v7a" }
|
||||
run_task = "android-copy-lib"
|
||||
|
||||
[tasks.post-android-i686]
|
||||
private = true
|
||||
env = { ANDROID_TARGET = "i686-linux-android", JNI_LIB_DIR = "x86" }
|
||||
run_task = "android-copy-lib"
|
||||
|
||||
[tasks.post-android-x86_64]
|
||||
private = true
|
||||
env = { ANDROID_TARGET = "x86_64-linux-android", JNI_LIB_DIR = "x86_64" }
|
||||
run_task = "android-copy-lib"
|
||||
|
||||
[tasks.post-android]
|
||||
dependencies = ["restore-crate-type"]
|
||||
|
||||
# IOS
|
||||
|
||||
[tasks.ios]
|
||||
description = "build iOS targets"
|
||||
category = "Build"
|
||||
dependencies = ["ios-build", "ios-release", "post-ios"]
|
||||
|
||||
[tasks.ios-build]
|
||||
condition = { platforms = ["mac"], env_true = ["DEV"] }
|
||||
description = "Build ios targets."
|
||||
category = "Build"
|
||||
command = "cargo"
|
||||
args = ["lipo"]
|
||||
dependencies = [
|
||||
"setup-crate-type-ios",
|
||||
]
|
||||
|
||||
[tasks.ios-release]
|
||||
condition = { platforms = ["mac"], env_true = ["RELEASE"] }
|
||||
description = "Build ios targets."
|
||||
category = "Build"
|
||||
command = "cargo"
|
||||
args = ["lipo", "--release"]
|
||||
dependencies = [
|
||||
"setup-crate-type-ios",
|
||||
]
|
||||
|
||||
[tasks.post-ios]
|
||||
script_runner = "@duckscript"
|
||||
condition = { platforms = ["mac"] }
|
||||
script = [
|
||||
"""
|
||||
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/universal/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.a \
|
||||
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/ios/lib${CARGO_MAKE_CRATE_FS_NAME}.a
|
||||
""",
|
||||
"""
|
||||
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/binding.h \
|
||||
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/ios/Classes/binding.h
|
||||
""",
|
||||
]
|
||||
dependencies = ["restore-crate-type"]
|
||||
|
||||
# LINUX
|
||||
|
||||
[tasks.linux]
|
||||
description = "Build linux targets."
|
||||
category = "Build"
|
||||
dependencies = [
|
||||
"setup-crate-type-linux",
|
||||
"pre-linux",
|
||||
"linux-x86_64-release",
|
||||
"linux-copy-lib",
|
||||
"post-linux"
|
||||
]
|
||||
|
||||
[tasks.pre-linux]
|
||||
private = true
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/linux",
|
||||
]
|
||||
|
||||
[tasks.linux-x86_64-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"] }
|
||||
env = { LINUX_TARGET = "x86_64-unknown-linux-gnu" }
|
||||
run_task = "linux-build-release"
|
||||
|
||||
[tasks.linux-build-release]
|
||||
private = true
|
||||
condition = { env_true = ["RELEASE"], env_set = ["LINUX_TARGET"] }
|
||||
command = "cargo"
|
||||
args = [
|
||||
"build",
|
||||
"--release",
|
||||
"--target",
|
||||
"${LINUX_TARGET}"
|
||||
]
|
||||
|
||||
[tasks.linux-copy-lib]
|
||||
private = true
|
||||
condition = { env_set = ["LINUX_TARGET"] }
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"""
|
||||
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${LINUX_TARGET}/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.so \
|
||||
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/linux/lib${CARGO_MAKE_CRATE_FS_NAME}.so
|
||||
""",
|
||||
]
|
||||
|
||||
[tasks.post-linux]
|
||||
dependencies = ["restore-crate-type"]
|
||||
|
||||
# SETUP CRATE TYPE
|
||||
|
||||
[tasks.setup-crate-type-android]
|
||||
private = true
|
||||
env = { TARGET_OS = "android" }
|
||||
run_task = "setup-crate-type"
|
||||
|
||||
[tasks.setup-crate-type-ios]
|
||||
private = true
|
||||
env = { TARGET_OS = "ios" }
|
||||
run_task = "setup-crate-type"
|
||||
|
||||
[tasks.setup-crate-type-linux]
|
||||
private = true
|
||||
env = { TARGET_OS = "linux" }
|
||||
run_task = "setup-crate-type"
|
||||
|
||||
[tasks.setup-crate-type]
|
||||
private = true
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"""
|
||||
toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml
|
||||
crate_type = set ""
|
||||
os = get_env TARGET_OS
|
||||
is_android = eq ${os} "android"
|
||||
is_ios = eq ${os} "ios"
|
||||
is_linux = eq ${os} "linux"
|
||||
if ${is_android}
|
||||
crate_type = set "cdylib"
|
||||
elseif ${is_ios}
|
||||
crate_type = set "staticlib"
|
||||
elseif ${is_linux}
|
||||
crate_type = set "cdylib"
|
||||
else
|
||||
crate_type = set "rlib"
|
||||
end
|
||||
val = replace ${toml} "rlib" ${crate_type}
|
||||
result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml ${val}
|
||||
assert ${result}
|
||||
""",
|
||||
]
|
||||
|
||||
# RESTORE CRATE TYPE
|
||||
|
||||
[tasks.restore-crate-type]
|
||||
private = true
|
||||
script_runner = "@duckscript"
|
||||
script = [
|
||||
"""
|
||||
toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml
|
||||
crate_type = set ""
|
||||
os = get_env TARGET_OS
|
||||
is_android = eq ${os} "android"
|
||||
is_ios = eq ${os} "ios"
|
||||
is_linux = eq ${os} "linux"
|
||||
if ${is_android}
|
||||
crate_type = set "cdylib"
|
||||
elseif ${is_ios}
|
||||
crate_type = set "staticlib"
|
||||
elseif ${is_linux}
|
||||
crate_type = set "cdylib"
|
||||
else
|
||||
crate_type = set "rlib"
|
||||
end
|
||||
val = replace ${toml} ${crate_type} "rlib"
|
||||
result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml ${val}
|
||||
assert ${result}
|
||||
""",
|
||||
]
|
|
@ -1,6 +1,6 @@
|
|||
# Ğecko
|
||||
|
||||
Ğecko is a transaction client owned by [Axiom-Team association] and written in Dart. It is fast and secure thanks to native code compilation, Rust cryptography bindings and Duniter's new GraphQL API (GVA). It is not intended to manage member accounts, but rather simple wallets.
|
||||
Ğecko is a transaction client owned by [Axiom-Team association] and written in Dart. It is fast and secure thanks to native code compilation. It is not intended to manage member accounts, but rather simple wallets.
|
||||
|
||||
The development is quite early, you can participate in the discussion [on the Duniter forum](https://forum.duniter.org/t/gecko-nouveau-client-de-paiements-1-sur-mobile-en-cours-de-developpement-dart-flutter/7857) (mostly FR)
|
||||
|
||||
|
@ -27,7 +27,6 @@ To contribute to the code, we advise you to install the following development en
|
|||
- Android NDK
|
||||
1. Flutter SDK
|
||||
1. VSCode/Codium Flutter extension
|
||||
1. Rust toolchain
|
||||
|
||||
This will take about 12GB on your drive and 30 min of your time (with a good connection). Don't hesitate to ask on the forum for a peer-coding session if you are stuck.
|
||||
|
||||
|
@ -58,12 +57,6 @@ Flutter is a powerfull SDK to develop Android apps. [Install it](https://flutter
|
|||
We are using VSCode and therefore document the process for this IDE. Of course you're free to use whatever you want.
|
||||
Clone the ğecko repo and open a dart file (e.g. `lib/main.dart`). VSCode will suggest you to insall relevant extensions.
|
||||
|
||||
### Rust toolchain
|
||||
|
||||
After installing Rust with the standard [rustup install script](https://www.rust-lang.org/tools/install),
|
||||
follow the instructions to build Rust dependencies [in this separate README](./packages/dubp_rs/README.md).
|
||||
If you installed a 32bits VM, use the 32bits build command.
|
||||
|
||||
### Build the app
|
||||
|
||||
In a dart file (e.g. `lib/main.dart`), type the `F5` key to build the code. The app should open automatically in your VM which is running.
|
||||
|
|
|
@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
|
|||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
compileSdkVersion 30
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
|
@ -44,9 +44,9 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.example.gecko"
|
||||
applicationId "gecko.axiomteam.fr"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
targetSdkVersion 30
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
multiDexEnabled true
|
||||
|
|
|
@ -6,7 +6,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 9.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
55
deny.toml
55
deny.toml
|
@ -1,55 +0,0 @@
|
|||
[bans]
|
||||
multiple-versions = "warn"
|
||||
deny = [
|
||||
# color-backtrace is nice but brings in too many dependencies and that are often outdated, so not worth it for us.
|
||||
{ name = "color-backtrace" },
|
||||
|
||||
# deprecated
|
||||
{ name = "quickersort" },
|
||||
|
||||
# term is not fully maintained, and termcolor is replacing it
|
||||
{ name = "term" },
|
||||
]
|
||||
skip-tree = [
|
||||
{ name = "winapi", version = "<= 0.3" },
|
||||
]
|
||||
|
||||
[licenses]
|
||||
unlicensed = "deny"
|
||||
# We want really high confidence when inferring licenses from text
|
||||
confidence-threshold = 0.8
|
||||
allow = [
|
||||
"AGPL-3.0",
|
||||
"Apache-2.0",
|
||||
"BSD-2-Clause",
|
||||
"BSD-3-Clause",
|
||||
"CC0-1.0",
|
||||
"ISC",
|
||||
"MIT",
|
||||
"MPL-2.0",
|
||||
"OpenSSL",
|
||||
"Zlib"
|
||||
]
|
||||
|
||||
[[licenses.clarify]]
|
||||
name = "ring"
|
||||
# SPDX considers OpenSSL to encompass both the OpenSSL and SSLeay licenses
|
||||
# https://spdx.org/licenses/OpenSSL.html
|
||||
# ISC - Both BoringSSL and ring use this for their new files
|
||||
# MIT - "Files in third_party/ have their own licenses, as described therein. The MIT
|
||||
# license, for third_party/fiat, which, unlike other third_party directories, is
|
||||
# compiled into non-test libraries, is included below."
|
||||
# OpenSSL - Obviously
|
||||
expression = "ISC AND MIT AND OpenSSL"
|
||||
license-files = [
|
||||
{ path = "LICENSE", hash = 0xbd0eed23 },
|
||||
]
|
||||
|
||||
[sources]
|
||||
unknown-registry = "deny"
|
||||
unknown-git = "deny"
|
||||
allow-git = [
|
||||
"https://git.duniter.org/libs/dubp-rs-client-lib",
|
||||
"https://git.duniter.org/nodes/rust/modules/duniter-gva",
|
||||
"https://github.com/librelois/fast-threadpool"
|
||||
]
|
|
@ -8,23 +8,25 @@ import 'package:logger/logger.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
// Files paths
|
||||
Directory appPath;
|
||||
Directory? appPath;
|
||||
|
||||
String appVersion;
|
||||
SharedPreferences prefs;
|
||||
String endPointGVA;
|
||||
int ramSys;
|
||||
Box<WalletData> walletBox;
|
||||
Box<ChestData> chestBox;
|
||||
Box configBox;
|
||||
Box<G1WalletsList> g1WalletsBox;
|
||||
late String appVersion;
|
||||
late SharedPreferences prefs;
|
||||
late String endPointGVA;
|
||||
const int pinLength = 5;
|
||||
const String appLang = 'french';
|
||||
|
||||
late Box<WalletData> walletBox;
|
||||
late Box<ChestData> chestBox;
|
||||
late Box configBox;
|
||||
late Box<G1WalletsList> g1WalletsBox;
|
||||
|
||||
String cesiumPod = "https://g1.data.le-sou.org";
|
||||
// String cesiumPod = "https://g1.data.e-is.pro";
|
||||
|
||||
// Responsive ratios
|
||||
bool isTall;
|
||||
double ratio;
|
||||
late bool isTall;
|
||||
late double ratio;
|
||||
|
||||
// Logger
|
||||
var log = Logger();
|
||||
|
|
|
@ -19,18 +19,18 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/models/change_pin.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/providers/change_pin.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/chest_provider.dart';
|
||||
import 'package:gecko/providers/chest_provider.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/models/home.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/search.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/home.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/providers/search.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/screens/home.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/screens/myWallets/wallets_home.dart';
|
||||
|
@ -38,25 +38,29 @@ import 'package:gecko/screens/search.dart';
|
|||
import 'package:gecko/screens/search_result.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:responsive_framework/responsive_framework.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:window_size/window_size.dart';
|
||||
|
||||
const bool enableSentry = true;
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
||||
setWindowTitle('Ğecko');
|
||||
setWindowMinSize(const Size(400, 700));
|
||||
setWindowMaxSize(const Size(800, 1000));
|
||||
}
|
||||
|
||||
HomeProvider _homeProvider = HomeProvider();
|
||||
appPath = await getApplicationDocumentsDirectory();
|
||||
await _homeProvider.initHive();
|
||||
appVersion = await _homeProvider.getAppVersion();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
// Configure Hive and open boxes
|
||||
await Hive.initFlutter(appPath.path);
|
||||
Hive.registerAdapter(WalletDataAdapter());
|
||||
Hive.registerAdapter(ChestDataAdapter());
|
||||
Hive.registerAdapter(G1WalletsListAdapter());
|
||||
|
@ -120,14 +124,14 @@ Future<void> main() async {
|
|||
}
|
||||
|
||||
class Gecko extends StatelessWidget {
|
||||
const Gecko(this.randomEndpoint, {Key key}) : super(key: key);
|
||||
final String randomEndpoint;
|
||||
const Gecko(this.randomEndpoint, {Key? key}) : super(key: key);
|
||||
final String? randomEndpoint;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
final _httpLink = HttpLink(
|
||||
randomEndpoint,
|
||||
randomEndpoint!,
|
||||
);
|
||||
|
||||
final _client = ValueNotifier(
|
||||
|
@ -156,7 +160,7 @@ class Gecko extends StatelessWidget {
|
|||
client: _client,
|
||||
child: MaterialApp(
|
||||
builder: (context, widget) => ResponsiveWrapper.builder(
|
||||
BouncingScrollWrapper.builder(context, widget),
|
||||
BouncingScrollWrapper.builder(context, widget!),
|
||||
maxWidth: 1200,
|
||||
minWidth: 480,
|
||||
defaultScale: true,
|
||||
|
@ -185,7 +189,7 @@ class Gecko extends StatelessWidget {
|
|||
home: const HomeScreen(),
|
||||
initialRoute: "/",
|
||||
routes: {
|
||||
'/mywallets': (context) => WalletsHome(),
|
||||
'/mywallets': (context) => const WalletsHome(),
|
||||
'/search': (context) => const SearchScreen(),
|
||||
'/searchResult': (context) => const SearchResultScreen(),
|
||||
},
|
||||
|
@ -198,7 +202,7 @@ class Gecko extends StatelessWidget {
|
|||
// This http overriding is needed to fix fail certifcat checking for Duniter node on old Android version
|
||||
class MyHttpOverrides extends HttpOverrides {
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext context) {
|
||||
HttpClient createHttpClient(SecurityContext? context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback =
|
||||
(X509Certificate cert, String host, int port) => true;
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import 'package:dubp/dubp.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
||||
class ChangePinProvider with ChangeNotifier {
|
||||
bool ischangedPin = false;
|
||||
TextEditingController newPin = TextEditingController();
|
||||
String pinToGive;
|
||||
|
||||
Future<NewWallet> get badWallet => null;
|
||||
|
||||
Future<NewWallet> changePin(String _oldPin) async {
|
||||
try {
|
||||
final _dewif = chestBox.get(configBox.get('currentChest')).dewif;
|
||||
|
||||
NewWallet newWalletFile = await DubpRust.changeDewifPin(
|
||||
dewif: _dewif,
|
||||
oldPin: _oldPin.toUpperCase(),
|
||||
);
|
||||
|
||||
newPin.text = pinToGive = newWalletFile.pin;
|
||||
ischangedPin = true;
|
||||
notifyListeners();
|
||||
return newWalletFile;
|
||||
} catch (e) {
|
||||
log.e('Impossible de changer le code PIN.');
|
||||
return badWallet;
|
||||
}
|
||||
}
|
||||
|
||||
void storeNewPinChest(context, NewWallet _newWalletFile) {
|
||||
// ChestData currentChest = chestBox.getAt(configBox.get('currentChest'));
|
||||
// currentChest.dewif = _newWalletFile.dewif;
|
||||
// await chestBox.add(currentChest);
|
||||
|
||||
chestBox.get(configBox.get('currentChest')).dewif = _newWalletFile.dewif;
|
||||
|
||||
Navigator.pop(context, pinToGive);
|
||||
pinToGive = '';
|
||||
}
|
||||
}
|
|
@ -7,22 +7,22 @@ part 'chest_data.g.dart';
|
|||
@HiveType(typeId: 1)
|
||||
class ChestData extends HiveObject {
|
||||
@HiveField(0)
|
||||
String dewif;
|
||||
String? dewif;
|
||||
|
||||
@HiveField(2)
|
||||
String name;
|
||||
String? name;
|
||||
|
||||
@HiveField(3)
|
||||
int defaultWallet;
|
||||
int? defaultWallet;
|
||||
|
||||
@HiveField(4)
|
||||
String imageName;
|
||||
String? imageName;
|
||||
|
||||
@HiveField(5)
|
||||
File imageFile;
|
||||
File? imageFile;
|
||||
|
||||
@HiveField(6)
|
||||
bool isCesium;
|
||||
bool? isCesium;
|
||||
|
||||
ChestData({
|
||||
this.dewif,
|
||||
|
@ -35,6 +35,6 @@ class ChestData extends HiveObject {
|
|||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
return name!;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ class ChestDataAdapter extends TypeAdapter<ChestData> {
|
|||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ChestData(
|
||||
dewif: fields[0] as String,
|
||||
name: fields[2] as String,
|
||||
defaultWallet: fields[3] as int,
|
||||
imageName: fields[4] as String,
|
||||
imageFile: fields[5] as File,
|
||||
isCesium: fields[6] as bool,
|
||||
dewif: fields[0] as String?,
|
||||
name: fields[2] as String?,
|
||||
defaultWallet: fields[3] as int?,
|
||||
imageName: fields[4] as String?,
|
||||
imageFile: fields[5] as File?,
|
||||
isCesium: fields[6] as bool?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,25 +6,25 @@ part 'g1_wallets_list.g.dart';
|
|||
@HiveType(typeId: 2)
|
||||
class G1WalletsList {
|
||||
@HiveField(0)
|
||||
String pubkey;
|
||||
String? pubkey;
|
||||
|
||||
@HiveField(1)
|
||||
double balance;
|
||||
double? balance;
|
||||
|
||||
@HiveField(3)
|
||||
Id id;
|
||||
Id? id;
|
||||
|
||||
@HiveField(4)
|
||||
Image avatar;
|
||||
Image? avatar;
|
||||
|
||||
@HiveField(5)
|
||||
String username;
|
||||
String? username;
|
||||
|
||||
@HiveField(6)
|
||||
String csName;
|
||||
String? csName;
|
||||
|
||||
@HiveField(7)
|
||||
bool isMembre;
|
||||
bool? isMembre;
|
||||
|
||||
G1WalletsList({
|
||||
this.pubkey,
|
||||
|
@ -47,7 +47,7 @@ class G1WalletsList {
|
|||
data['pubkey'] = pubkey;
|
||||
data['balance'] = balance;
|
||||
if (id != null) {
|
||||
data['id'] = id.toJson();
|
||||
data['id'] = id!.toJson();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ class G1WalletsList {
|
|||
|
||||
@HiveType(typeId: 3)
|
||||
class Id {
|
||||
bool isMember;
|
||||
String username;
|
||||
bool? isMember;
|
||||
String? username;
|
||||
|
||||
Id({this.isMember, this.username});
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ class G1WalletsListAdapter extends TypeAdapter<G1WalletsList> {
|
|||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return G1WalletsList(
|
||||
pubkey: fields[0] as String,
|
||||
balance: fields[1] as double,
|
||||
id: fields[3] as Id,
|
||||
avatar: fields[4] as Image,
|
||||
username: fields[5] as String,
|
||||
csName: fields[6] as String,
|
||||
isMembre: fields[7] as bool,
|
||||
pubkey: fields[0] as String?,
|
||||
balance: fields[1] as double?,
|
||||
id: fields[3] as Id?,
|
||||
avatar: fields[4] as Image?,
|
||||
username: fields[5] as String?,
|
||||
csName: fields[6] as String?,
|
||||
isMembre: fields[7] as bool?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,22 +7,22 @@ part 'wallet_data.g.dart';
|
|||
@HiveType(typeId: 0)
|
||||
class WalletData extends HiveObject {
|
||||
@HiveField(0)
|
||||
int chest;
|
||||
int? chest;
|
||||
|
||||
@HiveField(1)
|
||||
int number;
|
||||
int? number;
|
||||
|
||||
@HiveField(2)
|
||||
String name;
|
||||
String? name;
|
||||
|
||||
@HiveField(3)
|
||||
int derivation;
|
||||
int? derivation;
|
||||
|
||||
@HiveField(4)
|
||||
String imageName;
|
||||
String? imageName;
|
||||
|
||||
@HiveField(5)
|
||||
File imageFile;
|
||||
File? imageFile;
|
||||
|
||||
WalletData(
|
||||
{this.chest,
|
||||
|
@ -35,7 +35,7 @@ class WalletData extends HiveObject {
|
|||
// representation of WalletData when debugging
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
return name!;
|
||||
}
|
||||
|
||||
// creates the ':'-separated string from the WalletData
|
||||
|
@ -44,7 +44,7 @@ class WalletData extends HiveObject {
|
|||
}
|
||||
|
||||
// returns only the id part of the ':'-separated string
|
||||
List<int> id() {
|
||||
List<int?> id() {
|
||||
return [chest, number];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ class WalletDataAdapter extends TypeAdapter<WalletData> {
|
|||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return WalletData(
|
||||
chest: fields[0] as int,
|
||||
number: fields[1] as int,
|
||||
name: fields[2] as String,
|
||||
derivation: fields[3] as int,
|
||||
imageName: fields[4] as String,
|
||||
imageFile: fields[5] as File,
|
||||
chest: fields[0] as int?,
|
||||
number: fields[1] as int?,
|
||||
name: fields[2] as String?,
|
||||
derivation: fields[3] as int?,
|
||||
imageName: fields[4] as String?,
|
||||
imageFile: fields[5] as File?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'package:path_provider/path_provider.dart';
|
|||
|
||||
class CesiumPlusProvider with ChangeNotifier {
|
||||
TextEditingController cesiumName = TextEditingController();
|
||||
Image defaultAvatar(double size) =>
|
||||
Image defaultAvatar(double? size) =>
|
||||
Image.asset(('assets/icon_user.png'), height: size);
|
||||
|
||||
CancelToken avatarCancelToken = CancelToken();
|
||||
|
@ -60,17 +60,17 @@ class CesiumPlusProvider with ChangeNotifier {
|
|||
return [podRequest, queryGetAvatar, headers];
|
||||
}
|
||||
|
||||
Future<String> getName(String _pubkey) async {
|
||||
String _name;
|
||||
Future<String> getName(String? _pubkey) async {
|
||||
String? _name;
|
||||
|
||||
if (g1WalletsBox.get(_pubkey).csName != null) {
|
||||
return g1WalletsBox.get(_pubkey).csName;
|
||||
if (g1WalletsBox.get(_pubkey)!.csName != null) {
|
||||
return g1WalletsBox.get(_pubkey)!.csName!;
|
||||
}
|
||||
|
||||
List queryOptions = await _buildQuery(_pubkey);
|
||||
|
||||
var dio = Dio();
|
||||
Response response;
|
||||
late Response response;
|
||||
try {
|
||||
response = await dio.post(
|
||||
queryOptions[0],
|
||||
|
@ -97,14 +97,15 @@ class CesiumPlusProvider with ChangeNotifier {
|
|||
}
|
||||
_name = response.data['hits']['hits'][0]['_source']['title'];
|
||||
|
||||
g1WalletsBox.get(_pubkey).csName = _name;
|
||||
_name ??= '';
|
||||
g1WalletsBox.get(_pubkey)!.csName = _name;
|
||||
|
||||
return _name;
|
||||
}
|
||||
|
||||
Future<Image> getAvatar(String _pubkey, double size) async {
|
||||
if (g1WalletsBox.get(_pubkey).avatar != null) {
|
||||
return g1WalletsBox.get(_pubkey).avatar;
|
||||
Future<Image?> getAvatar(String? _pubkey, double size) async {
|
||||
if (g1WalletsBox.get(_pubkey)?.avatar != null) {
|
||||
return g1WalletsBox.get(_pubkey)!.avatar;
|
||||
}
|
||||
var dio = Dio();
|
||||
|
||||
|
@ -112,7 +113,7 @@ class CesiumPlusProvider with ChangeNotifier {
|
|||
|
||||
List queryOptions = await _buildQuery(_pubkey);
|
||||
|
||||
Response response;
|
||||
late Response response;
|
||||
try {
|
||||
response = await dio
|
||||
.post(queryOptions[0],
|
||||
|
@ -150,7 +151,7 @@ class CesiumPlusProvider with ChangeNotifier {
|
|||
fit: BoxFit.fitWidth,
|
||||
);
|
||||
|
||||
g1WalletsBox.get(_pubkey).avatar = finalAvatar;
|
||||
g1WalletsBox.get(_pubkey)!.avatar = finalAvatar;
|
||||
|
||||
return finalAvatar;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
||||
class ChangePinProvider with ChangeNotifier {
|
||||
bool ischangedPin = false;
|
||||
TextEditingController newPin = TextEditingController();
|
||||
String? pinToGive;
|
||||
|
||||
NewWallet? get badWallet => null;
|
||||
|
||||
Future<NewWallet?> changePin(String _oldPin, {String? newCustomPin}) async {
|
||||
final NewWallet newWalletFile;
|
||||
try {
|
||||
final _chest = chestBox.get(configBox.get('currentChest'))!;
|
||||
|
||||
if (_chest.isCesium!) {
|
||||
newWalletFile = await Dewif().changeCesiumPassword(
|
||||
dewif: _chest.dewif!,
|
||||
oldPassword: _oldPin.toUpperCase(),
|
||||
newPassword: newCustomPin);
|
||||
} else {
|
||||
newWalletFile = await Dewif().changePassword(
|
||||
dewif: _chest.dewif!,
|
||||
oldPassword: _oldPin.toUpperCase(),
|
||||
newPassword: newCustomPin);
|
||||
}
|
||||
newPin.text = pinToGive = newWalletFile.password;
|
||||
ischangedPin = true;
|
||||
// notifyListeners();
|
||||
return newWalletFile;
|
||||
} catch (e) {
|
||||
log.e('Impossible de changer le code PIN: $e');
|
||||
return badWallet;
|
||||
}
|
||||
}
|
||||
|
||||
void storeNewPinChest(context, NewWallet _newWalletFile) {
|
||||
// ChestData currentChest = chestBox.getAt(configBox.get('currentChest'));
|
||||
// currentChest.dewif = _newWalletFile.dewif;
|
||||
// await chestBox.add(currentChest);
|
||||
|
||||
chestBox.get(configBox.get('currentChest'))!.dewif = _newWalletFile.dewif;
|
||||
|
||||
Navigator.pop(context, pinToGive);
|
||||
pinToGive = '';
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
|
@ -8,14 +9,14 @@ class ChestProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
Future deleteChest(context, ChestData _chest) async {
|
||||
final bool _answer = await _confirmDeletingChest(context, _chest.name);
|
||||
final bool? _answer = await (_confirmDeletingChest(context, _chest.name));
|
||||
|
||||
if (_answer) {
|
||||
if (_answer!) {
|
||||
await chestBox.delete(_chest.key);
|
||||
if (chestBox.isEmpty) {
|
||||
await configBox.put('currentChest', 0);
|
||||
} else {
|
||||
int lastChest = chestBox.toMap().keys.first;
|
||||
int? lastChest = chestBox.toMap().keys.first;
|
||||
await configBox.put('currentChest', lastChest);
|
||||
}
|
||||
|
||||
|
@ -27,7 +28,7 @@ class ChestProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _confirmDeletingChest(context, String _walletName) async {
|
||||
Future<bool?> _confirmDeletingChest(context, String? _walletName) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
@ -15,16 +15,16 @@ import "package:unorm_dart/unorm_dart.dart" as unorm;
|
|||
class GenerateWalletsProvider with ChangeNotifier {
|
||||
GenerateWalletsProvider();
|
||||
// NewWallet generatedWallet;
|
||||
NewWallet actualWallet;
|
||||
NewWallet? actualWallet;
|
||||
|
||||
FocusNode walletNameFocus = FocusNode();
|
||||
Color askedWordColor = Colors.black;
|
||||
Color? askedWordColor = Colors.black;
|
||||
bool isAskedWordValid = false;
|
||||
|
||||
int nbrWord;
|
||||
String nbrWordAlpha;
|
||||
late int nbrWord;
|
||||
String? nbrWordAlpha;
|
||||
|
||||
String generatedMnemonic;
|
||||
String? generatedMnemonic;
|
||||
bool walletIsGenerated = true;
|
||||
|
||||
TextEditingController mnemonicController = TextEditingController();
|
||||
|
@ -37,7 +37,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
bool isCesiumIDVisible = false;
|
||||
bool isCesiumPWDVisible = false;
|
||||
bool canImport = false;
|
||||
bool isPinChanged = false;
|
||||
late CesiumWallet cesiumWallet;
|
||||
|
||||
// Import Chest
|
||||
TextEditingController cellController0 = TextEditingController();
|
||||
|
@ -58,7 +58,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
NewWallet _wallet, String _name, BuildContext context) async {
|
||||
int chestNumber = 0;
|
||||
chestBox.toMap().forEach((key, value) {
|
||||
if (!value.isCesium) {
|
||||
if (!value.isCesium!) {
|
||||
chestNumber++;
|
||||
}
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
isCesium: false,
|
||||
);
|
||||
await chestBox.add(thisChest);
|
||||
int chestKey = chestBox.keys.last;
|
||||
int? chestKey = chestBox.keys.last;
|
||||
|
||||
WalletData myWallet = WalletData(
|
||||
chest: chestKey,
|
||||
|
@ -128,7 +128,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
return rng.nextInt(12);
|
||||
}
|
||||
|
||||
String intToString(int _nbr) {
|
||||
String? intToString(int _nbr) {
|
||||
Map nbrToString = {};
|
||||
nbrToString[1] = 'Premier';
|
||||
nbrToString[2] = 'Deuxième';
|
||||
|
@ -152,53 +152,34 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<String> generateMnemonic() async {
|
||||
Future<NewWallet?> generateWallet(String generatedMnemonic,
|
||||
{required bool isImport}) async {
|
||||
try {
|
||||
generatedMnemonic = await DubpRust.genMnemonic(language: Language.french);
|
||||
actualWallet = await generateWallet(generatedMnemonic, isImport: false);
|
||||
walletIsGenerated = true;
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
}
|
||||
return generatedMnemonic;
|
||||
}
|
||||
|
||||
Future<NewWallet> generateWallet(String generatedMnemonic,
|
||||
{@required bool isImport}) async {
|
||||
try {
|
||||
actualWallet = await DubpRust.genWalletFromMnemonic(
|
||||
language: Language.french,
|
||||
mnemonic: generatedMnemonic,
|
||||
secretCodeType: SecretCodeType.letters,
|
||||
);
|
||||
actualWallet = await Dewif().generateDewif(
|
||||
generatedMnemonic, randomSecretCode(pinLength),
|
||||
lang: appLang);
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
}
|
||||
|
||||
if (!isImport) {
|
||||
mnemonicController.text = generatedMnemonic;
|
||||
pin.text = actualWallet.pin;
|
||||
pin.text = actualWallet!.password;
|
||||
}
|
||||
// notifyListeners();
|
||||
|
||||
return actualWallet;
|
||||
}
|
||||
|
||||
Future<NewWallet> changePinCode({bool reload}) async {
|
||||
actualWallet = await DubpRust.changeDewifPin(
|
||||
dewif: actualWallet.dewif,
|
||||
oldPin: actualWallet.pin,
|
||||
);
|
||||
|
||||
pin.text = actualWallet.pin;
|
||||
isPinChanged = true;
|
||||
String changePinCode({required bool reload}) {
|
||||
pin.text = randomSecretCode(pinLength);
|
||||
if (reload) {
|
||||
notifyListeners();
|
||||
}
|
||||
return actualWallet;
|
||||
return pin.text;
|
||||
}
|
||||
|
||||
Future<Uint8List> printWallet(String _title) async {
|
||||
Future<Uint8List> printWallet(String? _title) async {
|
||||
final ByteData fontData =
|
||||
await rootBundle.load("assets/OpenSans-Regular.ttf");
|
||||
final pw.Font ttf = pw.Font.ttf(fontData.buffer.asByteData());
|
||||
|
@ -216,7 +197,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
pw.Text("Phrase de restauration:",
|
||||
style: pw.TextStyle(fontSize: 20, font: ttf)),
|
||||
pw.SizedBox(height: 10),
|
||||
pw.Text(_title,
|
||||
pw.Text(_title!,
|
||||
style: pw.TextStyle(fontSize: 15, font: ttf),
|
||||
textAlign: pw.TextAlign.center),
|
||||
pw.Expanded(
|
||||
|
@ -238,18 +219,14 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
|
||||
Future<void> generateCesiumWalletPubkey(
|
||||
String _cesiumID, String _cesiumPWD) async {
|
||||
actualWallet = await DubpRust.genWalletFromDeprecatedSaltPassword(
|
||||
salt: _cesiumID, password: _cesiumPWD);
|
||||
String _walletPubkey = await DubpRust.getLegacyPublicKey(
|
||||
salt: _cesiumID, password: _cesiumPWD);
|
||||
cesiumWallet = CesiumWallet(_cesiumID, _cesiumPWD);
|
||||
String _walletPubkey = cesiumWallet.pubkey;
|
||||
|
||||
cesiumPubkey.text = _walletPubkey;
|
||||
pin.text = actualWallet.pin;
|
||||
isPinChanged = true;
|
||||
log.d(_walletPubkey);
|
||||
}
|
||||
|
||||
Future importCesiumWallet() async {
|
||||
Future<int?> importCesiumWallet() async {
|
||||
// String _walletPubkey = await DubpRust.getLegacyPublicKey(
|
||||
// salt: _cesiumID, password: _cesiumPWD);
|
||||
// String shortPubkey = truncate(_walletPubkey, 9,
|
||||
|
@ -262,14 +239,12 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
cesiumPWD.text = '';
|
||||
cesiumPubkey.text = '';
|
||||
canImport = false;
|
||||
isPinChanged = false;
|
||||
pin.text = '';
|
||||
isCesiumIDVisible = false;
|
||||
isCesiumPWDVisible = false;
|
||||
|
||||
int chestNumber = 0;
|
||||
chestBox.toMap().forEach((key, value) {
|
||||
if (value.isCesium) {
|
||||
if (value.isCesium!) {
|
||||
chestNumber++;
|
||||
}
|
||||
});
|
||||
|
@ -281,19 +256,24 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
chestName = 'Coffre à Césium ${chestNumber + 1}';
|
||||
}
|
||||
|
||||
log.d(pin.text);
|
||||
NewWallet cesiumDewif =
|
||||
await Dewif().generateCesiumDewif(cesiumWallet.seed, pin.text);
|
||||
|
||||
ChestData cesiumChest = ChestData(
|
||||
dewif: actualWallet.dewif,
|
||||
dewif: cesiumDewif.dewif,
|
||||
name: chestName,
|
||||
imageName: 'cesium.png',
|
||||
defaultWallet: 0,
|
||||
isCesium: true);
|
||||
|
||||
await chestBox.add(cesiumChest).then((value) => null);
|
||||
int chestKey = await chestBox.toMap().keys.last;
|
||||
int? chestKey = await chestBox.toMap().keys.last;
|
||||
// chestBox.toMap().
|
||||
await configBox.put('currentChest', chestKey);
|
||||
|
||||
notifyListeners();
|
||||
pin.text = '';
|
||||
return chestKey;
|
||||
}
|
||||
|
||||
void cesiumIDisVisible() {
|
||||
|
@ -308,18 +288,18 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
|
||||
void resetCesiumImportView() {
|
||||
cesiumID.text = cesiumPWD.text = cesiumPubkey.text = pin.text = '';
|
||||
canImport = isPinChanged = isCesiumIDVisible = isCesiumPWDVisible = false;
|
||||
canImport = isCesiumIDVisible = isCesiumPWDVisible = false;
|
||||
actualWallet = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<List<String>> generateWordList() async {
|
||||
final String _sentance = await generateMnemonic();
|
||||
List<String> generateWordList() {
|
||||
generatedMnemonic = generateMnemonic(lang: appLang);
|
||||
List<String> _wordsList = [];
|
||||
String word;
|
||||
int _nbr = 1;
|
||||
|
||||
for (word in _sentance.split(' ')) {
|
||||
for (word in generatedMnemonic!.split(' ')) {
|
||||
_wordsList.add("$_nbr:$word");
|
||||
_nbr++;
|
||||
}
|
||||
|
@ -336,7 +316,7 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
return bip39Words.contains(word);
|
||||
}
|
||||
|
||||
bool isBipWordsList(List words) {
|
||||
bool isBipWordsList(List<String> words) {
|
||||
bool isValid = true;
|
||||
for (String word in words) {
|
||||
// Needed for bad encoding of UTF-8
|
||||
|
@ -353,8 +333,8 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
cellController0.text = cellController1.text = cellController2.text =
|
||||
cellController3.text = cellController4.text = cellController5.text =
|
||||
cellController6.text = cellController7.text = cellController8.text =
|
||||
cellController9.text =
|
||||
cellController10.text = cellController11.text = '';
|
||||
cellController9.text = cellController10.text =
|
||||
cellController11.text = '';
|
||||
isFirstTimeSentenceComplete = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -394,12 +374,13 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
inputMnemonic = inputMnemonic.replaceAll('é', 'é');
|
||||
inputMnemonic = inputMnemonic.replaceAll('è', 'è');
|
||||
|
||||
NewWallet generatedWallet =
|
||||
NewWallet? generatedWallet =
|
||||
await generateWallet(inputMnemonic, isImport: true);
|
||||
|
||||
if (generatedWallet == null) {
|
||||
return false;
|
||||
} else {
|
||||
generatedMnemonic = inputMnemonic;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -7,54 +7,64 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/screens/old_history_pay.dart';
|
||||
import 'package:gecko/screens/myWallets/wallets_home.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:path_provider/path_provider.dart' as pp;
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
class HomeProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
bool isSearching;
|
||||
bool? isSearching;
|
||||
Icon searchIcon = const Icon(Icons.search);
|
||||
final TextEditingController searchQuery = TextEditingController();
|
||||
Widget appBarTitle = Text('Ğecko', style: TextStyle(color: Colors.grey[850]));
|
||||
Widget appBarExplorer =
|
||||
Text('Explorateur', style: TextStyle(color: Colors.grey[850]));
|
||||
|
||||
List currentTab = [OldHistoryScreen(), WalletsHome()];
|
||||
bool isFirstBuild = true;
|
||||
// AudioCache player = AudioCache(prefix: 'sounds/');
|
||||
|
||||
get currentIndex => _currentIndex;
|
||||
Future<void> initHive() async {
|
||||
late Directory hivePath;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
if (!kIsWeb) {
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
final home = Platform.environment['HOME'];
|
||||
hivePath = Directory('$home/.gecko/db');
|
||||
} else if (Platform.isWindows) {
|
||||
final home = Platform.environment['UserProfile'];
|
||||
hivePath = Directory('$home/.gecko/db');
|
||||
} else if (Platform.isAndroid || Platform.isIOS) {
|
||||
final home = await pp.getApplicationDocumentsDirectory();
|
||||
hivePath = Directory('${home.path}/db');
|
||||
}
|
||||
if (!await hivePath.exists()) {
|
||||
await hivePath.create(recursive: true);
|
||||
}
|
||||
await Hive.initFlutter(hivePath.path);
|
||||
} else {
|
||||
await Hive.initFlutter();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getAppVersion() async {
|
||||
String version;
|
||||
String buildNumber;
|
||||
if (Platform.isLinux) {
|
||||
version = "undefined";
|
||||
buildNumber = "undefined";
|
||||
} else {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
version = packageInfo.version;
|
||||
buildNumber = packageInfo.buildNumber;
|
||||
}
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
version = packageInfo.version;
|
||||
buildNumber = packageInfo.buildNumber;
|
||||
|
||||
notifyListeners();
|
||||
return version + '+' + buildNumber;
|
||||
}
|
||||
|
||||
Future<String> getValidEndpoint() async {
|
||||
Future<String?> getValidEndpoint() async {
|
||||
List _listEndpoints = await rootBundle
|
||||
.loadString('config/gva_endpoints.json')
|
||||
.then((jsonStr) => jsonDecode(jsonStr));
|
||||
_listEndpoints.shuffle();
|
||||
|
||||
int i = 0;
|
||||
String _endpoint;
|
||||
String? _endpoint;
|
||||
int _statusCode = 0;
|
||||
|
||||
final _client = HttpClient();
|
||||
|
@ -95,7 +105,7 @@ class HomeProvider with ChangeNotifier {
|
|||
}
|
||||
} while (_statusCode != 400);
|
||||
|
||||
log.i('ENDPOINT: ' + _endpoint);
|
||||
log.i('ENDPOINT: ' + _endpoint!);
|
||||
return _endpoint;
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
@ -5,10 +8,12 @@ import 'package:gecko/models/wallet_data.dart';
|
|||
|
||||
class MyWalletsProvider with ChangeNotifier {
|
||||
List<WalletData> listWallets = [];
|
||||
String pinCode;
|
||||
int pinLenght;
|
||||
late String pinCode;
|
||||
late String mnemonic;
|
||||
late Uint8List cesiumSeed;
|
||||
int? pinLenght;
|
||||
|
||||
int getCurrentChest() {
|
||||
int? getCurrentChest() {
|
||||
if (configBox.get('currentChest') == null) {
|
||||
configBox.put('currentChest', 0);
|
||||
}
|
||||
|
@ -16,6 +21,24 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
return configBox.get('currentChest');
|
||||
}
|
||||
|
||||
String dewifToMnemonic(context, WalletData _wallet, String _pin) {
|
||||
String _mnemonic;
|
||||
|
||||
try {
|
||||
String _localDewif = chestBox.get(_wallet.chest)!.dewif!;
|
||||
_mnemonic = Dewif()
|
||||
.mnemonicFromDewif(_localDewif, _pin.toUpperCase(), lang: appLang);
|
||||
} on ChecksumException catch (e) {
|
||||
log.e(e.cause);
|
||||
return 'bad';
|
||||
} catch (e) {
|
||||
// _homeProvider.playSound('non', 0.6);
|
||||
log.e('ERROR READING FILE: $e');
|
||||
return 'bad';
|
||||
}
|
||||
return _mnemonic;
|
||||
}
|
||||
|
||||
bool checkIfWalletExist() {
|
||||
if (chestBox.isEmpty) {
|
||||
log.i('No wallets detected');
|
||||
|
@ -25,7 +48,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
List<WalletData> readAllWallets(int _chest) {
|
||||
List<WalletData> readAllWallets(int? _chest) {
|
||||
listWallets.clear();
|
||||
walletBox.toMap().forEach((key, value) {
|
||||
if (value.chest == _chest) {
|
||||
|
@ -36,11 +59,11 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
return listWallets;
|
||||
}
|
||||
|
||||
WalletData getWalletData(List<int> _id) {
|
||||
WalletData? getWalletData(List<int?> _id) {
|
||||
if (_id.isEmpty) return WalletData();
|
||||
int _chest = _id[0];
|
||||
int _nbr = _id[1];
|
||||
WalletData _targetedWallet;
|
||||
int? _chest = _id[0];
|
||||
int? _nbr = _id[1];
|
||||
WalletData? _targetedWallet;
|
||||
|
||||
walletBox.toMap().forEach((key, value) {
|
||||
if (value.chest == _chest && value.number == _nbr) {
|
||||
|
@ -52,11 +75,11 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
return _targetedWallet;
|
||||
}
|
||||
|
||||
WalletData getDefaultWallet(int chest) {
|
||||
WalletData? getDefaultWallet(int? chest) {
|
||||
if (chestBox.isEmpty) {
|
||||
return WalletData(chest: 0, number: 0);
|
||||
} else {
|
||||
int defaultWalletNumber = chestBox.get(chest).defaultWallet;
|
||||
int? defaultWalletNumber = chestBox.get(chest)!.defaultWallet;
|
||||
return getWalletData([chest, defaultWalletNumber]);
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +88,8 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
try {
|
||||
log.w('DELETE ALL WALLETS ?');
|
||||
|
||||
final bool _answer = await _confirmDeletingAllWallets(context);
|
||||
if (_answer) {
|
||||
final bool? _answer = await (_confirmDeletingAllWallets(context));
|
||||
if (_answer!) {
|
||||
await walletBox.clear();
|
||||
await chestBox.clear();
|
||||
await configBox.delete('defaultWallet');
|
||||
|
@ -84,7 +107,7 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _confirmDeletingAllWallets(context) async {
|
||||
Future<bool?> _confirmDeletingAllWallets(context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
||||
|
@ -116,15 +139,15 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
Future<void> generateNewDerivation(context, String _name) async {
|
||||
int _newDerivationNbr;
|
||||
int _newWalletNbr;
|
||||
int _chest = getCurrentChest();
|
||||
int? _chest = getCurrentChest();
|
||||
List<WalletData> _walletConfig = readAllWallets(_chest);
|
||||
|
||||
if (_walletConfig.isEmpty) {
|
||||
_newDerivationNbr = 3;
|
||||
_newWalletNbr = 0;
|
||||
} else {
|
||||
_newDerivationNbr = _walletConfig.last.derivation + 3;
|
||||
_newWalletNbr = _walletConfig.last.number + 1;
|
||||
_newDerivationNbr = _walletConfig.last.derivation! + 3;
|
||||
_newWalletNbr = _walletConfig.last.number! + 1;
|
||||
}
|
||||
|
||||
WalletData newWallet = WalletData(
|
|
@ -2,7 +2,7 @@ import 'package:dio/dio.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
|
||||
class SearchProvider with ChangeNotifier {
|
||||
TextEditingController searchController = TextEditingController();
|
||||
|
@ -25,7 +25,7 @@ class SearchProvider with ChangeNotifier {
|
|||
// final response = await http.get(url);
|
||||
|
||||
var dio = Dio();
|
||||
Response response;
|
||||
late Response response;
|
||||
try {
|
||||
response = await dio.get(
|
||||
'https://g1-stats.axiom-team.fr/data/forbes.json',
|
||||
|
@ -40,8 +40,8 @@ class SearchProvider with ChangeNotifier {
|
|||
log.e(e);
|
||||
}
|
||||
|
||||
List<G1WalletsList> _listWallets = _parseG1Wallets(response.data);
|
||||
Map<String, G1WalletsList> _mapWallets = {
|
||||
List<G1WalletsList> _listWallets = _parseG1Wallets(response.data)!;
|
||||
Map<String?, G1WalletsList> _mapWallets = {
|
||||
for (var e in _listWallets) e.pubkey: e
|
||||
};
|
||||
|
||||
|
@ -51,11 +51,11 @@ class SearchProvider with ChangeNotifier {
|
|||
|
||||
g1WalletsBox.toMap().forEach((key, value) {
|
||||
if ((value.id != null &&
|
||||
value.id.username != null &&
|
||||
value.id.username
|
||||
value.id!.username != null &&
|
||||
value.id!.username!
|
||||
.toLowerCase()
|
||||
.contains(searchController.text)) ||
|
||||
value.pubkey.contains(searchController.text)) {
|
||||
value.pubkey!.contains(searchController.text)) {
|
||||
searchResult.add(value);
|
||||
return;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class SearchProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
List<G1WalletsList> _parseG1Wallets(var responseBody) {
|
||||
List<G1WalletsList>? _parseG1Wallets(var responseBody) {
|
||||
final parsed = responseBody.cast<Map<String, dynamic>>();
|
||||
|
||||
return parsed
|
|
@ -1,18 +1,15 @@
|
|||
// import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:fast_base58/fast_base58.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:truncate/truncate.dart';
|
||||
import 'package:qrscan/qrscan.dart' as scanner;
|
||||
|
||||
class WalletOptionsProvider with ChangeNotifier {
|
||||
TextEditingController pubkey = TextEditingController();
|
||||
|
@ -24,13 +21,12 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
bool isBalanceBlur = true;
|
||||
FocusNode walletNameFocus = FocusNode();
|
||||
TextEditingController nameController = TextEditingController();
|
||||
bool isDefaultWallet;
|
||||
late bool isDefaultWallet;
|
||||
|
||||
Future<NewWallet> get badWallet => null;
|
||||
Future<NewWallet>? get badWallet => null;
|
||||
|
||||
Future _getPubkeyFromDewif(
|
||||
String _dewif, _pin, int _pinLenght, int derivation) async {
|
||||
String _pubkey;
|
||||
String _getPubkeyFromDewif(
|
||||
String? _dewif, _pin, int _pinLenght, int? derivation) {
|
||||
RegExp regExp = RegExp(
|
||||
r'^[A-Z0-9]+$',
|
||||
caseSensitive: false,
|
||||
|
@ -43,27 +39,25 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
if (derivation != -1) {
|
||||
try {
|
||||
List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys(
|
||||
dewif: _dewif, secretCode: _pin, accountsIndex: [derivation]);
|
||||
_pubkey = _pubkeysTmp[0];
|
||||
pubkey.text = _pubkey;
|
||||
final _wallet = HdWallet.fromDewif(_dewif!, _pin, lang: appLang);
|
||||
pubkey.text = _wallet.getPubkey(derivation!);
|
||||
log.d(pubkey.text);
|
||||
notifyListeners();
|
||||
|
||||
return _pubkey;
|
||||
return pubkey.text;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
log.w('Bad PIN code !\n' + e.toString());
|
||||
notifyListeners();
|
||||
|
||||
return 'false';
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
_pubkey = await DubpRust.getDewifPublicKey(dewif: _dewif, pin: _pin);
|
||||
pubkey.text = _pubkey;
|
||||
pubkey.text = CesiumWallet.fromDewif(_dewif!, _pin).pubkey;
|
||||
notifyListeners();
|
||||
return _pubkey;
|
||||
return pubkey.text;
|
||||
} catch (e) {
|
||||
log.w('Bad PIN code !\n' + e);
|
||||
log.w('Bad PIN code !\n' + e.toString());
|
||||
notifyListeners();
|
||||
|
||||
return 'false';
|
||||
|
@ -71,22 +65,34 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future readLocalWallet(
|
||||
context, WalletData _wallet, String _pin, int _pinLenght) async {
|
||||
String? readLocalWallet(
|
||||
context, WalletData _wallet, String _pin, int _pinLenght,
|
||||
{String? mnemonic}) {
|
||||
isWalletUnlock = false;
|
||||
try {
|
||||
String _localDewif = chestBox.get(_wallet.chest).dewif;
|
||||
String _localPubkey;
|
||||
final String _localPubkey;
|
||||
|
||||
if ((_localPubkey = await _getPubkeyFromDewif(
|
||||
_localDewif, _pin, _pinLenght, _wallet.derivation)) !=
|
||||
'false') {
|
||||
try {
|
||||
String? _localDewif = chestBox.get(_wallet.chest)!.dewif;
|
||||
|
||||
if (mnemonic == null) {
|
||||
_localPubkey = _getPubkeyFromDewif(
|
||||
_localDewif, _pin.toUpperCase(), _pinLenght, _wallet.derivation);
|
||||
} else {
|
||||
final _hdwallet = HdWallet.fromMnemonic(mnemonic);
|
||||
_localPubkey = _hdwallet.getPubkey(_wallet.derivation!);
|
||||
}
|
||||
|
||||
if (_localPubkey != 'false') {
|
||||
pubkey.text = _localPubkey;
|
||||
isWalletUnlock = true;
|
||||
log.d(pubkey.text);
|
||||
return _localDewif;
|
||||
} else {
|
||||
throw 'Bad pubkey';
|
||||
}
|
||||
} on ChecksumException catch (e) {
|
||||
log.e(e.cause);
|
||||
return 'bad';
|
||||
} catch (e) {
|
||||
// _homeProvider.playSound('non', 0.6);
|
||||
log.e('ERROR READING FILE: $e');
|
||||
|
@ -95,44 +101,36 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Future checkPinOK(String _createdDewif, String _pin, int _pinLenght) async {
|
||||
isWalletUnlock = false;
|
||||
try {
|
||||
if (await _getPubkeyFromDewif(_createdDewif, _pin, _pinLenght, 3) !=
|
||||
'false') {
|
||||
return true;
|
||||
} else {
|
||||
throw false;
|
||||
}
|
||||
} catch (e) {
|
||||
log.e('ERROR READING FILE: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int getPinLenght(_walletNbr) {
|
||||
String _localDewif;
|
||||
if (_walletNbr is int || _walletNbr == null) {
|
||||
_localDewif = chestBox.get(configBox.get('currentChest')).dewif;
|
||||
} else {
|
||||
_localDewif = _walletNbr;
|
||||
}
|
||||
// TODOo: Get real Dewif lenght
|
||||
// String _localDewif;
|
||||
// if (_walletNbr is int || _walletNbr == null) {
|
||||
// _localDewif = chestBox.get(configBox.get('currentChest')).dewif;
|
||||
// } else {
|
||||
// _localDewif = _walletNbr;
|
||||
// }
|
||||
|
||||
final int _pinLenght = DubpRust.getDewifSecretCodeLen(
|
||||
dewif: _localDewif, secretCodeType: SecretCodeType.letters);
|
||||
// final int _pinLenght = DubpRust.getDewifSecretCodeLen(
|
||||
// dewif: _localDewif, secretCodeType: SecretCodeType.letters);
|
||||
|
||||
return _pinLenght;
|
||||
return pinLength;
|
||||
}
|
||||
|
||||
void _renameWallet(List<int> _walletID, _newName, {bool isCesium}) async {
|
||||
Future<double> getBalance(String pubkey, {bool isUd = false}) async {
|
||||
final node = Gva(node: endPointGVA);
|
||||
return await node.balance(pubkey, ud: isUd);
|
||||
}
|
||||
|
||||
void _renameWallet(List<int?> _walletID, _newName,
|
||||
{required bool isCesium}) async {
|
||||
if (isCesium) {
|
||||
ChestData _chestTarget = chestBox.get(_walletID[0]);
|
||||
ChestData _chestTarget = chestBox.get(_walletID[0])!;
|
||||
_chestTarget.name = _newName;
|
||||
await chestBox.put(_chestTarget.key, _chestTarget);
|
||||
} else {
|
||||
MyWalletsProvider myWalletClass = MyWalletsProvider();
|
||||
|
||||
WalletData _walletTarget = myWalletClass.getWalletData(_walletID);
|
||||
WalletData _walletTarget = myWalletClass.getWalletData(_walletID)!;
|
||||
_walletTarget.name = _newName;
|
||||
await walletBox.put(_walletTarget.key, _walletTarget);
|
||||
}
|
||||
|
@ -140,12 +138,12 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
_newWalletName.text = '';
|
||||
}
|
||||
|
||||
bool editWalletName(List<int> _wID, {bool isCesium}) {
|
||||
bool editWalletName(List<int?> _wID, {bool? isCesium}) {
|
||||
bool nameState;
|
||||
if (isEditing) {
|
||||
if (!nameController.text.contains(':') &&
|
||||
nameController.text.length <= 39) {
|
||||
_renameWallet(_wID, nameController.text, isCesium: isCesium);
|
||||
_renameWallet(_wID, nameController.text, isCesium: isCesium!);
|
||||
nameState = true;
|
||||
} else {
|
||||
nameState = false;
|
||||
|
@ -160,9 +158,9 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
Future<int> deleteWallet(context, WalletData wallet) async {
|
||||
final bool _answer = await _confirmDeletingWallet(context, wallet.name);
|
||||
final bool? _answer = await (_confirmDeletingWallet(context, wallet.name));
|
||||
|
||||
if (_answer) {
|
||||
if (_answer!) {
|
||||
walletBox.delete(wallet.key);
|
||||
|
||||
Navigator.popUntil(
|
||||
|
@ -173,7 +171,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
return 0;
|
||||
}
|
||||
|
||||
Future<bool> _confirmDeletingWallet(context, _walletName) async {
|
||||
Future<bool?> _confirmDeletingWallet(context, _walletName) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
||||
|
@ -216,7 +214,6 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
String getShortPubkey(String pubkey) {
|
||||
log.d(pubkey);
|
||||
List<int> pubkeyByte = Base58Decode(pubkey);
|
||||
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
|
||||
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
|
||||
|
@ -237,15 +234,11 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<Uint8List> generateQRcode(String _pubkey) async {
|
||||
return await scanner.generateBarCode(_pubkey);
|
||||
}
|
||||
|
||||
Future changeAvatar() async {
|
||||
File _image;
|
||||
final picker = ImagePicker();
|
||||
|
||||
XFile pickedFile = await picker.pickImage(source: ImageSource.gallery);
|
||||
XFile? pickedFile = await picker.pickImage(source: ImageSource.gallery);
|
||||
|
||||
if (pickedFile != null) {
|
||||
_image = File(pickedFile.path);
|
|
@ -1,12 +1,14 @@
|
|||
import 'package:dubp/dubp.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:jdenticon_dart/jdenticon_dart.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qrscan/qrscan.dart' as scanner;
|
||||
import 'dart:math';
|
||||
import 'package:intl/intl.dart';
|
||||
|
@ -17,24 +19,26 @@ import 'package:fast_base58/fast_base58.dart';
|
|||
class WalletsProfilesProvider with ChangeNotifier {
|
||||
WalletsProfilesProvider(this.pubkey);
|
||||
|
||||
String pubkey = '';
|
||||
String? pubkey = '';
|
||||
String pubkeyShort = '';
|
||||
final TextEditingController outputPubkey = TextEditingController();
|
||||
List transBC;
|
||||
String fetchMoreCursor;
|
||||
Map pageInfo;
|
||||
List? transBC;
|
||||
String? fetchMoreCursor;
|
||||
Map? pageInfo;
|
||||
bool isHistoryScreen = false;
|
||||
String historySwitchButtun = "Voir l'historique";
|
||||
String rawSvg;
|
||||
String? rawSvg;
|
||||
TextEditingController payAmount = TextEditingController();
|
||||
TextEditingController payComment = TextEditingController();
|
||||
num balance;
|
||||
num? balance;
|
||||
int nRepositories = 20;
|
||||
int nPage = 1;
|
||||
|
||||
Future scan(context) async {
|
||||
await Permission.camera.request();
|
||||
String barcode;
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
await Permission.camera.request();
|
||||
}
|
||||
String? barcode;
|
||||
try {
|
||||
barcode = await scanner.scan();
|
||||
} catch (e) {
|
||||
|
@ -55,35 +59,33 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
return barcode;
|
||||
}
|
||||
|
||||
Future<String> pay(BuildContext context, String pinCode) async {
|
||||
MyWalletsProvider _myWalletModel = MyWalletsProvider();
|
||||
int currentChest = configBox.get('currentChest');
|
||||
WalletData defaultWallet = _myWalletModel.getDefaultWallet(currentChest);
|
||||
Future<String> pay(BuildContext context, {int? derivation}) async {
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
int? currentChest = configBox.get('currentChest');
|
||||
String result;
|
||||
|
||||
String dewif = chestBox.get(currentChest).dewif;
|
||||
int derivation;
|
||||
|
||||
if (chestBox.get(currentChest).isCesium) {
|
||||
derivation = 0;
|
||||
} else {
|
||||
derivation = defaultWallet.derivation;
|
||||
}
|
||||
|
||||
try {
|
||||
await DubpRust.simplePaymentFromTransparentAccount(
|
||||
accountIndex: derivation,
|
||||
if (chestBox.get(currentChest)!.isCesium!) {
|
||||
result = await Gva(node: endPointGVA).pay(
|
||||
recipient: pubkey!,
|
||||
amount: double.parse(payAmount.text),
|
||||
txComment: payComment.text,
|
||||
dewif: dewif,
|
||||
gvaEndpoint: endPointGVA,
|
||||
secretCode: pinCode,
|
||||
recipient: pubkey);
|
||||
return "Success";
|
||||
} catch (e) {
|
||||
log.e("ERROR DUBP PAYMENTS");
|
||||
log.e(e);
|
||||
return "Payments errors: $e";
|
||||
cesiumSeed: _myWalletProvider.cesiumSeed,
|
||||
comment: payComment.text,
|
||||
derivation: -1,
|
||||
lang: appLang);
|
||||
} else {
|
||||
derivation ??=
|
||||
_myWalletProvider.getDefaultWallet(currentChest)!.derivation!;
|
||||
result = await Gva(node: endPointGVA).pay(
|
||||
recipient: pubkey!,
|
||||
amount: double.parse(payAmount.text),
|
||||
mnemonic: _myWalletProvider.mnemonic,
|
||||
comment: payComment.text,
|
||||
derivation: derivation,
|
||||
lang: appLang);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isPubkey(pubkey) {
|
||||
|
@ -149,7 +151,7 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
for (final trans in txs) {
|
||||
var direction = trans['direction'];
|
||||
final transaction = trans['node'];
|
||||
String output;
|
||||
String? output;
|
||||
if (direction == "RECEIVED") {
|
||||
for (String line in transaction['outputs']) {
|
||||
if (line.contains(_pubkey)) {
|
||||
|
@ -196,14 +198,14 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
return transBC;
|
||||
}
|
||||
|
||||
FetchMoreOptions checkQueryResult(result, opts, _pubkey) {
|
||||
final List<dynamic> blockchainTX =
|
||||
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
|
||||
FetchMoreOptions? checkQueryResult(result, opts, _pubkey) {
|
||||
final List<dynamic>? blockchainTX =
|
||||
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>?);
|
||||
// final List<dynamic> mempoolTX =
|
||||
// (result.data['txsHistoryMp']['receiving'] as List<dynamic>);
|
||||
|
||||
pageInfo = result.data['txsHistoryBc']['both']['pageInfo'];
|
||||
fetchMoreCursor = pageInfo['endCursor'];
|
||||
fetchMoreCursor = pageInfo!['endCursor'];
|
||||
if (fetchMoreCursor == null) nPage = 1;
|
||||
|
||||
if (nPage == 1) {
|
||||
|
@ -211,8 +213,6 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
} else if (nPage == 2) {
|
||||
nRepositories = 100;
|
||||
}
|
||||
log.d(nPage);
|
||||
log.d(nRepositories);
|
||||
nPage++;
|
||||
|
||||
if (fetchMoreCursor != null) {
|
||||
|
@ -220,9 +220,9 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
variables: {'cursor': fetchMoreCursor, 'number': nRepositories},
|
||||
updateQuery: (previousResultData, fetchMoreResultData) {
|
||||
final List<dynamic> repos = [
|
||||
...previousResultData['txsHistoryBc']['both']['edges']
|
||||
...previousResultData!['txsHistoryBc']['both']['edges']
|
||||
as List<dynamic>,
|
||||
...fetchMoreResultData['txsHistoryBc']['both']['edges']
|
||||
...fetchMoreResultData!['txsHistoryBc']['both']['edges']
|
||||
as List<dynamic>
|
||||
];
|
||||
|
||||
|
@ -291,7 +291,7 @@ class WalletsProfilesProvider with ChangeNotifier {
|
|||
// return balance;
|
||||
// }
|
||||
|
||||
Future<num> getBalance(String _pubkey) async {
|
||||
Future<num?> getBalance(String? _pubkey) async {
|
||||
while (balance == null) {
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
}
|
|
@ -8,11 +8,11 @@ import 'package:flutter/material.dart';
|
|||
class AvatarFullscreen extends StatelessWidget {
|
||||
TextEditingController tplController = TextEditingController();
|
||||
|
||||
AvatarFullscreen(this.avatar, {this.title, this.color, Key key})
|
||||
AvatarFullscreen(this.avatar, {this.title, this.color, Key? key})
|
||||
: super(key: key);
|
||||
final Image avatar;
|
||||
final String title;
|
||||
final Color color;
|
||||
final Image? avatar;
|
||||
final String? title;
|
||||
final Color? color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -43,8 +43,8 @@ class AvatarFullscreen extends StatelessWidget {
|
|||
// height: MediaQuery.of(context).size.height,
|
||||
// width: MediaQuery.of(context).size.width,
|
||||
child: Image(
|
||||
image: avatar.image,
|
||||
height: avatar.height,
|
||||
image: avatar!.image,
|
||||
height: avatar!.height,
|
||||
fit: BoxFit.fitWidth),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -8,39 +8,46 @@ class CommonElements {
|
|||
return const Text('Coucou');
|
||||
}
|
||||
|
||||
Widget bubbleSpeak(String text, {double long, Key textKey}) {
|
||||
return Bubble(
|
||||
padding: long == null
|
||||
? const BubbleEdges.all(18)
|
||||
: BubbleEdges.symmetric(horizontal: long, vertical: 30),
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
margin: const BubbleEdges.fromLTRB(10, 0, 20, 10),
|
||||
// nip: BubbleNip.leftTop,
|
||||
child: Text(
|
||||
text,
|
||||
key: textKey,
|
||||
style: const TextStyle(
|
||||
color: Colors.black, fontSize: 18, fontWeight: FontWeight.w400),
|
||||
Widget bubbleSpeak(String text,
|
||||
{double? long, Key? textKey, bool isMaxWidth = true}) {
|
||||
return SizedBox(
|
||||
width: isMaxWidth ? double.infinity : 300,
|
||||
child: Bubble(
|
||||
padding: long == null
|
||||
? const BubbleEdges.all(18)
|
||||
: BubbleEdges.symmetric(horizontal: long, vertical: 30),
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
margin: const BubbleEdges.fromLTRB(10, 0, 20, 10),
|
||||
// nip: BubbleNip.leftTop,
|
||||
child: Text(
|
||||
text,
|
||||
key: textKey,
|
||||
style: const TextStyle(
|
||||
color: Colors.black, fontSize: 18, fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget bubbleSpeakRich(List<TextSpan> text, {Key textKey}) {
|
||||
return Bubble(
|
||||
padding: const BubbleEdges.all(18),
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
margin: const BubbleEdges.fromLTRB(10, 0, 20, 10),
|
||||
// nip: BubbleNip.leftTop,
|
||||
child: RichText(
|
||||
key: textKey,
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
fontSize: 18.0,
|
||||
color: Colors.black,
|
||||
Widget bubbleSpeakRich(List<TextSpan> text, {Key? textKey}) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Bubble(
|
||||
padding: const BubbleEdges.all(18),
|
||||
elevation: 5,
|
||||
color: Colors.white,
|
||||
margin: const BubbleEdges.fromLTRB(10, 0, 20, 10),
|
||||
// nip: BubbleNip.leftTop,
|
||||
child: RichText(
|
||||
key: textKey,
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
fontSize: 18.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
children: text,
|
||||
),
|
||||
children: text,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -130,7 +137,7 @@ class CommonElements {
|
|||
}
|
||||
|
||||
class SmoothTransition extends PageRouteBuilder {
|
||||
final Widget page;
|
||||
final Widget? page;
|
||||
SmoothTransition({this.page})
|
||||
: super(
|
||||
pageBuilder: (
|
||||
|
@ -141,8 +148,8 @@ class SmoothTransition extends PageRouteBuilder {
|
|||
TweenAnimationBuilder(
|
||||
duration: const Duration(seconds: 5),
|
||||
tween: Tween(begin: 200, end: 200),
|
||||
builder: (BuildContext context, dynamic value, Widget child) {
|
||||
return page;
|
||||
builder: (BuildContext context, dynamic value, Widget? child) {
|
||||
return page!;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -152,7 +159,7 @@ class FaderTransition extends PageRouteBuilder {
|
|||
final Widget page;
|
||||
final bool isFast;
|
||||
|
||||
FaderTransition({@required this.page, @required this.isFast})
|
||||
FaderTransition({required this.page, required this.isFast})
|
||||
: super(
|
||||
pageBuilder: (
|
||||
BuildContext context,
|
||||
|
@ -175,7 +182,7 @@ class FaderTransition extends PageRouteBuilder {
|
|||
}
|
||||
|
||||
class SlideLeftRoute extends PageRouteBuilder {
|
||||
final Widget page;
|
||||
final Widget? page;
|
||||
SlideLeftRoute({this.page})
|
||||
: super(
|
||||
pageBuilder: (
|
||||
|
@ -183,7 +190,7 @@ class SlideLeftRoute extends PageRouteBuilder {
|
|||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
) =>
|
||||
page,
|
||||
page!,
|
||||
transitionsBuilder: (
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
|
@ -207,7 +214,7 @@ class GeckoSpeechAppBar extends StatelessWidget with PreferredSizeWidget {
|
|||
|
||||
GeckoSpeechAppBar(
|
||||
this.title, {
|
||||
Key key,
|
||||
Key? key,
|
||||
}) : preferredSize = const Size.fromHeight(105.4),
|
||||
super(key: key);
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/screens/avatar_fullscreen.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
|
@ -12,16 +12,16 @@ import 'package:provider/provider.dart';
|
|||
|
||||
// ignore: must_be_immutable
|
||||
class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||
HistoryScreen({@required this.pubkey, this.avatar, this.username, Key key})
|
||||
HistoryScreen({required this.pubkey, this.avatar, this.username, Key? key})
|
||||
: super(key: key);
|
||||
final ScrollController scrollController = ScrollController();
|
||||
final double avatarsSize = 80;
|
||||
final String pubkey;
|
||||
final String username;
|
||||
final Image avatar;
|
||||
final String? pubkey;
|
||||
final String? username;
|
||||
final Image? avatar;
|
||||
|
||||
FetchMore fetchMore;
|
||||
FetchMoreOptions opts;
|
||||
FetchMore? fetchMore;
|
||||
FetchMoreOptions? opts;
|
||||
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
|
@ -32,8 +32,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
CesiumPlusProvider _cesiumPlusProvider =
|
||||
Provider.of<CesiumPlusProvider>(context, listen: false);
|
||||
log.i('Build pubkey : ' + pubkey);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {});
|
||||
log.i('Build pubkey : ' + pubkey!);
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) {});
|
||||
|
||||
_historyProvider.balance = _historyProvider.transBC = null;
|
||||
|
||||
|
@ -97,11 +97,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
]);
|
||||
}
|
||||
|
||||
if (result.data['balance'] == null) {
|
||||
if (result.data!['balance'] == null) {
|
||||
_historyProvider.balance = 0.0;
|
||||
} else {
|
||||
_historyProvider.balance = _historyProvider
|
||||
.removeDecimalZero(result.data['balance']['amount'] / 100);
|
||||
.removeDecimalZero(result.data!['balance']['amount'] / 100);
|
||||
}
|
||||
|
||||
if (result.isNotLoading) {
|
||||
|
@ -120,12 +120,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
),
|
||||
),
|
||||
),
|
||||
onNotification: (t) {
|
||||
onNotification: (dynamic t) {
|
||||
if (t is ScrollEndNotification &&
|
||||
scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent * 0.7 &&
|
||||
_historyProvider.pageInfo['hasPreviousPage']) {
|
||||
fetchMore(opts);
|
||||
_historyProvider.pageInfo!['hasPreviousPage'] &&
|
||||
result.isNotLoading) {
|
||||
fetchMore!(opts!);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -150,14 +151,14 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
: Column(children: <Widget>[
|
||||
getTransactionTile(context, _historyProvider),
|
||||
if (result.isLoading &&
|
||||
_historyProvider.pageInfo['hasPreviousPage'])
|
||||
_historyProvider.pageInfo!['hasPreviousPage'])
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
],
|
||||
),
|
||||
if (!_historyProvider.pageInfo['hasPreviousPage'])
|
||||
if (!_historyProvider.pageInfo!['hasPreviousPage'])
|
||||
Column(
|
||||
children: const <Widget>[
|
||||
SizedBox(height: 15),
|
||||
|
@ -175,8 +176,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
CesiumPlusProvider _cesiumPlusProvider =
|
||||
Provider.of<CesiumPlusProvider>(context, listen: false);
|
||||
int keyID = 0;
|
||||
String dateDelimiter;
|
||||
String lastDateDelimiter;
|
||||
String? dateDelimiter;
|
||||
String? lastDateDelimiter;
|
||||
const double _avatarSize = 200;
|
||||
|
||||
bool isTody = false;
|
||||
|
@ -199,15 +200,15 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
};
|
||||
|
||||
return Column(
|
||||
children: _historyProvider.transBC.map((repository) {
|
||||
children: _historyProvider.transBC!.map((repository) {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime date = DateTime.fromMillisecondsSinceEpoch(repository[0] * 1000);
|
||||
|
||||
String dateForm;
|
||||
if ({4, 10, 11, 12}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month].substring(0, 3)}.";
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}.";
|
||||
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month].substring(0, 4)}.";
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}.";
|
||||
} else {
|
||||
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
||||
}
|
||||
|
@ -217,30 +218,28 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
return ((dayOfYear - date.weekday + 10) / 7).floor();
|
||||
}
|
||||
|
||||
if (DateTime(date.year, date.month, date.day) ==
|
||||
DateTime(now.year, now.month, now.day) &&
|
||||
!isTody) {
|
||||
final transactionDate = DateTime(date.year, date.month, date.day);
|
||||
final todayDate = DateTime(now.year, now.month, now.day);
|
||||
final yesterdayDate = DateTime(now.year, now.month, now.day - 1);
|
||||
|
||||
if (transactionDate == todayDate && !isTody) {
|
||||
dateDelimiter = lastDateDelimiter = "Aujourd'hui";
|
||||
isTody = true;
|
||||
} else if (DateTime(date.year, date.month, date.day) ==
|
||||
DateTime(now.year, now.month, now.day - 1) &&
|
||||
!isYesterday) {
|
||||
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
||||
dateDelimiter = lastDateDelimiter = "Hier";
|
||||
isYesterday = true;
|
||||
} else if (weekNumber(date) == weekNumber(now) &&
|
||||
date.year == now.year &&
|
||||
lastDateDelimiter != "Cette semaine" &&
|
||||
DateTime(date.year, date.month, date.day) !=
|
||||
DateTime(now.year, now.month, now.day - 1) &&
|
||||
transactionDate != yesterdayDate &&
|
||||
transactionDate != todayDate &&
|
||||
!isThisWeek) {
|
||||
dateDelimiter = lastDateDelimiter = "Cette semaine";
|
||||
isThisWeek = true;
|
||||
} else if (lastDateDelimiter != monthsInYear[date.month] &&
|
||||
lastDateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
||||
DateTime(date.year, date.month, date.day) !=
|
||||
DateTime(now.year, now.month, now.day) &&
|
||||
DateTime(date.year, date.month, date.day) !=
|
||||
DateTime(now.year, now.month, now.day - 1) &&
|
||||
transactionDate != todayDate &&
|
||||
transactionDate != yesterdayDate &&
|
||||
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
||||
if (date.year == now.year) {
|
||||
dateDelimiter = lastDateDelimiter = monthsInYear[date.month];
|
||||
|
@ -257,7 +256,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30),
|
||||
child: Text(
|
||||
dateDelimiter,
|
||||
dateDelimiter!,
|
||||
style: TextStyle(
|
||||
fontSize: 23, color: orangeC, fontWeight: FontWeight.w300),
|
||||
),
|
||||
|
@ -275,7 +274,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
future: _cesiumPlusProvider.getAvatar(
|
||||
repository[2], _avatarSize),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Image> _avatar) {
|
||||
AsyncSnapshot<Image?> _avatar) {
|
||||
if (_avatar.connectionState !=
|
||||
ConnectionState.done ||
|
||||
_avatar.hasError) {
|
||||
|
@ -294,11 +293,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
]);
|
||||
}
|
||||
if (_avatar.hasData) {
|
||||
g1WalletsBox.get(repository[2]).avatar =
|
||||
g1WalletsBox.get(repository[2])?.avatar =
|
||||
_avatar.data;
|
||||
return ClipOval(child: _avatar.data);
|
||||
} else {
|
||||
g1WalletsBox.get(repository[2]).avatar =
|
||||
g1WalletsBox.get(repository[2])?.avatar =
|
||||
_cesiumPlusProvider
|
||||
.defaultAvatar(repository[2]);
|
||||
return _cesiumPlusProvider
|
||||
|
@ -307,7 +306,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
})
|
||||
: ClipOval(
|
||||
child: Image(
|
||||
image: g1WalletsBox.get(repository[2]).avatar.image,
|
||||
image:
|
||||
g1WalletsBox.get(repository[2])!.avatar!.image,
|
||||
height: _avatarSize,
|
||||
),
|
||||
),
|
||||
|
@ -406,7 +406,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
_historyProvider.snackCopyKey(context);
|
||||
},
|
||||
child: Text(
|
||||
_historyProvider.getShortPubkey(pubkey),
|
||||
_historyProvider.getShortPubkey(pubkey!),
|
||||
style: const TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.w800,
|
||||
|
@ -424,17 +424,17 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
},
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback refetch, FetchMore fetchMore}) {
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.isLoading || result.hasException) {
|
||||
return const Text('...');
|
||||
} else if (result.data['idty'] == null ||
|
||||
result.data['idty']['username'] == null) {
|
||||
} else if (result.data!['idty'] == null ||
|
||||
result.data!['idty']['username'] == null) {
|
||||
return const Text('');
|
||||
} else {
|
||||
return SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
result?.data['idty']['username'] ?? '',
|
||||
result.data!['idty']['username'] ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 27,
|
||||
color: Color(0xff814C00),
|
||||
|
@ -448,7 +448,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
username,
|
||||
username!,
|
||||
style: const TextStyle(
|
||||
fontSize: 27,
|
||||
color: Color(0xff814C00),
|
||||
|
@ -460,7 +460,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
FutureBuilder(
|
||||
future: _historyProvider.getBalance(pubkey),
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<num> _balance) {
|
||||
(BuildContext context, AsyncSnapshot<num?> _balance) {
|
||||
if (_balance.connectionState != ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
return const Text('...');
|
||||
|
@ -480,7 +480,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
FutureBuilder(
|
||||
future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<Image> _avatar) {
|
||||
(BuildContext context, AsyncSnapshot<Image?> _avatar) {
|
||||
if (_avatar.connectionState != ConnectionState.done) {
|
||||
return Stack(children: [
|
||||
ClipOval(
|
||||
|
@ -512,7 +512,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
},
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
image: _avatar.data.image,
|
||||
image: _avatar.data!.image,
|
||||
height: _avatarSize,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
|
@ -536,7 +536,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
},
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
image: avatar.image,
|
||||
image: avatar!.image,
|
||||
height: _avatarSize,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import 'package:bubble/bubble.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_provider.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/chest_provider.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/home.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/home.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/screens/myWallets/restore_chest.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
|
@ -16,7 +15,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({Key key}) : super(key: key);
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -66,13 +65,11 @@ class HomeScreen extends StatelessWidget {
|
|||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('A propos'),
|
||||
onTap: () {
|
||||
// Update the state of the app.
|
||||
// ...
|
||||
},
|
||||
),
|
||||
// ListTile(
|
||||
// title: const Text('A propos'),
|
||||
// onTap: () {
|
||||
// },
|
||||
// ),
|
||||
])),
|
||||
Align(
|
||||
alignment: FractionalOffset.bottomCenter,
|
||||
|
@ -85,8 +82,7 @@ class HomeScreen extends StatelessWidget {
|
|||
body: Builder(
|
||||
builder: (ctx) => StatefulWrapper(
|
||||
onInit: () {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
DubpRust.setup();
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||
if (isWalletsExists) homeClass.snackNode(ctx);
|
||||
});
|
||||
},
|
||||
|
@ -256,7 +252,7 @@ Widget geckHome(context) {
|
|||
image: AssetImage('assets/home/wallet.png'),
|
||||
height: 75)),
|
||||
onTap: () {
|
||||
WalletData defaultWallet =
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(
|
||||
configBox.get('currentChest'));
|
||||
Navigator.push(
|
||||
|
@ -413,19 +409,21 @@ Widget welcomeHome(context) {
|
|||
]),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.9),
|
||||
],
|
||||
),
|
||||
flex: 1,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.9),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 480),
|
||||
child: Column(children: <Widget>[
|
||||
const Spacer(),
|
||||
Row(children: <Widget>[
|
||||
|
@ -507,7 +505,9 @@ Widget welcomeHome(context) {
|
|||
SizedBox(height: isTall ? 100 : 50)
|
||||
]),
|
||||
),
|
||||
))
|
||||
),
|
||||
),
|
||||
)
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ Widget welcomeHome(context) {
|
|||
class StatefulWrapper extends StatefulWidget {
|
||||
final Function onInit;
|
||||
final Widget child;
|
||||
const StatefulWrapper({Key key, @required this.onInit, @required this.child})
|
||||
const StatefulWrapper({Key? key, required this.onInit, required this.child})
|
||||
: super(key: key);
|
||||
@override
|
||||
_StatefulWrapperState createState() => _StatefulWrapperState();
|
||||
|
@ -524,9 +524,7 @@ class StatefulWrapper extends StatefulWidget {
|
|||
class _StatefulWrapperState extends State<StatefulWrapper> {
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.onInit != null) {
|
||||
widget.onInit();
|
||||
}
|
||||
widget.onInit();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -536,7 +534,7 @@ class _StatefulWrapperState extends State<StatefulWrapper> {
|
|||
}
|
||||
}
|
||||
|
||||
Widget bubbleSpeak(String text, {double long, Key textKey}) {
|
||||
Widget bubbleSpeak(String text, {double? long, Key? textKey}) {
|
||||
return Bubble(
|
||||
padding: long == null
|
||||
? const BubbleEdges.all(20)
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/chest_provider.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/chest_provider.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/screens/history.dart';
|
||||
import 'package:gecko/screens/myWallets/change_pin.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
|
||||
int _nbrLinesName = 1;
|
||||
bool _isNewNameValid = false;
|
||||
|
||||
class CesiumWalletOptions extends StatelessWidget {
|
||||
const CesiumWalletOptions(
|
||||
{Key key, Key keyMyWallets, @required this.cesiumWallet})
|
||||
{Key? key, Key? keyMyWallets, required this.cesiumWallet})
|
||||
: super(key: key);
|
||||
|
||||
final ChestData cesiumWallet;
|
||||
|
@ -39,20 +40,12 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
final String shortPubkey =
|
||||
_walletOptions.getShortPubkey(_walletOptions.pubkey.text);
|
||||
|
||||
if (_walletOptions.nameController.text == null ||
|
||||
_isNewNameValid == false) {
|
||||
_walletOptions.nameController.text = cesiumWallet.name;
|
||||
if (_isNewNameValid == false) {
|
||||
_walletOptions.nameController.text = cesiumWallet.name!;
|
||||
} else {
|
||||
cesiumWallet.name = _walletOptions.nameController.text;
|
||||
}
|
||||
|
||||
_walletOptions.nameController.text.length >= 15
|
||||
? _nbrLinesName = 2
|
||||
: _nbrLinesName = 1;
|
||||
if (_walletOptions.nameController.text.length >= 26 && isTall) {
|
||||
_nbrLinesName = 3;
|
||||
}
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
_walletOptions.isEditing = false;
|
||||
|
@ -101,40 +94,40 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
const Color(0xfffafafa),
|
||||
],
|
||||
)),
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 25),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await _walletOptions.changeAvatar();
|
||||
if (newAvatar != null) {
|
||||
cesiumWallet.imageFile = newAvatar;
|
||||
}
|
||||
_walletOptions.reloadBuild();
|
||||
},
|
||||
child: cesiumWallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/chests/${cesiumWallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(cesiumWallet.imageFile, width: 110),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await _walletOptions.changeAvatar();
|
||||
if (newAvatar != null) {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
const Spacer(flex: 1),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar =
|
||||
await (_walletOptions.changeAvatar());
|
||||
cesiumWallet.imageFile = newAvatar;
|
||||
}
|
||||
_walletOptions.reloadBuild();
|
||||
},
|
||||
child: Column(children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/walletOptions/camera.png',
|
||||
height: 40,
|
||||
),
|
||||
const SizedBox(height: 80)
|
||||
])),
|
||||
Column(children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
_walletOptions.reloadBuild();
|
||||
},
|
||||
child: cesiumWallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/chests/${cesiumWallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(cesiumWallet.imageFile!, width: 110),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar =
|
||||
await (_walletOptions.changeAvatar());
|
||||
cesiumWallet.imageFile = newAvatar;
|
||||
_walletOptions.reloadBuild();
|
||||
},
|
||||
child: Column(children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/walletOptions/camera.png',
|
||||
height: 40,
|
||||
),
|
||||
const SizedBox(height: 80)
|
||||
])),
|
||||
const Spacer(flex: 1),
|
||||
Column(children: <Widget>[
|
||||
SizedBox(
|
||||
width: 260,
|
||||
|
@ -144,7 +137,8 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
focusNode: _walletOptions.walletNameFocus,
|
||||
enabled: _walletOptions.isEditing,
|
||||
controller: _walletOptions.nameController,
|
||||
maxLines: _nbrLinesName,
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
|
@ -154,10 +148,10 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 27 : 23,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontFamily: 'Monospace')),
|
||||
fontSize: isTall ? 27 : 23,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
)),
|
||||
),
|
||||
SizedBox(height: isTall ? 5 : 0),
|
||||
Query(
|
||||
|
@ -169,7 +163,7 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
// pollInterval: Duration(seconds: 1),
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback refetch, FetchMore fetchMore}) {
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.hasException) {
|
||||
return Text(result.exception.toString());
|
||||
}
|
||||
|
@ -180,13 +174,13 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
|
||||
// List repositories = result.data['viewer']['repositories']['nodes'];
|
||||
String wBalanceUD;
|
||||
if (result.data['balance'] == null) {
|
||||
if (result.data!['balance'] == null) {
|
||||
wBalanceUD = '0.0';
|
||||
} else {
|
||||
int wBalanceG1 =
|
||||
result.data['balance']['amount'];
|
||||
result.data!['balance']['amount'];
|
||||
int currentUD =
|
||||
result.data['currentUd']['amount'];
|
||||
result.data!['currentUd']['amount'];
|
||||
double wBalanceUDBrut =
|
||||
wBalanceG1 / currentUD; // .toString();
|
||||
wBalanceUD = double.parse(
|
||||
|
@ -196,10 +190,12 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
return Row(children: <Widget>[
|
||||
ImageFiltered(
|
||||
imageFilter: ImageFilter.blur(
|
||||
sigmaX:
|
||||
_walletOptions.isBalanceBlur ? 6 : 0,
|
||||
sigmaY:
|
||||
_walletOptions.isBalanceBlur ? 5 : 0),
|
||||
sigmaX: _walletOptions.isBalanceBlur
|
||||
? 6
|
||||
: 0.001,
|
||||
sigmaY: _walletOptions.isBalanceBlur
|
||||
? 5
|
||||
: 0.001),
|
||||
child: Text(wBalanceUD,
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 20 : 18,
|
||||
|
@ -232,7 +228,6 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(width: 0),
|
||||
Column(children: <Widget>[
|
||||
InkWell(
|
||||
key: const Key('renameWallet'),
|
||||
|
@ -255,22 +250,17 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
const SizedBox(
|
||||
height: 60,
|
||||
)
|
||||
])
|
||||
]),
|
||||
const Spacer(flex: 3),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
SizedBox(height: 4 * ratio),
|
||||
FutureBuilder(
|
||||
future:
|
||||
_walletOptions.generateQRcode(_walletOptions.pubkey.text),
|
||||
builder: (context, snapshot) {
|
||||
return snapshot.data != null
|
||||
? Image.memory(snapshot.data,
|
||||
height: isTall ? 300 : 270)
|
||||
: const Text('-', style: TextStyle(fontSize: 20));
|
||||
}),
|
||||
QrImage(
|
||||
data: _walletOptions.pubkey.text,
|
||||
version: QrVersions.auto,
|
||||
size: isTall ? 300 : 270,
|
||||
),
|
||||
SizedBox(height: 15 * ratio),
|
||||
GestureDetector(
|
||||
key: const Key('copyPubkey'),
|
||||
|
@ -358,7 +348,7 @@ class CesiumWalletOptions extends StatelessWidget {
|
|||
key: const Key('changePin'),
|
||||
onTap: () async {
|
||||
// await _chestProvider.changePin(context, cesiumWallet);
|
||||
String newPin = await Navigator.push(
|
||||
String? newPin = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/change_pin.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/change_pin.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'dart:io';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
||||
ChangePinScreen(
|
||||
{Key keyMyWallets,
|
||||
@required this.walletName,
|
||||
@required this.walletProvider})
|
||||
{Key? keyMyWallets,
|
||||
required this.walletName,
|
||||
required this.walletProvider})
|
||||
: super(key: keyMyWallets);
|
||||
final String walletName;
|
||||
final String? walletName;
|
||||
final MyWalletsProvider walletProvider;
|
||||
Directory appPath;
|
||||
NewWallet _newWalletFile;
|
||||
Directory? appPath;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -42,16 +41,15 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
|||
}),
|
||||
title: SizedBox(
|
||||
height: 22,
|
||||
child: Text(walletName),
|
||||
child: Text(walletName!),
|
||||
),
|
||||
),
|
||||
body: Center(
|
||||
child: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
StatefulWrapper(
|
||||
onInit: () async {
|
||||
_newWalletFile =
|
||||
await _changePin.changePin(walletProvider.pinCode);
|
||||
onInit: () {
|
||||
_changePin.newPin.text = randomSecretCode(pinLength);
|
||||
},
|
||||
child: Container(),
|
||||
),
|
||||
|
@ -82,8 +80,7 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
|||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () async {
|
||||
_newWalletFile =
|
||||
await _changePin.changePin(walletProvider.pinCode);
|
||||
_changePin.newPin.text = randomSecretCode(pinLength);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -98,13 +95,14 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
|||
primary: Colors.green[400], //smoothYellow, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: _changePin.newPin.text != ''
|
||||
? () {
|
||||
_changePin.newPin.text = '';
|
||||
_changePin.storeNewPinChest(context, _newWalletFile);
|
||||
walletProvider.pinCode = _changePin.newPin.text;
|
||||
}
|
||||
: null,
|
||||
onPressed: () async {
|
||||
NewWallet? _newWalletFile = await _changePin.changePin(
|
||||
walletProvider.pinCode,
|
||||
newCustomPin: _changePin.newPin.text);
|
||||
_changePin.newPin.text = '';
|
||||
_changePin.storeNewPinChest(context, _newWalletFile!);
|
||||
walletProvider.pinCode = _changePin.newPin.text;
|
||||
},
|
||||
child: const Text(
|
||||
'Confirmer',
|
||||
style: TextStyle(fontSize: 28),
|
||||
|
@ -122,7 +120,7 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
|
|||
class StatefulWrapper extends StatefulWidget {
|
||||
final Function onInit;
|
||||
final Widget child;
|
||||
const StatefulWrapper({Key key, @required this.onInit, @required this.child})
|
||||
const StatefulWrapper({Key? key, required this.onInit, required this.child})
|
||||
: super(key: key);
|
||||
@override
|
||||
_StatefulWrapperState createState() => _StatefulWrapperState();
|
||||
|
@ -131,9 +129,7 @@ class StatefulWrapper extends StatefulWidget {
|
|||
class _StatefulWrapperState extends State<StatefulWrapper> {
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.onInit != null) {
|
||||
widget.onInit();
|
||||
}
|
||||
widget.onInit();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/models/chest_provider.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/chest_provider.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/screens/myWallets/change_pin.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ChestOptions extends StatelessWidget {
|
||||
const ChestOptions({Key keyMyWallets, @required this.walletProvider})
|
||||
const ChestOptions({Key? keyMyWallets, required this.walletProvider})
|
||||
: super(key: keyMyWallets);
|
||||
final MyWalletsProvider walletProvider;
|
||||
|
||||
|
@ -18,7 +18,7 @@ class ChestOptions extends StatelessWidget {
|
|||
ChestProvider _chestProvider =
|
||||
Provider.of<ChestProvider>(context, listen: false);
|
||||
|
||||
ChestData currentChest = chestBox.get(configBox.get('currentChest'));
|
||||
ChestData currentChest = chestBox.get(configBox.get('currentChest'))!;
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
|
@ -34,7 +34,7 @@ class ChestOptions extends StatelessWidget {
|
|||
}),
|
||||
title: SizedBox(
|
||||
height: 22,
|
||||
child: Text(currentChest.name),
|
||||
child: Text(currentChest.name!),
|
||||
)),
|
||||
body: Builder(
|
||||
builder: (ctx) => SafeArea(
|
||||
|
@ -44,7 +44,7 @@ class ChestOptions extends StatelessWidget {
|
|||
key: const Key('changePin'),
|
||||
onTap: () async {
|
||||
// await _chestProvider.changePin(context, cesiumWallet);
|
||||
String pinResult = await Navigator.push(
|
||||
String? pinResult = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
|
@ -69,8 +69,10 @@ class ChestOptions extends StatelessWidget {
|
|||
height: 25,
|
||||
),
|
||||
const SizedBox(width: 18),
|
||||
const Text('Changer mon code secret',
|
||||
style: TextStyle(fontSize: 20, color: Colors.black)),
|
||||
const Text(
|
||||
'Changer mon code secret',
|
||||
style: TextStyle(fontSize: 20, color: Colors.black),
|
||||
),
|
||||
])),
|
||||
),
|
||||
SizedBox(height: 10 * ratio),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/screens/myWallets/generate_wallets.dart';
|
||||
|
@ -9,8 +9,8 @@ import 'package:carousel_slider/carousel_slider.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class ChooseChest extends StatefulWidget {
|
||||
const ChooseChest({this.action, Key key}) : super(key: key);
|
||||
final String action;
|
||||
const ChooseChest({this.action, Key? key}) : super(key: key);
|
||||
final String? action;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
|
@ -22,7 +22,7 @@ class ChooseChest extends StatefulWidget {
|
|||
class _ChooseChestState extends State<ChooseChest> {
|
||||
TextEditingController tplController = TextEditingController();
|
||||
CarouselController buttonCarouselController = CarouselController();
|
||||
int currentChest = configBox.get('currentChest');
|
||||
int? currentChest = configBox.get('currentChest');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -51,9 +51,9 @@ class _ChooseChestState extends State<ChooseChest> {
|
|||
setState(() {});
|
||||
},
|
||||
enableInfiniteScroll: false,
|
||||
initialPage: currentChest,
|
||||
initialPage: currentChest!,
|
||||
enlargeCenterPage: true,
|
||||
viewportFraction: 0.6,
|
||||
viewportFraction: 0.5,
|
||||
),
|
||||
items: chestBox.toMap().entries.map((i) {
|
||||
return Builder(
|
||||
|
@ -65,12 +65,12 @@ class _ChooseChestState extends State<ChooseChest> {
|
|||
height: 150,
|
||||
)
|
||||
: Image.file(
|
||||
i.value.imageFile,
|
||||
i.value.imageFile!,
|
||||
height: 150,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
i.value.name,
|
||||
i.value.name!,
|
||||
style: const TextStyle(fontSize: 21),
|
||||
),
|
||||
]);
|
||||
|
@ -113,7 +113,7 @@ class _ChooseChestState extends State<ChooseChest> {
|
|||
),
|
||||
onPressed: () {
|
||||
configBox.put('currentChest', currentChest);
|
||||
WalletData defaultWallet =
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(currentChest);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
Navigator.pushAndRemoveUntil(
|
||||
|
|
|
@ -0,0 +1,222 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/myWallets/wallets_home.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
// import 'package:gecko/models/home.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ChooseWalletScreen extends StatelessWidget {
|
||||
ChooseWalletScreen({Key? key}) : super(key: key);
|
||||
int? _derivation;
|
||||
List<int?>? _selectedId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
// HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
|
||||
WalletsProfilesProvider _walletsProfilesProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
title: const SizedBox(
|
||||
height: 22,
|
||||
child: Text('Choix du portefeuille source'),
|
||||
)),
|
||||
body: SafeArea(
|
||||
child: Stack(children: [
|
||||
myWalletsTiles(context),
|
||||
Positioned.fill(
|
||||
bottom: 60,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SizedBox(
|
||||
width: 470,
|
||||
height: 70,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: () async {
|
||||
final resultPay = await _walletsProfilesProvider
|
||||
.pay(context, derivation: _derivation);
|
||||
await paymentsResult(context, resultPay);
|
||||
},
|
||||
child: const Text(
|
||||
'Valider le paiement',
|
||||
style:
|
||||
TextStyle(fontSize: 24, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 160),
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
||||
Widget myWalletsTiles(BuildContext context) {
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
|
||||
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
|
||||
_selectedId ??= defaultWallet!.id();
|
||||
_derivation ??= defaultWallet!.derivation!;
|
||||
|
||||
_myWalletProvider.readAllWallets(configBox.get('currentChest'));
|
||||
|
||||
if (!isWalletsExists) {
|
||||
return const Text('');
|
||||
}
|
||||
|
||||
if (_myWalletProvider.listWallets.isEmpty) {
|
||||
return Column(children: const <Widget>[
|
||||
Center(
|
||||
child: Text(
|
||||
'Veuillez générer votre premier portefeuille',
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
|
||||
)),
|
||||
]);
|
||||
}
|
||||
|
||||
List _listWallets = _myWalletProvider.listWallets;
|
||||
final double screenWidth = MediaQuery.of(context).size.width;
|
||||
int nTule = 2;
|
||||
|
||||
if (screenWidth >= 900) {
|
||||
nTule = 4;
|
||||
} else if (screenWidth >= 650) {
|
||||
nTule = 3;
|
||||
}
|
||||
|
||||
return CustomScrollView(slivers: <Widget>[
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 20)),
|
||||
SliverGrid.count(
|
||||
key: const Key('listWallets'),
|
||||
crossAxisCount: nTule,
|
||||
childAspectRatio: 1,
|
||||
crossAxisSpacing: 0,
|
||||
mainAxisSpacing: 0,
|
||||
children: <Widget>[
|
||||
for (WalletData _repository in _listWallets as Iterable<WalletData>)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
_derivation = _repository.derivation!;
|
||||
_selectedId = _repository.id();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
},
|
||||
child: ClipOvalShadow(
|
||||
shadow: const Shadow(
|
||||
color: Colors.transparent,
|
||||
offset: Offset(0, 0),
|
||||
blurRadius: 5,
|
||||
),
|
||||
clipper: CustomClipperOval(),
|
||||
child: ClipRRect(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(12)),
|
||||
child: Column(children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
gradient: RadialGradient(
|
||||
radius: 0.6,
|
||||
colors: [
|
||||
Colors.green[400]!,
|
||||
const Color(0xFFE7E7A6),
|
||||
],
|
||||
)),
|
||||
child: _repository.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/avatars/${_repository.imageName}',
|
||||
alignment: Alignment.bottomCenter,
|
||||
scale: 0.5,
|
||||
)
|
||||
: Image.file(
|
||||
_repository.imageFile!,
|
||||
alignment: Alignment.bottomCenter,
|
||||
scale: 0.5,
|
||||
),
|
||||
)),
|
||||
ListTile(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
tileColor: _repository.id()[1] == _selectedId![1]
|
||||
? orangeC
|
||||
: const Color(0xffFFD58D),
|
||||
title: Center(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: Text(
|
||||
_repository.name!,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
color:
|
||||
_repository.id()[1] == _selectedId![1]
|
||||
? const Color(0xffF9F9F1)
|
||||
: Colors.black,
|
||||
fontStyle: FontStyle.italic),
|
||||
),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
_derivation = _repository.derivation!;
|
||||
_selectedId = _repository.id();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
},
|
||||
)
|
||||
]),
|
||||
),
|
||||
),
|
||||
)),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> paymentsResult(context, String resultPay) {
|
||||
if (resultPay != "success") log.e(resultPay);
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(resultPay == "success"
|
||||
? 'Paiement effecuté avec succès !'
|
||||
: "Une erreur s'est produite lors du paiement:\n$resultPay"),
|
||||
content: const SingleChildScrollView(child: Text('')),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text("OK"),
|
||||
onPressed: () {
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
|
@ -1,24 +1,23 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
||||
ConfirmStoreWallet({
|
||||
Key validationKey,
|
||||
@required this.generatedMnemonic,
|
||||
@required this.generatedWallet,
|
||||
Key? validationKey,
|
||||
required this.generatedMnemonic,
|
||||
required this.generatedWallet,
|
||||
}) : super(key: validationKey);
|
||||
|
||||
String generatedMnemonic;
|
||||
NewWallet generatedWallet;
|
||||
String? generatedMnemonic;
|
||||
NewWallet? generatedWallet;
|
||||
|
||||
final TextEditingController _mnemonicController = TextEditingController();
|
||||
final TextEditingController _inputRestoreWord = TextEditingController();
|
||||
|
@ -32,9 +31,9 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
|||
Provider.of<GenerateWalletsProvider>(context);
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
final int _currentChest = _myWalletProvider.getCurrentChest();
|
||||
final int? _currentChest = _myWalletProvider.getCurrentChest();
|
||||
|
||||
_mnemonicController.text = generatedMnemonic;
|
||||
_mnemonicController.text = generatedMnemonic!;
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
_generateWalletProvider.isAskedWordValid = false;
|
||||
|
@ -136,7 +135,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
|||
walletName.text != '')
|
||||
? () async {
|
||||
_generateWalletProvider.storeHDWChest(
|
||||
generatedWallet,
|
||||
generatedWallet!,
|
||||
walletName.text,
|
||||
context);
|
||||
_generateWalletProvider.isAskedWordValid =
|
||||
|
@ -149,6 +148,9 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
|
|||
await Future.delayed(
|
||||
const Duration(milliseconds: 50));
|
||||
_myWalletProvider.rebuildWidget();
|
||||
_generateWalletProvider.pin.text = '';
|
||||
_generateWalletProvider
|
||||
.mnemonicController.text = '';
|
||||
Navigator.pushAndRemoveUntil(context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return UnlockingWallet(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/screens/myWallets/confirm_wallet_storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
@ -9,7 +10,7 @@ import 'package:super_tooltip/super_tooltip.dart';
|
|||
|
||||
// ignore: must_be_immutable
|
||||
class GenerateFastChestScreen extends StatelessWidget {
|
||||
SuperTooltip tooltip;
|
||||
SuperTooltip? tooltip;
|
||||
bool hasError = false;
|
||||
String validPin = 'NO PIN';
|
||||
String currentText = "";
|
||||
|
@ -18,18 +19,37 @@ class GenerateFastChestScreen extends StatelessWidget {
|
|||
final GlobalKey _toolTipSentence = GlobalKey();
|
||||
final GlobalKey _toolTipSecret = GlobalKey();
|
||||
|
||||
GenerateFastChestScreen({Key key}) : super(key: key);
|
||||
GenerateFastChestScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
_generateWalletProvider.generateMnemonic();
|
||||
|
||||
return Scaffold(
|
||||
if (_generateWalletProvider.mnemonicController.text == '') {
|
||||
_generateWalletProvider.generateWordList();
|
||||
_generateWalletProvider.mnemonicController.text =
|
||||
_generateWalletProvider.generatedMnemonic!;
|
||||
_generateWalletProvider.pin.text = randomSecretCode(pinLength);
|
||||
}
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
_generateWalletProvider.pin.text = '';
|
||||
_generateWalletProvider.mnemonicController.text = '';
|
||||
return Future<bool>.value(true);
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
onPressed: () {
|
||||
_generateWalletProvider.pin.text = '';
|
||||
_generateWalletProvider.mnemonicController.text = '';
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
title: const SizedBox(
|
||||
height: 22,
|
||||
child: Text('Générer un trousseau'),
|
||||
|
@ -40,7 +60,11 @@ class GenerateFastChestScreen extends StatelessWidget {
|
|||
child: FittedBox(
|
||||
child: FloatingActionButton(
|
||||
heroTag: "buttonGenerateWallet",
|
||||
onPressed: () => _generateWalletProvider.generateMnemonic(),
|
||||
onPressed: () {
|
||||
_generateWalletProvider.generateWordList();
|
||||
_generateWalletProvider.mnemonicController.text =
|
||||
_generateWalletProvider.generatedMnemonic!;
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 40.0,
|
||||
width: 40.0,
|
||||
|
@ -50,103 +74,96 @@ class GenerateFastChestScreen extends StatelessWidget {
|
|||
floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255),
|
||||
))),
|
||||
body: Builder(
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
toolTips(_toolTipSentence, 'Phrase de restauration:',
|
||||
"Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"),
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.mnemonicController,
|
||||
maxLines: 3,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 22.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400)),
|
||||
const SizedBox(height: 8),
|
||||
toolTips(_toolTipSecret, 'Code secret:',
|
||||
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"),
|
||||
Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
key: const Key('generatedPin'),
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.pin,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(),
|
||||
style: const TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () {
|
||||
_generateWalletProvider.changePinCode(
|
||||
reload: false);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
key: const Key('storeKeychain'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: _generateWalletProvider.walletIsGenerated
|
||||
? () async {
|
||||
_generateWalletProvider.nbrWord =
|
||||
_generateWalletProvider.getRandomInt();
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ConfirmStoreWallet(
|
||||
generatedMnemonic:
|
||||
_generateWalletProvider
|
||||
.generatedMnemonic,
|
||||
generatedWallet: _generateWalletProvider
|
||||
.actualWallet);
|
||||
}),
|
||||
);
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 20));
|
||||
// if (_generateWalletProvider.hasBeenStored) {
|
||||
// _generateWalletProvider.hasBeenStored = false;
|
||||
// await Navigator.pushAndRemoveUntil(context,
|
||||
// MaterialPageRoute(builder: (context) {
|
||||
// return UnlockingWallet(
|
||||
// wallet: _myWalletClass.getDefaultWallet(
|
||||
// configBox.get('currentChest')),
|
||||
// action: "mywallets",
|
||||
// );
|
||||
// }), ModalRoute.withName('/'));
|
||||
// }
|
||||
}
|
||||
: null,
|
||||
child: const Text('Enregistrer ce trousseau',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
const SizedBox(height: 20),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
toolTips(_toolTipSentence, 'Phrase de restauration:',
|
||||
"Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"),
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.mnemonicController,
|
||||
maxLines: 3,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 22.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400)),
|
||||
const SizedBox(height: 8),
|
||||
toolTips(_toolTipSecret, 'Code secret:',
|
||||
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"),
|
||||
Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
key: const Key('generatedPin'),
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.pin,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(),
|
||||
style: const TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () {
|
||||
_generateWalletProvider.changePinCode(reload: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
key: const Key('storeKeychain'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: _generateWalletProvider.walletIsGenerated
|
||||
? () async {
|
||||
_generateWalletProvider.nbrWord =
|
||||
_generateWalletProvider.getRandomInt();
|
||||
_generateWalletProvider.actualWallet = await Dewif()
|
||||
.generateDewif(
|
||||
_generateWalletProvider.generatedMnemonic!,
|
||||
_generateWalletProvider.pin.text,
|
||||
lang: appLang);
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return PrintWallet(
|
||||
_generateWalletProvider.generatedMnemonic);
|
||||
return ConfirmStoreWallet(
|
||||
generatedMnemonic:
|
||||
_generateWalletProvider.generatedMnemonic,
|
||||
generatedWallet:
|
||||
_generateWalletProvider.actualWallet);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.print))
|
||||
]),
|
||||
)));
|
||||
}
|
||||
: null,
|
||||
child: const Text('Enregistrer ce trousseau',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
const SizedBox(height: 20),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return PrintWallet(
|
||||
_generateWalletProvider.generatedMnemonic);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.print))
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget toolTips(_key, _text, _message) {
|
||||
|
@ -186,9 +203,9 @@ class GenerateFastChestScreen extends StatelessWidget {
|
|||
|
||||
// ignore: must_be_immutable
|
||||
class PrintWallet extends StatelessWidget {
|
||||
const PrintWallet(this.sentence, {Key key}) : super(key: key);
|
||||
const PrintWallet(this.sentence, {Key? key}) : super(key: key);
|
||||
|
||||
final String sentence;
|
||||
final String? sentence;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -197,6 +214,11 @@ class PrintWallet extends StatelessWidget {
|
|||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
toolbarHeight: 60 * ratio,
|
||||
title: const Text('Imprimer ce trousseau')),
|
||||
body: PdfPreview(
|
||||
|
|
|
@ -1,189 +1,211 @@
|
|||
import 'dart:async';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ImportWalletScreen extends StatelessWidget {
|
||||
const ImportWalletScreen({Key key}) : super(key: key);
|
||||
const ImportWalletScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
GlobalKey _toolTipSecret = GlobalKey();
|
||||
Timer _debounce;
|
||||
Timer? _debounce;
|
||||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
Provider.of<GenerateWalletsProvider>(context, listen: false);
|
||||
WalletOptionsProvider _walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context);
|
||||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
|
||||
_generateWalletProvider.pin.text = randomSecretCode(pinLength);
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
_generateWalletProvider.resetCesiumImportView();
|
||||
return Future<bool>.value(true);
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
onWillPop: () {
|
||||
_generateWalletProvider.resetCesiumImportView();
|
||||
return Future<bool>.value(true);
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
onPressed: () {
|
||||
_generateWalletProvider.resetCesiumImportView();
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
title: const SizedBox(
|
||||
height: 22,
|
||||
child: Text('Importer un portefeuille'),
|
||||
)),
|
||||
body: Builder(
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
Consumer<GenerateWalletsProvider>(
|
||||
builder: (context, walletProvider, _) {
|
||||
return TextFormField(
|
||||
autofocus: true,
|
||||
onChanged: (text) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce!.cancel();
|
||||
}
|
||||
_debounce = Timer(const Duration(milliseconds: 600), () {
|
||||
walletProvider
|
||||
.generateCesiumWalletPubkey(
|
||||
text, walletProvider.cesiumPWD.text)
|
||||
.then((value) {
|
||||
walletProvider.canImport = true;
|
||||
walletProvider.reloadBuild();
|
||||
});
|
||||
});
|
||||
},
|
||||
keyboardType: TextInputType.text,
|
||||
controller: walletProvider.cesiumID,
|
||||
obscureText: !walletProvider
|
||||
.isCesiumIDVisible, //This will obscure text dynamically
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez votre identifiant Cesium',
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
walletProvider.isCesiumIDVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Colors.black,
|
||||
),
|
||||
onPressed: () {
|
||||
walletProvider.cesiumIDisVisible();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 15),
|
||||
Consumer<GenerateWalletsProvider>(
|
||||
builder: (context, walletProvider, _) {
|
||||
return TextFormField(
|
||||
onChanged: (text) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce!.cancel();
|
||||
}
|
||||
_debounce = Timer(const Duration(milliseconds: 600), () {
|
||||
walletProvider
|
||||
.generateCesiumWalletPubkey(
|
||||
walletProvider.cesiumID.text, text)
|
||||
.then((value) {
|
||||
walletProvider.canImport = true;
|
||||
walletProvider.reloadBuild();
|
||||
});
|
||||
});
|
||||
},
|
||||
keyboardType: TextInputType.text,
|
||||
controller: walletProvider.cesiumPWD,
|
||||
obscureText: !walletProvider
|
||||
.isCesiumPWDVisible, //This will obscure text dynamically
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez votre mot de passe Cesium',
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
walletProvider.isCesiumPWDVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Colors.black,
|
||||
),
|
||||
onPressed: () {
|
||||
walletProvider.cesiumPWDisVisible();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 15),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: _generateWalletProvider.cesiumPubkey.text));
|
||||
_walletOptions.snackCopyKey(ctx);
|
||||
},
|
||||
child: Consumer<GenerateWalletsProvider>(
|
||||
builder: (context, walletProvider, _) {
|
||||
return Text(
|
||||
_generateWalletProvider.cesiumPubkey.text,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'Monospace'),
|
||||
);
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
toolTips(_toolTipSecret, 'Code secret:',
|
||||
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"),
|
||||
Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.pin,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(),
|
||||
style: const TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () {
|
||||
_generateWalletProvider.resetCesiumImportView();
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
title: const SizedBox(
|
||||
height: 22,
|
||||
child: Text('Importer un portefeuille'),
|
||||
)),
|
||||
body: Builder(
|
||||
builder: (ctx) => SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
TextFormField(
|
||||
onChanged: (text) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce.cancel();
|
||||
}
|
||||
_debounce =
|
||||
Timer(const Duration(milliseconds: 200), () {
|
||||
_generateWalletProvider
|
||||
.generateCesiumWalletPubkey(text,
|
||||
_generateWalletProvider.cesiumPWD.text)
|
||||
.then((value) {
|
||||
_generateWalletProvider.canImport = true;
|
||||
_generateWalletProvider.reloadBuild();
|
||||
});
|
||||
});
|
||||
},
|
||||
keyboardType: TextInputType.text,
|
||||
controller: _generateWalletProvider.cesiumID,
|
||||
obscureText: !_generateWalletProvider
|
||||
.isCesiumIDVisible, //This will obscure text dynamically
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez votre identifiant Cesium',
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_generateWalletProvider.isCesiumIDVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Colors.black,
|
||||
),
|
||||
onPressed: () {
|
||||
_generateWalletProvider.cesiumIDisVisible();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
TextFormField(
|
||||
onChanged: (text) {
|
||||
if (_debounce?.isActive ?? false) {
|
||||
_debounce.cancel();
|
||||
}
|
||||
_debounce =
|
||||
Timer(const Duration(milliseconds: 200), () {
|
||||
_generateWalletProvider
|
||||
.generateCesiumWalletPubkey(
|
||||
_generateWalletProvider.cesiumID.text,
|
||||
text)
|
||||
.then((value) {
|
||||
_generateWalletProvider.canImport = true;
|
||||
_generateWalletProvider.reloadBuild();
|
||||
});
|
||||
});
|
||||
},
|
||||
keyboardType: TextInputType.text,
|
||||
controller: _generateWalletProvider.cesiumPWD,
|
||||
obscureText: !_generateWalletProvider
|
||||
.isCesiumPWDVisible, //This will obscure text dynamically
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Entrez votre mot de passe Cesium',
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_generateWalletProvider.isCesiumPWDVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Colors.black,
|
||||
),
|
||||
onPressed: () {
|
||||
_generateWalletProvider.cesiumPWDisVisible();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: _generateWalletProvider
|
||||
.cesiumPubkey.text));
|
||||
_walletOptions.snackCopyKey(ctx);
|
||||
},
|
||||
child: Text(
|
||||
_generateWalletProvider.cesiumPubkey.text,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontFamily: 'Monospace'),
|
||||
)),
|
||||
const SizedBox(height: 20),
|
||||
toolTips(_toolTipSecret, 'Code secret:',
|
||||
"Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"),
|
||||
Stack(
|
||||
alignment: Alignment.centerRight,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
enabled: false,
|
||||
controller: _generateWalletProvider.pin,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(),
|
||||
style: const TextStyle(
|
||||
fontSize: 30.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () {
|
||||
_generateWalletProvider.changePinCode(
|
||||
reload: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: _generateWalletProvider.canImport &&
|
||||
_generateWalletProvider.isPinChanged
|
||||
? () {
|
||||
_generateWalletProvider
|
||||
.importCesiumWallet()
|
||||
.then((value) {
|
||||
_myWalletProvider.rebuildWidget();
|
||||
_generateWalletProvider
|
||||
.resetCesiumImportView();
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: const Text('Importer ce portefeuille Cesium',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
]),
|
||||
))));
|
||||
_generateWalletProvider.changePinCode(reload: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Consumer<GenerateWalletsProvider>(
|
||||
builder: (context, walletProvider, _) {
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: walletProvider.canImport
|
||||
? () async {
|
||||
final chestKey =
|
||||
await walletProvider.importCesiumWallet();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: WalletData(chest: chestKey),
|
||||
action: "mywallets",
|
||||
);
|
||||
}),
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
_generateWalletProvider.resetCesiumImportView();
|
||||
}
|
||||
: null,
|
||||
child: const Text(
|
||||
'Importer ce portefeuille Cesium',
|
||||
style: TextStyle(fontSize: 20),
|
||||
),
|
||||
);
|
||||
}),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget toolTips(_key, _text, _message) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:bubble/bubble.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/onBoarding/11.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -10,7 +10,7 @@ import 'package:provider/provider.dart';
|
|||
// import 'package:provider/provider.dart';
|
||||
|
||||
class RestoreChest extends StatelessWidget {
|
||||
const RestoreChest({Key key}) : super(key: key);
|
||||
const RestoreChest({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -92,7 +92,7 @@ class RestoreChest extends StatelessWidget {
|
|||
await Navigator.push(
|
||||
context,
|
||||
FaderTransition(
|
||||
page: OnboardingStepThirteen(), isFast: true),
|
||||
page: const OnboardingStepThirteen(), isFast: true),
|
||||
);
|
||||
} else {
|
||||
await badMnemonicPopup(context);
|
||||
|
@ -160,7 +160,7 @@ class RestoreChest extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
Future<bool> badMnemonicPopup(BuildContext context) async {
|
||||
Future<bool?> badMnemonicPopup(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:gecko/models/home.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class TransactionCommentScreen extends StatelessWidget {
|
||||
TextEditingController tplController = TextEditingController();
|
||||
|
||||
TransactionCommentScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
// HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
title: const SizedBox(
|
||||
height: 22,
|
||||
child: Text('Confirmer le paiement'),
|
||||
),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
TextField(
|
||||
enabled: true,
|
||||
controller: tplController,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 22.0,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400)),
|
||||
const SizedBox(height: 20),
|
||||
]),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
import 'dart:async';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/screens/myWallets/cesium_wallet_options.dart';
|
||||
import 'package:gecko/screens/myWallets/choose_chest.dart';
|
||||
import 'package:gecko/screens/myWallets/choose_wallet.dart';
|
||||
import 'package:gecko/screens/myWallets/wallets_home.dart';
|
||||
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
|
@ -16,105 +18,122 @@ import 'package:gecko/globals.dart';
|
|||
// ignore: must_be_immutable
|
||||
class UnlockingWallet extends StatelessWidget {
|
||||
UnlockingWallet(
|
||||
{Key keyUnlockWallet, @required this.wallet, @required this.action})
|
||||
{Key? keyUnlockWallet, required this.wallet, required this.action})
|
||||
: super(key: keyUnlockWallet);
|
||||
WalletData wallet;
|
||||
WalletData? wallet;
|
||||
String action;
|
||||
|
||||
// ignore: close_sinks
|
||||
StreamController<ErrorAnimationType> errorController;
|
||||
StreamController<ErrorAnimationType>? errorController;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
var pinColor = const Color(0xffF9F9F1);
|
||||
Color? pinColor = const Color(0xffF9F9F1);
|
||||
var walletPin = '';
|
||||
String resultPay;
|
||||
|
||||
Future<NewWallet> get badWallet => null;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
WalletOptionsProvider _walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context);
|
||||
final double statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
|
||||
int _pinLenght;
|
||||
ChestData currentChest = chestBox.get(configBox.get('currentChest'));
|
||||
ChestData currentChest = chestBox.get(configBox.get('currentChest'))!;
|
||||
|
||||
if (currentChest.isCesium) {
|
||||
if (currentChest.isCesium!) {
|
||||
_pinLenght = _walletOptions.getPinLenght(currentChest.dewif);
|
||||
wallet = WalletData(derivation: -1, chest: currentChest.key);
|
||||
} else {
|
||||
_pinLenght = _walletOptions.getPinLenght(wallet.number);
|
||||
_pinLenght = _walletOptions.getPinLenght(wallet!.number);
|
||||
}
|
||||
errorController = StreamController<ErrorAnimationType>();
|
||||
|
||||
return Scaffold(
|
||||
// backgroundColor: Colors.brown[600],
|
||||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(children: <Widget>[
|
||||
SizedBox(height: isTall ? 100 : 20),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
||||
currentChest.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/chests/${currentChest.imageName}',
|
||||
width: isTall ? 130 : 100,
|
||||
)
|
||||
: Image.file(
|
||||
currentChest.imageFile,
|
||||
width: isTall ? 130 : 100,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: Text(
|
||||
currentChest.name,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 25,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w700),
|
||||
)),
|
||||
]),
|
||||
SizedBox(height: 30 * ratio),
|
||||
const SizedBox(
|
||||
width: 400,
|
||||
child: Text(
|
||||
'Pour déverrouiller votre coffre, composez votre code secret à l’abri des lézards indiscrets :',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Stack(children: <Widget>[
|
||||
Positioned(
|
||||
top: statusBarHeight + 10,
|
||||
left: 15,
|
||||
child: Builder(
|
||||
builder: (context) => IconButton(
|
||||
key: const Key('popButton'),
|
||||
icon: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400),
|
||||
)),
|
||||
SizedBox(height: 40 * ratio),
|
||||
pinForm(context, _pinLenght, currentChest),
|
||||
SizedBox(height: 3 * ratio),
|
||||
InkWell(
|
||||
key: const Key('chooseChest'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseChest(action: action);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 70,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Changer de coffre',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
color: orangeC,
|
||||
fontWeight: FontWeight.w600),
|
||||
size: 25,
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
Column(children: <Widget>[
|
||||
SizedBox(height: isTall ? 100 : 20),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
currentChest.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/chests/${currentChest.imageName}',
|
||||
width: isTall ? 130 : 100,
|
||||
)
|
||||
: Image.file(
|
||||
currentChest.imageFile!,
|
||||
width: isTall ? 130 : 100,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: Text(
|
||||
currentChest.name!,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 25,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w700),
|
||||
)),
|
||||
]),
|
||||
SizedBox(height: 30 * ratio),
|
||||
const SizedBox(
|
||||
width: 400,
|
||||
child: Text(
|
||||
'Pour déverrouiller votre coffre, composez votre code secret à l’abri des lézards indiscrets :',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400),
|
||||
)),
|
||||
SizedBox(height: 40 * ratio),
|
||||
pinForm(context, _pinLenght, currentChest),
|
||||
SizedBox(height: 3 * ratio),
|
||||
InkWell(
|
||||
key: const Key('chooseChest'),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseChest(action: action);
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 70,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Changer de coffre',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
color: orangeC,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
)),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -150,7 +169,7 @@ class UnlockingWallet extends StatelessWidget {
|
|||
obscuringCharacter: '*',
|
||||
animationType: AnimationType.fade,
|
||||
validator: (v) {
|
||||
if (v.length < _pinLenght) {
|
||||
if (v!.length < _pinLenght) {
|
||||
return "Votre code PIN fait $_pinLenght caractères";
|
||||
} else {
|
||||
return null;
|
||||
|
@ -183,35 +202,65 @@ class UnlockingWallet extends StatelessWidget {
|
|||
onCompleted: (_pin) async {
|
||||
log.d("Completed");
|
||||
_myWalletProvider.pinCode = _pin;
|
||||
final String resultWallet = await _walletOptions.readLocalWallet(
|
||||
context, wallet, _pin.toUpperCase(), _pinLenght);
|
||||
|
||||
if (currentChest.isCesium!) {
|
||||
try {
|
||||
String _localDewif = chestBox.get(wallet!.chest)!.dewif!;
|
||||
final cesiumWallet =
|
||||
CesiumWallet.fromDewif(_localDewif, _pin.toUpperCase());
|
||||
_walletOptions.pubkey.text = cesiumWallet.pubkey;
|
||||
_myWalletProvider.cesiumSeed = cesiumWallet.seed;
|
||||
_myWalletProvider.mnemonic = 'cesium';
|
||||
} catch (e) {
|
||||
log.e(e);
|
||||
_myWalletProvider.mnemonic = 'bad';
|
||||
}
|
||||
} else {
|
||||
_myWalletProvider.mnemonic = _myWalletProvider.dewifToMnemonic(
|
||||
context, wallet!, _pin.toUpperCase());
|
||||
}
|
||||
// final String? resultWallet = _walletOptions.readLocalWallet(
|
||||
// context, wallet!, _pin.toUpperCase(), _pinLenght);
|
||||
// _myWalletProvider.pinCode = _pin.toUpperCase();
|
||||
_myWalletProvider.pinLenght = _pinLenght;
|
||||
|
||||
if (resultWallet == 'bad') {
|
||||
if (_myWalletProvider.mnemonic == 'bad') {
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
errorController.add(ErrorAnimationType
|
||||
.shake); // Triggering error shake animation
|
||||
pinColor = Colors.red[600];
|
||||
_myWalletProvider.pinCode = _myWalletProvider.mnemonic = '';
|
||||
_walletOptions.reloadBuild();
|
||||
pinFocus.requestFocus();
|
||||
} else {
|
||||
pinColor = Colors.green[400];
|
||||
// await Future.delayed(Duration(milliseconds: 50));
|
||||
if (action == "mywallets") {
|
||||
currentChest.isCesium
|
||||
currentChest.isCesium!
|
||||
? Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return CesiumWalletOptions(
|
||||
cesiumWallet: currentChest);
|
||||
}),
|
||||
)
|
||||
: Navigator.pushNamed(
|
||||
formKey.currentContext, '/mywallets');
|
||||
).then((value) => _myWalletProvider.mnemonic = '')
|
||||
: Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const WalletsHome();
|
||||
}),
|
||||
).then((value) => _myWalletProvider.cesiumSeed.clear());
|
||||
} else if (action == "pay") {
|
||||
resultPay =
|
||||
await _historyProvider.pay(context, _pin.toUpperCase());
|
||||
await _paymentsResult(context);
|
||||
if (currentChest.isCesium!) {
|
||||
final resultPay = await _historyProvider.pay(context);
|
||||
await paymentsResult(context, resultPay);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return ChooseWalletScreen();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -223,31 +272,4 @@ class UnlockingWallet extends StatelessWidget {
|
|||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _paymentsResult(context) {
|
||||
if (resultPay != "Success") log.i(resultPay);
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(resultPay == "Success"
|
||||
? 'Paiement effecuté avec succès !'
|
||||
: "Une erreur s'est produite lors du paiement"),
|
||||
content: const SingleChildScrollView(child: Text('')),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text("OK"),
|
||||
onPressed: () {
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/history.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class WalletOptions extends StatelessWidget {
|
||||
WalletOptions({Key keyMyWallets, @required this.wallet})
|
||||
const WalletOptions({Key? keyMyWallets, required this.wallet})
|
||||
: super(key: keyMyWallets);
|
||||
WalletData wallet;
|
||||
int _nbrLinesName = 1;
|
||||
bool _isNewNameValid = false;
|
||||
final WalletData wallet;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -27,45 +24,20 @@ class WalletOptions extends StatelessWidget {
|
|||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
WalletsProfilesProvider _historyProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
|
||||
final int _currentChest = _myWalletProvider.getCurrentChest();
|
||||
final String shortPubkey =
|
||||
_walletOptions.getShortPubkey(_walletOptions.pubkey.text);
|
||||
log.d(_walletOptions.pubkey.text);
|
||||
|
||||
if (_walletOptions.nameController.text == null ||
|
||||
_isNewNameValid == false) {
|
||||
_walletOptions.nameController.text = wallet.name;
|
||||
} else {
|
||||
wallet.name = _walletOptions.nameController.text;
|
||||
}
|
||||
final int _currentChest = _myWalletProvider.getCurrentChest()!;
|
||||
|
||||
_walletOptions.nameController.text.length >= 15
|
||||
? _nbrLinesName = 2
|
||||
: _nbrLinesName = 1;
|
||||
if (_walletOptions.nameController.text.length >= 26 && isTall) {
|
||||
_nbrLinesName = 3;
|
||||
}
|
||||
|
||||
WalletData defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(_currentChest);
|
||||
|
||||
_walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]);
|
||||
|
||||
int currentChest = _myWalletProvider.getCurrentChest();
|
||||
|
||||
log.d("Wallet options: $currentChest:${wallet.number}");
|
||||
log.d("Wallet options: $_currentChest:${wallet.number}");
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
_walletOptions.isEditing = false;
|
||||
_walletOptions.isBalanceBlur = true;
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/mywallets'),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
return Future<bool>.value(true);
|
||||
},
|
||||
child: Scaffold(
|
||||
|
@ -78,10 +50,7 @@ class WalletOptions extends StatelessWidget {
|
|||
onPressed: () {
|
||||
_walletOptions.isEditing = false;
|
||||
_walletOptions.isBalanceBlur = true;
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/mywallets'),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
title: SizedBox(
|
||||
height: 22,
|
||||
|
@ -110,350 +79,42 @@ class WalletOptions extends StatelessWidget {
|
|||
const Color(0xfffafafa),
|
||||
],
|
||||
)),
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 25),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await walletProvider.changeAvatar();
|
||||
if (newAvatar != null) {
|
||||
wallet.imageFile = newAvatar;
|
||||
}
|
||||
walletProvider.reloadBuild();
|
||||
},
|
||||
child: wallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/avatars/${wallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(
|
||||
wallet.imageFile,
|
||||
width: 110,
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await walletProvider.changeAvatar();
|
||||
if (newAvatar != null) {
|
||||
wallet.imageFile = newAvatar;
|
||||
}
|
||||
walletProvider.reloadBuild();
|
||||
},
|
||||
child: Column(children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/walletOptions/camera.png',
|
||||
height: 40,
|
||||
),
|
||||
const SizedBox(height: 80)
|
||||
])),
|
||||
Column(children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
const Spacer(flex: 1),
|
||||
avatar(walletProvider),
|
||||
const Spacer(flex: 1),
|
||||
Column(children: <Widget>[
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: TextField(
|
||||
key: const Key('walletName'),
|
||||
autofocus: false,
|
||||
focusNode: walletProvider.walletNameFocus,
|
||||
enabled: walletProvider.isEditing,
|
||||
controller: walletProvider.nameController,
|
||||
maxLines: _nbrLinesName,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 27 : 23,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontFamily: 'Monospace')),
|
||||
),
|
||||
walletName(walletProvider, _walletOptions),
|
||||
SizedBox(height: isTall ? 5 : 0),
|
||||
Query(
|
||||
options: QueryOptions(
|
||||
document: gql(getBalance),
|
||||
variables: {
|
||||
'pubkey': walletProvider.pubkey.text,
|
||||
},
|
||||
// pollInterval: Duration(seconds: 1),
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback refetch, FetchMore fetchMore}) {
|
||||
if (result.hasException) {
|
||||
return Text(result.exception.toString());
|
||||
}
|
||||
|
||||
if (result.isLoading) {
|
||||
return const Text('Loading');
|
||||
}
|
||||
|
||||
// List repositories = result.data['viewer']['repositories']['nodes'];
|
||||
String wBalanceUD;
|
||||
if (result.data['balance'] == null) {
|
||||
wBalanceUD = '0.0';
|
||||
} else if (result.hasException) {
|
||||
wBalanceUD = '?';
|
||||
} else {
|
||||
int wBalanceG1 =
|
||||
result.data['balance']['amount'];
|
||||
int currentUD =
|
||||
result.data['currentUd']['amount'];
|
||||
double wBalanceUDBrut =
|
||||
wBalanceG1 / currentUD; // .toString();
|
||||
wBalanceUD = double.parse(
|
||||
(wBalanceUDBrut).toStringAsFixed(2))
|
||||
.toString();
|
||||
}
|
||||
return Row(children: <Widget>[
|
||||
ImageFiltered(
|
||||
imageFilter: ImageFilter.blur(
|
||||
sigmaX:
|
||||
walletProvider.isBalanceBlur ? 6 : 0,
|
||||
sigmaY:
|
||||
walletProvider.isBalanceBlur ? 5 : 0),
|
||||
child: Text(
|
||||
wBalanceUD,
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 20 : 18,
|
||||
color: Colors.black),
|
||||
),
|
||||
),
|
||||
Text(' DU',
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 20 : 18,
|
||||
color: Colors.black))
|
||||
]);
|
||||
|
||||
// Text(
|
||||
// '$wBalanceUD DU',
|
||||
// style: TextStyle(
|
||||
// fontSize: 20, color: Colors.black),
|
||||
// );
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
InkWell(
|
||||
key: const Key('displayBalance'),
|
||||
onTap: () {
|
||||
walletProvider.bluringBalance();
|
||||
},
|
||||
child: Image.asset(
|
||||
walletProvider.isBalanceBlur
|
||||
? 'assets/walletOptions/icon_oeuil.png'
|
||||
: 'assets/walletOptions/icon_oeuil_close.png',
|
||||
height: 35,
|
||||
),
|
||||
),
|
||||
balance(walletProvider),
|
||||
]),
|
||||
const SizedBox(width: 0),
|
||||
Column(children: <Widget>[
|
||||
InkWell(
|
||||
key: const Key('renameWallet'),
|
||||
onTap: () async {
|
||||
_isNewNameValid = walletProvider.editWalletName(
|
||||
wallet.id(),
|
||||
isCesium: false);
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 30));
|
||||
walletProvider.walletNameFocus.requestFocus();
|
||||
},
|
||||
child: ClipRRect(
|
||||
child: Image.asset(
|
||||
walletProvider.isEditing
|
||||
? 'assets/walletOptions/android-checkmark.png'
|
||||
: 'assets/walletOptions/edit.png',
|
||||
width: 20,
|
||||
height: 20),
|
||||
)),
|
||||
const SizedBox(
|
||||
height: 60,
|
||||
)
|
||||
])
|
||||
const Spacer(flex: 3),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
}),
|
||||
SizedBox(height: 4 * ratio),
|
||||
FutureBuilder(
|
||||
future:
|
||||
_walletOptions.generateQRcode(_walletOptions.pubkey.text),
|
||||
builder: (context, snapshot) {
|
||||
return snapshot.data != null
|
||||
? Image.memory(snapshot.data, height: isTall ? 300 : 270)
|
||||
: const Text('-', style: TextStyle(fontSize: 20));
|
||||
},
|
||||
QrImage(
|
||||
data: _walletOptions.pubkey.text,
|
||||
version: QrVersions.auto,
|
||||
size: isTall ? 300 : 270,
|
||||
),
|
||||
SizedBox(height: 15 * ratio),
|
||||
Consumer<WalletOptionsProvider>(
|
||||
builder: (context, walletProvider, _) {
|
||||
return Column(children: [
|
||||
GestureDetector(
|
||||
key: const Key('copyPubkey'),
|
||||
onTap: () {
|
||||
Clipboard.setData(
|
||||
ClipboardData(text: walletProvider.pubkey.text));
|
||||
walletProvider.snackCopyKey(ctx);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/key.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Text("${shortPubkey.split(':')[0]}:",
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontFamily: 'Monospace',
|
||||
color: Colors.black)),
|
||||
Text(shortPubkey.split(':')[1],
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontFamily: 'Monospace')),
|
||||
const SizedBox(width: 15),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
elevation: 1,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: walletProvider.pubkey.text));
|
||||
walletProvider.snackCopyKey(ctx);
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/walletOptions/copy-white.png',
|
||||
height: 25,
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Text(
|
||||
'Copier',
|
||||
style: TextStyle(
|
||||
fontSize: 15, color: Colors.grey[50]),
|
||||
)
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
pubkeyWidget(walletProvider, ctx),
|
||||
SizedBox(height: 10 * ratio),
|
||||
InkWell(
|
||||
key: const Key('displayHistory'),
|
||||
onTap: () {
|
||||
_historyProvider.nPage = 1;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return HistoryScreen(
|
||||
pubkey: walletProvider.pubkey.text,
|
||||
avatar: wallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/avatars/${wallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(
|
||||
wallet.imageFile,
|
||||
width: 110,
|
||||
));
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/clock.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 22),
|
||||
const Text('Historique des transactions',
|
||||
style:
|
||||
TextStyle(fontSize: 20, color: Colors.black)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
historyWidget(context, _historyProvider, walletProvider),
|
||||
SizedBox(height: 12 * ratio),
|
||||
InkWell(
|
||||
key: const Key('setDefaultWallet'),
|
||||
onTap: !walletProvider.isDefaultWallet
|
||||
? () {
|
||||
defaultWallet = wallet;
|
||||
chestBox.get(currentChest).defaultWallet =
|
||||
wallet.number;
|
||||
_myWalletProvider.readAllWallets(_currentChest);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
}
|
||||
: null,
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 31),
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors
|
||||
.grey[walletProvider.isDefaultWallet ? 300 : 500],
|
||||
child: Image.asset(
|
||||
'assets/walletOptions/android-checkmark.png',
|
||||
height: 25,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 22),
|
||||
Text(
|
||||
walletProvider.isDefaultWallet
|
||||
? 'Ce portefeuille est celui par defaut'
|
||||
: 'Définir comme portefeuille par défaut',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: walletProvider.isDefaultWallet
|
||||
? Colors.grey[500]
|
||||
: Colors.black)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
setDefaultWallet(walletProvider, _myWalletProvider,
|
||||
_walletOptions, _currentChest),
|
||||
SizedBox(height: 17 * ratio),
|
||||
if (!walletProvider.isDefaultWallet)
|
||||
InkWell(
|
||||
key: const Key('deleteWallet'),
|
||||
onTap: !walletProvider.isDefaultWallet
|
||||
? () async {
|
||||
await walletProvider.deleteWallet(
|
||||
context, wallet);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_myWalletProvider.listWallets =
|
||||
_myWalletProvider
|
||||
.readAllWallets(_currentChest);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/trash.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 19),
|
||||
const Text('Supprimer ce portefeuille',
|
||||
style: TextStyle(
|
||||
fontSize: 20, color: Color(0xffD80000))),
|
||||
]),
|
||||
),
|
||||
deleteWallet(context, walletProvider, _myWalletProvider,
|
||||
_currentChest)
|
||||
]);
|
||||
}),
|
||||
]),
|
||||
|
@ -462,4 +123,322 @@ class WalletOptions extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget avatar(WalletOptionsProvider walletProvider) {
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await (walletProvider.changeAvatar());
|
||||
wallet.imageFile = newAvatar;
|
||||
walletProvider.reloadBuild();
|
||||
},
|
||||
child: wallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/avatars/${wallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(
|
||||
wallet.imageFile!,
|
||||
width: 110,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 0,
|
||||
top: 0,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
File newAvatar = await (walletProvider.changeAvatar());
|
||||
wallet.imageFile = newAvatar;
|
||||
walletProvider.reloadBuild();
|
||||
},
|
||||
child: Image.asset(
|
||||
'assets/walletOptions/camera.png',
|
||||
height: 40,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget walletName(WalletOptionsProvider walletProvider,
|
||||
WalletOptionsProvider _walletOptions) {
|
||||
bool _isNewNameValid = false;
|
||||
if (_isNewNameValid == false) {
|
||||
_walletOptions.nameController.text = wallet.name!;
|
||||
} else {
|
||||
wallet.name = _walletOptions.nameController.text;
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
width: 260,
|
||||
child: Stack(children: <Widget>[
|
||||
TextField(
|
||||
key: const Key('walletName'),
|
||||
autofocus: false,
|
||||
focusNode: walletProvider.walletNameFocus,
|
||||
enabled: walletProvider.isEditing,
|
||||
controller: walletProvider.nameController,
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
contentPadding: EdgeInsets.all(15.0),
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 27 : 23,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 0,
|
||||
child: InkWell(
|
||||
key: const Key('renameWallet'),
|
||||
onTap: () async {
|
||||
_isNewNameValid =
|
||||
walletProvider.editWalletName(wallet.id(), isCesium: false);
|
||||
await Future.delayed(const Duration(milliseconds: 30));
|
||||
walletProvider.walletNameFocus.requestFocus();
|
||||
},
|
||||
child: ClipRRect(
|
||||
child: Image.asset(
|
||||
walletProvider.isEditing
|
||||
? 'assets/walletOptions/android-checkmark.png'
|
||||
: 'assets/walletOptions/edit.png',
|
||||
width: 20,
|
||||
height: 20),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget balance(WalletOptionsProvider walletProvider) {
|
||||
return Column(children: <Widget>[
|
||||
FutureBuilder(
|
||||
future: walletProvider.getBalance(walletProvider.pubkey.text),
|
||||
builder: (BuildContext context, AsyncSnapshot<num?> _balance) {
|
||||
if (_balance.connectionState != ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
return Text('',
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 20 : 18,
|
||||
));
|
||||
}
|
||||
return ImageFiltered(
|
||||
imageFilter: ImageFilter.blur(
|
||||
sigmaX: walletProvider.isBalanceBlur ? 6 : 0,
|
||||
sigmaY: walletProvider.isBalanceBlur ? 5 : 0),
|
||||
child: Text(
|
||||
_balance.data.toString() + ' Ğ1',
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? 20 : 18,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: 5),
|
||||
InkWell(
|
||||
key: const Key('displayBalance'),
|
||||
onTap: () {
|
||||
walletProvider.bluringBalance();
|
||||
},
|
||||
child: Image.asset(
|
||||
walletProvider.isBalanceBlur
|
||||
? 'assets/walletOptions/icon_oeuil.png'
|
||||
: 'assets/walletOptions/icon_oeuil_close.png',
|
||||
height: 35,
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget pubkeyWidget(WalletOptionsProvider walletProvider, BuildContext ctx) {
|
||||
final String shortPubkey =
|
||||
walletProvider.getShortPubkey(walletProvider.pubkey.text);
|
||||
return GestureDetector(
|
||||
key: const Key('copyPubkey'),
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: walletProvider.pubkey.text));
|
||||
walletProvider.snackCopyKey(ctx);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/key.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Text("${shortPubkey.split(':')[0]}:",
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontFamily: 'Monospace',
|
||||
color: Colors.black)),
|
||||
Text(shortPubkey.split(':')[1],
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontFamily: 'Monospace')),
|
||||
const SizedBox(width: 15),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
elevation: 1,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
Clipboard.setData(
|
||||
ClipboardData(text: walletProvider.pubkey.text));
|
||||
walletProvider.snackCopyKey(ctx);
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
Image.asset(
|
||||
'assets/walletOptions/copy-white.png',
|
||||
height: 25,
|
||||
),
|
||||
const SizedBox(width: 7),
|
||||
Text(
|
||||
'Copier',
|
||||
style: TextStyle(fontSize: 15, color: Colors.grey[50]),
|
||||
)
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget historyWidget(
|
||||
BuildContext context,
|
||||
WalletsProfilesProvider _historyProvider,
|
||||
WalletOptionsProvider walletProvider) {
|
||||
return InkWell(
|
||||
key: const Key('displayHistory'),
|
||||
onTap: () {
|
||||
_historyProvider.nPage = 1;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return HistoryScreen(
|
||||
pubkey: walletProvider.pubkey.text,
|
||||
avatar: wallet.imageFile == null
|
||||
? Image.asset(
|
||||
'assets/avatars/${wallet.imageName}',
|
||||
width: 110,
|
||||
)
|
||||
: Image.file(
|
||||
wallet.imageFile!,
|
||||
width: 110,
|
||||
));
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/clock.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 22),
|
||||
const Text('Historique des transactions',
|
||||
style: TextStyle(fontSize: 20, color: Colors.black)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget setDefaultWallet(
|
||||
WalletOptionsProvider walletProvider,
|
||||
MyWalletsProvider _myWalletProvider,
|
||||
WalletOptionsProvider _walletOptions,
|
||||
int _currentChest) {
|
||||
WalletData defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(_currentChest)!;
|
||||
|
||||
_walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]);
|
||||
|
||||
return InkWell(
|
||||
key: const Key('setDefaultWallet'),
|
||||
onTap: !walletProvider.isDefaultWallet
|
||||
? () {
|
||||
defaultWallet = wallet;
|
||||
chestBox.get(_currentChest)!.defaultWallet = wallet.number;
|
||||
_myWalletProvider.readAllWallets(_currentChest);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
}
|
||||
: null,
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 31),
|
||||
CircleAvatar(
|
||||
backgroundColor:
|
||||
Colors.grey[walletProvider.isDefaultWallet ? 300 : 500],
|
||||
child: Image.asset(
|
||||
'assets/walletOptions/android-checkmark.png',
|
||||
height: 25,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 22),
|
||||
Text(
|
||||
walletProvider.isDefaultWallet
|
||||
? 'Ce portefeuille est celui par defaut'
|
||||
: 'Définir comme portefeuille par défaut',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: walletProvider.isDefaultWallet
|
||||
? Colors.grey[500]
|
||||
: Colors.black)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget deleteWallet(
|
||||
BuildContext context,
|
||||
WalletOptionsProvider walletProvider,
|
||||
MyWalletsProvider _myWalletProvider,
|
||||
int _currentChest) {
|
||||
return InkWell(
|
||||
key: const Key('deleteWallet'),
|
||||
onTap: !walletProvider.isDefaultWallet
|
||||
? () async {
|
||||
await walletProvider.deleteWallet(context, wallet);
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||
_myWalletProvider.listWallets =
|
||||
_myWalletProvider.readAllWallets(_currentChest);
|
||||
_myWalletProvider.rebuildWidget();
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: Row(children: <Widget>[
|
||||
const SizedBox(width: 30),
|
||||
Image.asset(
|
||||
'assets/walletOptions/trash.png',
|
||||
height: 45,
|
||||
),
|
||||
const SizedBox(width: 19),
|
||||
const Text('Supprimer ce portefeuille',
|
||||
style: TextStyle(fontSize: 20, color: Color(0xffD80000))),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/chest_data.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/myWallets/chest_options.dart';
|
||||
import 'package:gecko/screens/myWallets/choose_chest.dart';
|
||||
|
@ -14,9 +15,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class WalletsHome extends StatelessWidget {
|
||||
final _derivationKey = GlobalKey<FormState>();
|
||||
|
||||
WalletsHome({Key key}) : super(key: key);
|
||||
const WalletsHome({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -24,13 +23,14 @@ class WalletsHome extends StatelessWidget {
|
|||
MyWalletsProvider myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
|
||||
final int _currentChestNumber = myWalletProvider.getCurrentChest();
|
||||
final ChestData _currentChest = chestBox.get(_currentChestNumber);
|
||||
final int? _currentChestNumber = myWalletProvider.getCurrentChest();
|
||||
final ChestData _currentChest = chestBox.get(_currentChestNumber)!;
|
||||
myWalletProvider.listWallets =
|
||||
myWalletProvider.readAllWallets(_currentChestNumber);
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
myWalletProvider.pinCode = myWalletProvider.mnemonic = '';
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/'),
|
||||
|
@ -43,12 +43,13 @@ class WalletsHome extends StatelessWidget {
|
|||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
||||
onPressed: () {
|
||||
myWalletProvider.pinCode = myWalletProvider.mnemonic = '';
|
||||
Navigator.popUntil(
|
||||
context,
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
}),
|
||||
title: Text(_currentChest.name,
|
||||
title: Text(_currentChest.name!,
|
||||
key: const Key('myWallets'),
|
||||
style: TextStyle(color: Colors.grey[850])),
|
||||
backgroundColor: const Color(0xffFFD58D),
|
||||
|
@ -71,11 +72,12 @@ class WalletsHome extends StatelessWidget {
|
|||
return Column(children: [
|
||||
const SizedBox(height: 50),
|
||||
SizedBox(
|
||||
height: 120,
|
||||
width: 445,
|
||||
height: 90,
|
||||
width: 420,
|
||||
child: ElevatedButton.icon(
|
||||
icon: Image.asset(
|
||||
'assets/chests/config.png',
|
||||
height: 60,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 2,
|
||||
|
@ -89,9 +91,9 @@ class WalletsHome extends StatelessWidget {
|
|||
}),
|
||||
),
|
||||
label: const Text(
|
||||
" Paramétrer ce coffre",
|
||||
" Paramétrer ce coffre",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xff8a3c0f),
|
||||
),
|
||||
|
@ -99,10 +101,13 @@ class WalletsHome extends StatelessWidget {
|
|||
)),
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(
|
||||
height: 120,
|
||||
width: 445,
|
||||
height: 90,
|
||||
width: 420,
|
||||
child: ElevatedButton.icon(
|
||||
icon: Image.asset('assets/chests/miniChests.png'),
|
||||
icon: Image.asset(
|
||||
'assets/chests/miniChests.png',
|
||||
height: 70,
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 2,
|
||||
primary: floattingYellow, // background
|
||||
|
@ -115,9 +120,9 @@ class WalletsHome extends StatelessWidget {
|
|||
}),
|
||||
),
|
||||
label: const Text(
|
||||
" Changer de coffre",
|
||||
" Changer de coffre",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xff8a3c0f),
|
||||
),
|
||||
|
@ -131,8 +136,7 @@ class WalletsHome extends StatelessWidget {
|
|||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
WalletOptionsProvider _walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context);
|
||||
|
||||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
final bool isWalletsExists = _myWalletProvider.checkIfWalletExist();
|
||||
|
||||
if (!isWalletsExists) {
|
||||
|
@ -151,34 +155,44 @@ class WalletsHome extends StatelessWidget {
|
|||
}
|
||||
|
||||
List _listWallets = _myWalletProvider.listWallets;
|
||||
WalletData defaultWallet =
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
|
||||
final double screenWidth = MediaQuery.of(context).size.width;
|
||||
int nTule = 2;
|
||||
|
||||
if (screenWidth >= 900) {
|
||||
nTule = 4;
|
||||
} else if (screenWidth >= 650) {
|
||||
nTule = 3;
|
||||
}
|
||||
|
||||
return CustomScrollView(slivers: <Widget>[
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 20)),
|
||||
SliverGrid.count(
|
||||
key: const Key('listWallets'),
|
||||
crossAxisCount: 2,
|
||||
crossAxisCount: nTule,
|
||||
childAspectRatio: 1,
|
||||
crossAxisSpacing: 0,
|
||||
mainAxisSpacing: 0,
|
||||
children: <Widget>[
|
||||
for (WalletData _repository in _listWallets)
|
||||
for (WalletData _repository in _listWallets as Iterable<WalletData>)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
await _walletOptions.readLocalWallet(
|
||||
context,
|
||||
_repository,
|
||||
_myWalletProvider.pinCode,
|
||||
_myWalletProvider.pinLenght);
|
||||
onTap: () {
|
||||
// _walletOptions.readLocalWallet(context, _repository,
|
||||
// _myWalletProvider.pinCode, pinLength);
|
||||
_walletOptions.pubkey.text =
|
||||
HdWallet.fromMnemonic(_myWalletProvider.mnemonic)
|
||||
.getPubkey(_repository.derivation!);
|
||||
Navigator.push(
|
||||
context,
|
||||
SmoothTransition(
|
||||
page: WalletOptions(
|
||||
context,
|
||||
SmoothTransition(
|
||||
page: WalletOptions(
|
||||
wallet: _repository,
|
||||
)));
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Navigator.push(context,
|
||||
// MaterialPageRoute(builder: (context) {
|
||||
|
@ -204,7 +218,7 @@ class WalletsHome extends StatelessWidget {
|
|||
gradient: RadialGradient(
|
||||
radius: 0.6,
|
||||
colors: [
|
||||
Colors.green[400],
|
||||
Colors.green[400]!,
|
||||
const Color(0xFFE7E7A6),
|
||||
],
|
||||
)),
|
||||
|
@ -218,7 +232,7 @@ class WalletsHome extends StatelessWidget {
|
|||
scale: 0.5,
|
||||
)
|
||||
: Image.file(
|
||||
_repository.imageFile,
|
||||
_repository.imageFile!,
|
||||
alignment: Alignment.bottomCenter,
|
||||
scale: 0.5,
|
||||
),
|
||||
|
@ -230,7 +244,7 @@ class WalletsHome extends StatelessWidget {
|
|||
bottom: Radius.circular(12))),
|
||||
// contentPadding: const EdgeInsets.only(left: 7.0),
|
||||
tileColor:
|
||||
_repository.id()[1] == defaultWallet.id()[1]
|
||||
_repository.id()[1] == defaultWallet!.id()[1]
|
||||
? orangeC
|
||||
: const Color(0xffFFD58D),
|
||||
// leading: Text('IMAGE'),
|
||||
|
@ -242,7 +256,7 @@ class WalletsHome extends StatelessWidget {
|
|||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: Text(
|
||||
_repository.name,
|
||||
_repository.name!,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
|
@ -256,6 +270,15 @@ class WalletsHome extends StatelessWidget {
|
|||
),
|
||||
// dense: true,
|
||||
onTap: () {
|
||||
// _walletOptions.readLocalWallet(
|
||||
// context,
|
||||
// _repository,
|
||||
// _myWalletProvider.pinCode,
|
||||
// pinLength);
|
||||
_walletOptions.pubkey.text =
|
||||
HdWallet.fromMnemonic(
|
||||
_myWalletProvider.mnemonic)
|
||||
.getPubkey(_repository.derivation!);
|
||||
Navigator.push(
|
||||
context,
|
||||
SmoothTransition(
|
||||
|
@ -295,7 +318,7 @@ class WalletsHome extends StatelessWidget {
|
|||
// pollInterval: Duration(seconds: 1),
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback refetch, FetchMore fetchMore}) {
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.hasException) {
|
||||
return Text(result.exception.toString());
|
||||
}
|
||||
|
@ -304,11 +327,11 @@ class WalletsHome extends StatelessWidget {
|
|||
return const Text('Loading');
|
||||
}
|
||||
String wBalanceUD;
|
||||
if (result.data['balance'] == null) {
|
||||
if (result.data!['balance'] == null) {
|
||||
wBalanceUD = '0.0';
|
||||
} else {
|
||||
int wBalanceG1 = result.data['balance']['amount'];
|
||||
int currentUD = result.data['currentUd']['amount'];
|
||||
int wBalanceG1 = result.data!['balance']['amount'];
|
||||
int currentUD = result.data!['currentUd']['amount'];
|
||||
double wBalanceUDBrut = wBalanceG1 / currentUD; // .toString();
|
||||
wBalanceUD =
|
||||
double.parse((wBalanceUDBrut).toStringAsFixed(2)).toString();
|
||||
|
@ -322,7 +345,7 @@ class WalletsHome extends StatelessWidget {
|
|||
Provider.of<MyWalletsProvider>(context);
|
||||
|
||||
String _newDerivationName =
|
||||
'Portefeuille ${_myWalletProvider.listWallets.last.number + 2}';
|
||||
'Portefeuille ${_myWalletProvider.listWallets.last.number! + 2}';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ClipRRect(
|
||||
|
@ -351,56 +374,6 @@ class WalletsHome extends StatelessWidget {
|
|||
),
|
||||
])));
|
||||
}
|
||||
|
||||
Widget addNewDerivationPopup(context) {
|
||||
final TextEditingController _newDerivationName = TextEditingController();
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context);
|
||||
|
||||
return AlertDialog(
|
||||
content: Stack(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: <Widget>[
|
||||
Form(
|
||||
key: _derivationKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
const Text('Nom du portefeuille:'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextFormField(
|
||||
key: const Key('DerivationNameKey'),
|
||||
controller: _newDerivationName,
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ElevatedButton(
|
||||
key: const Key('validDerivation'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 1,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () async {
|
||||
await _myWalletProvider
|
||||
.generateNewDerivation(
|
||||
context, _newDerivationName.text)
|
||||
.then((_) => _newDerivationName.text == '');
|
||||
},
|
||||
child: const Text("Créer")),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// extension Range on num {
|
||||
|
@ -429,10 +402,10 @@ class ClipOvalShadow extends StatelessWidget {
|
|||
final Widget child;
|
||||
|
||||
const ClipOvalShadow({
|
||||
Key key,
|
||||
@required this.shadow,
|
||||
@required this.clipper,
|
||||
@required this.child,
|
||||
Key? key,
|
||||
required this.shadow,
|
||||
required this.clipper,
|
||||
required this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -451,7 +424,7 @@ class _ClipOvalShadowPainter extends CustomPainter {
|
|||
final Shadow shadow;
|
||||
final CustomClipper<Rect> clipper;
|
||||
|
||||
_ClipOvalShadowPainter({@required this.shadow, @required this.clipper});
|
||||
_ClipOvalShadowPainter({required this.shadow, required this.clipper});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
|
|
|
@ -1,483 +0,0 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/models/home.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class OldHistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||
final TextEditingController _outputPubkey = TextEditingController();
|
||||
ScrollController scrollController = ScrollController();
|
||||
final nRepositories = 20;
|
||||
// HistoryProvider _historyProvider;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final FocusNode _pubkeyFocus = FocusNode();
|
||||
final double avatarsSize = 80;
|
||||
|
||||
FetchMore fetchMore;
|
||||
FetchMoreOptions opts;
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
OldHistoryScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
WalletsProfilesProvider _historyProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context);
|
||||
HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
|
||||
_outputPubkey.text = _historyProvider.pubkey;
|
||||
log.i('Build pubkey : ' + _historyProvider.pubkey);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {});
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 60 * ratio,
|
||||
title: _homeProvider.appBarExplorer,
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: IconButton(
|
||||
icon: _homeProvider.searchIcon,
|
||||
color: Colors.grey[850],
|
||||
onPressed: () {
|
||||
if (_homeProvider.searchIcon.icon == Icons.search) {
|
||||
_homeProvider.searchIcon = Icon(
|
||||
Icons.close,
|
||||
color: Colors.grey[850],
|
||||
);
|
||||
_homeProvider.appBarExplorer = TextField(
|
||||
autofocus: true,
|
||||
controller: _homeProvider.searchQuery,
|
||||
onChanged: (text) {
|
||||
log.d("Clé tappé: $text");
|
||||
if (_historyProvider.isPubkey(text)) {
|
||||
_homeProvider.currentIndex = 0;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return WalletViewScreen(pubkey: text);
|
||||
}),
|
||||
);
|
||||
}
|
||||
},
|
||||
style: TextStyle(
|
||||
color: Colors.grey[850],
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
prefixIcon:
|
||||
Icon(Icons.search, color: Colors.grey[850]),
|
||||
hintText: "Rechercher ...",
|
||||
hintStyle: TextStyle(color: Colors.grey[850])),
|
||||
);
|
||||
_homeProvider.handleSearchStart();
|
||||
} else {
|
||||
_homeProvider.handleSearchEnd();
|
||||
}
|
||||
}))
|
||||
],
|
||||
backgroundColor: const Color(0xffFFD58D),
|
||||
),
|
||||
floatingActionButton: SizedBox(
|
||||
height: 80.0,
|
||||
width: 80.0,
|
||||
child: FittedBox(
|
||||
child: FloatingActionButton(
|
||||
heroTag: "buttonScan",
|
||||
onPressed: () async {
|
||||
await _historyProvider.scan(context);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 40.0,
|
||||
width: 40.0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||
child: Image.asset('assets/qrcode-scan.png'))),
|
||||
backgroundColor:
|
||||
floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Column(children: <Widget>[
|
||||
const SizedBox(height: 0),
|
||||
if (_historyProvider.pubkey != '')
|
||||
historyQuery(context, _historyProvider),
|
||||
]));
|
||||
}
|
||||
|
||||
Widget historyQuery(context, WalletsProfilesProvider _historyProvider) {
|
||||
_pubkeyFocus.unfocus();
|
||||
// HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
||||
CesiumPlusProvider _cesiumPlusProvider =
|
||||
Provider.of<CesiumPlusProvider>(context);
|
||||
bool _isFirstExec = true;
|
||||
return Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Query(
|
||||
options: QueryOptions(
|
||||
document: gql(getHistory),
|
||||
variables: <String, dynamic>{
|
||||
'pubkey': _historyProvider.pubkey,
|
||||
'number': nRepositories,
|
||||
'cursor': null
|
||||
},
|
||||
),
|
||||
builder: (QueryResult result, {fetchMore, refetch}) {
|
||||
if (result.isLoading && result.data == null) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
if (result.hasException) {
|
||||
log.e('Error GVA: ' + result.exception.toString());
|
||||
return Column(children: const <Widget>[
|
||||
SizedBox(height: 50),
|
||||
Text(
|
||||
"Aucun noeud GVA valide n'a pu être trouvé.\nVeuillez réessayer ultérieurement.",
|
||||
style: TextStyle(fontSize: 17.0),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
if (result.data == null && result.exception.toString() == null) {
|
||||
return const Text('Aucune donnée à afficher.');
|
||||
}
|
||||
|
||||
num balance;
|
||||
|
||||
if (result.data['balance'] == null) {
|
||||
balance = 0.0;
|
||||
} else {
|
||||
balance = _historyProvider
|
||||
.removeDecimalZero(result.data['balance']['amount'] / 100);
|
||||
}
|
||||
|
||||
opts = _historyProvider.checkQueryResult(
|
||||
result, opts, _outputPubkey.text);
|
||||
|
||||
// _historyProvider.transBC = null;
|
||||
|
||||
// Build history list
|
||||
return NotificationListener(
|
||||
child: Builder(
|
||||
builder: (context) => Expanded(
|
||||
child: ListView(
|
||||
key: const Key('listTransactions'),
|
||||
controller: scrollController,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
if (_historyProvider.pubkey != '')
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (_isFirstExec)
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
20, 0, 30, 0),
|
||||
child: FutureBuilder(
|
||||
future:
|
||||
_cesiumPlusProvider.getAvatar(
|
||||
_historyProvider.pubkey,
|
||||
55),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Image> _avatar) {
|
||||
if (_avatar.connectionState !=
|
||||
ConnectionState.done ||
|
||||
_avatar.hasError) {
|
||||
return Stack(children: [
|
||||
_cesiumPlusProvider
|
||||
.defaultAvatar(55),
|
||||
Positioned(
|
||||
top: 8,
|
||||
right: 0,
|
||||
width: 12,
|
||||
height: 12,
|
||||
child:
|
||||
CircularProgressIndicator(
|
||||
strokeWidth: 1,
|
||||
color: orangeC,
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
if (_avatar.hasData) {
|
||||
return ClipOval(
|
||||
child: _avatar.data,
|
||||
);
|
||||
}
|
||||
return _cesiumPlusProvider
|
||||
.defaultAvatar(55);
|
||||
}),
|
||||
),
|
||||
GestureDetector(
|
||||
key: const Key('copyPubkey'),
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: _historyProvider.pubkey));
|
||||
_historyProvider.snackCopyKey(context);
|
||||
},
|
||||
child: Text(
|
||||
_historyProvider.getShortPubkey(
|
||||
_historyProvider.pubkey),
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontFamily: 'Monospace')),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
30, 0, 5, 0), // .only(right: 15),
|
||||
child: Card(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
SvgPicture.string(
|
||||
_historyProvider
|
||||
.generateIdenticon(
|
||||
_historyProvider
|
||||
.pubkey),
|
||||
fit: BoxFit.contain,
|
||||
height: 64,
|
||||
width: 64,
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
const SizedBox(width: 0)
|
||||
]),
|
||||
if (_isFirstExec)
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.fromLTRB(0, 0, 0, 0),
|
||||
// padding: const EdgeInsets.,
|
||||
child: FutureBuilder(
|
||||
future: _cesiumPlusProvider
|
||||
.getName(_historyProvider.pubkey),
|
||||
initialData: '...',
|
||||
builder: (context, snapshot) {
|
||||
return Text(snapshot.data ?? '-',
|
||||
style: const TextStyle(
|
||||
fontSize: 20));
|
||||
}),
|
||||
)
|
||||
]),
|
||||
const SizedBox(height: 18),
|
||||
if (_isFirstExec)
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.fromLTRB(0, 0, 0, 0),
|
||||
child: Text(balance.toString() + ' Ğ1',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 18.0))),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
key: const Key('switchPayHistory'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 1,
|
||||
primary: Colors.grey[50], // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
_historyProvider.switchProfileView();
|
||||
},
|
||||
child: Text(
|
||||
_historyProvider.historySwitchButtun,
|
||||
style: TextStyle(
|
||||
fontSize: 15, color: orangeC))),
|
||||
// const Divider(
|
||||
// color: Colors.grey,
|
||||
// height: 5,
|
||||
// thickness: 0.5,
|
||||
// indent: 0,
|
||||
// endIndent: 0,
|
||||
// ),
|
||||
_historyProvider.isHistoryScreen
|
||||
? historyView(context, result)
|
||||
: payView(context, _historyProvider),
|
||||
],
|
||||
))),
|
||||
onNotification: (t) {
|
||||
if (t is ScrollEndNotification &&
|
||||
scrollController.position.pixels >=
|
||||
scrollController.position.maxScrollExtent * 0.7) {
|
||||
fetchMore(opts);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
Widget payView(context, WalletsProfilesProvider _historyProvider) {
|
||||
MyWalletsProvider _myWalletProvider = MyWalletsProvider();
|
||||
WalletData defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
|
||||
|
||||
return Stack(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: <Widget>[
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 20),
|
||||
const Text('Commentaire:', style: TextStyle(fontSize: 20.0)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: _historyProvider.payComment,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(),
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold))),
|
||||
const SizedBox(height: 20),
|
||||
const Text('Montant (DU/Ğ1):', style: TextStyle(fontSize: 20.0)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextFormField(
|
||||
style: const TextStyle(fontSize: 22),
|
||||
controller: _historyProvider.payAmount,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 25.0, horizontal: 10.0),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10.0)),
|
||||
),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d*)'))
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: OutlinedButton(
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(width: 2, color: orangeC)),
|
||||
onPressed: () {
|
||||
// if (_formKey.currentState.validate()) {
|
||||
// _formKey.currentState.save();
|
||||
// }
|
||||
// _historyProvider.pay(payAmount.text, payComment.text);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet, action: "pay");
|
||||
}),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Text(
|
||||
"PAYER",
|
||||
style: TextStyle(fontSize: 25, color: Colors.grey[850]),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget historyView(context, result) {
|
||||
WalletsProfilesProvider _historyProvider =
|
||||
Provider.of<WalletsProfilesProvider>(context);
|
||||
HomeProvider _homeProvider =
|
||||
Provider.of<HomeProvider>(context, listen: false);
|
||||
int keyID = 0;
|
||||
|
||||
return _historyProvider.transBC == null
|
||||
? const Text('Aucune transaction à afficher.')
|
||||
: Column(children: <Widget>[
|
||||
for (var repository in _historyProvider.transBC)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5.0),
|
||||
child: ListTile(
|
||||
key: Key('transaction${keyID++}'),
|
||||
contentPadding: const EdgeInsets.all(5.0),
|
||||
leading: Text(repository[1].toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[800],
|
||||
fontWeight: FontWeight.w700),
|
||||
textAlign: TextAlign.center),
|
||||
title: Text(repository[3],
|
||||
style: const TextStyle(
|
||||
fontSize: 15.0, fontFamily: 'Monospace'),
|
||||
textAlign: TextAlign.center),
|
||||
subtitle: Text(repository[6] != '' ? repository[6] : '-',
|
||||
style: const TextStyle(fontSize: 12.0),
|
||||
textAlign: TextAlign.center),
|
||||
trailing: Text("${repository[4]} Ğ1",
|
||||
style: const TextStyle(fontSize: 14.0),
|
||||
textAlign: TextAlign.justify),
|
||||
dense: true,
|
||||
isThreeLine: false,
|
||||
onTap: () {
|
||||
if (_historyProvider.isPubkey(repository[2])) {
|
||||
_homeProvider.currentIndex = 0;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return WalletViewScreen(pubkey: repository[2]);
|
||||
}),
|
||||
);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
),
|
||||
if (result.isLoading &&
|
||||
_historyProvider.pageInfo['hasPreviousPage'])
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const <Widget>[
|
||||
CircularProgressIndicator(),
|
||||
],
|
||||
),
|
||||
// if (_historyProvider.isTheEnd) // What I did before ...
|
||||
if (!_historyProvider.pageInfo['hasPreviousPage'])
|
||||
Column(
|
||||
children: const <Widget>[
|
||||
SizedBox(height: 15),
|
||||
Text("Début de l'historique.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 20)),
|
||||
SizedBox(height: 15)
|
||||
],
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import 'package:gecko/screens/myWallets/import_cesium_wallet.dart';
|
|||
import 'package:gecko/screens/onBoarding/1.dart';
|
||||
|
||||
class NoKeyChainScreen extends StatelessWidget {
|
||||
const NoKeyChainScreen({Key key}) : super(key: key);
|
||||
const NoKeyChainScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -13,7 +13,7 @@ class OnboardingStepOne extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 1;
|
||||
|
||||
OnboardingStepOne({Key key}) : super(key: key);
|
||||
OnboardingStepOne({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class OnboardingStepTwelve extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 9;
|
||||
|
||||
OnboardingStepTwelve({Key key}) : super(key: key);
|
||||
OnboardingStepTwelve({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -31,7 +31,7 @@ class OnboardingStepTwelve extends StatelessWidget {
|
|||
const SizedBox(height: 10),
|
||||
Image.asset(
|
||||
'assets/onBoarding/plusieurs-codes-secrets-un-trousseau.png',
|
||||
height: 410 * ratio,
|
||||
height: isTall ? 410 : 380,
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
|
@ -50,13 +50,14 @@ class OnboardingStepTwelve extends StatelessWidget {
|
|||
Navigator.push(
|
||||
context,
|
||||
FaderTransition(
|
||||
page: OnboardingStepThirteen(), isFast: true),
|
||||
page: const OnboardingStepThirteen(),
|
||||
isFast: true),
|
||||
);
|
||||
},
|
||||
child: const Text("Générer le code secret",
|
||||
style: TextStyle(fontSize: 20))),
|
||||
))),
|
||||
SizedBox(height: isTall ? 80 : 40),
|
||||
const SizedBox(height: 80),
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
// ignore_for_file: file_names
|
||||
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/onBoarding/12.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class OnboardingStepThirteen extends StatelessWidget {
|
||||
NewWallet generatedWallet;
|
||||
final int progress = 10;
|
||||
|
||||
OnboardingStepThirteen({Key key}) : super(key: key);
|
||||
const OnboardingStepThirteen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -24,19 +21,13 @@ class OnboardingStepThirteen extends StatelessWidget {
|
|||
// MyWalletsProvider myWalletProvider =
|
||||
// Provider.of<MyWalletsProvider>(context);
|
||||
CommonElements common = CommonElements();
|
||||
_generateWalletProvider.pin.text = '';
|
||||
_generateWalletProvider.pin.text =
|
||||
_generateWalletProvider.changePinCode(reload: false);
|
||||
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
body: SafeArea(
|
||||
child: Column(children: <Widget>[
|
||||
FutureBuilder(
|
||||
future: _generateWalletProvider.changePinCode(reload: false),
|
||||
// initialData: '...',
|
||||
builder: (context, snapshot) {
|
||||
generatedWallet = snapshot.data;
|
||||
return const Visibility(visible: false, child: Text(''));
|
||||
}),
|
||||
common.onboardingProgressBar(
|
||||
context, 'Ma phrase de restauration', progress),
|
||||
common.bubbleSpeakRich(
|
||||
|
@ -72,9 +63,8 @@ class OnboardingStepThirteen extends StatelessWidget {
|
|||
IconButton(
|
||||
icon: const Icon(Icons.replay),
|
||||
color: orangeC,
|
||||
onPressed: () async {
|
||||
generatedWallet = await _generateWalletProvider
|
||||
.changePinCode(reload: false);
|
||||
onPressed: () {
|
||||
_generateWalletProvider.changePinCode(reload: true);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -92,9 +82,8 @@ class OnboardingStepThirteen extends StatelessWidget {
|
|||
primary: const Color(0xffFFD58D),
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () async {
|
||||
generatedWallet = await _generateWalletProvider
|
||||
.changePinCode(reload: false);
|
||||
onPressed: () {
|
||||
_generateWalletProvider.changePinCode(reload: true);
|
||||
},
|
||||
child: const Text("Choisir un autre code secret",
|
||||
style: TextStyle(fontSize: 20))),
|
||||
|
@ -116,9 +105,7 @@ class OnboardingStepThirteen extends StatelessWidget {
|
|||
Navigator.push(
|
||||
context,
|
||||
FaderTransition(
|
||||
page: OnboardingStepFourteen(
|
||||
generatedWallet: generatedWallet),
|
||||
isFast: true),
|
||||
page: OnboardingStepFourteen(), isFast: true),
|
||||
);
|
||||
},
|
||||
child: const Text("J'ai noté mon code secret",
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
// ignore_for_file: file_names
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_options.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/providers/wallet_options.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/onBoarding/13_congratulations.dart';
|
||||
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||
|
@ -16,25 +16,23 @@ import 'package:provider/provider.dart';
|
|||
// ignore: must_be_immutable
|
||||
class OnboardingStepFourteen extends StatelessWidget {
|
||||
OnboardingStepFourteen({
|
||||
Key validationKey,
|
||||
@required this.generatedWallet,
|
||||
Key? validationKey,
|
||||
}) : super(key: validationKey);
|
||||
|
||||
NewWallet generatedWallet;
|
||||
final int progress = 11;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
var pinColor = const Color(0xFFA4B600);
|
||||
Color? pinColor = const Color(0xFFA4B600);
|
||||
bool hasError = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
// GenerateWalletsProvider _generateWalletProvider =
|
||||
// Provider.of<GenerateWalletsProvider>(context);
|
||||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
WalletOptionsProvider _walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context);
|
||||
CommonElements common = CommonElements();
|
||||
final int _pinLenght = _walletOptions.getPinLenght(generatedWallet.dewif);
|
||||
final int _pinLenght = _generateWalletProvider.pin.text.length;
|
||||
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
|
@ -64,7 +62,7 @@ class OnboardingStepFourteen extends StatelessWidget {
|
|||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
|
||||
final int _currentChest = _myWalletProvider.getCurrentChest();
|
||||
final int? _currentChest = _myWalletProvider.getCurrentChest();
|
||||
|
||||
return Form(
|
||||
key: formKey,
|
||||
|
@ -83,7 +81,7 @@ class OnboardingStepFourteen extends StatelessWidget {
|
|||
obscuringCharacter: '*',
|
||||
animationType: AnimationType.fade,
|
||||
validator: (v) {
|
||||
if (v.length < _pinLenght) {
|
||||
if (v!.length < _pinLenght) {
|
||||
return "Votre code PIN fait $_pinLenght caractères";
|
||||
} else {
|
||||
return null;
|
||||
|
@ -114,19 +112,23 @@ class OnboardingStepFourteen extends StatelessWidget {
|
|||
)
|
||||
],
|
||||
onCompleted: (_pin) async {
|
||||
_myWalletProvider.pinCode = _pin;
|
||||
_myWalletProvider.pinCode = _pin.toUpperCase();
|
||||
_myWalletProvider.pinLenght = _pinLenght;
|
||||
final bool resultWallet = await _walletOptions.checkPinOK(
|
||||
generatedWallet.dewif, _pin.toUpperCase(), _pinLenght);
|
||||
if (resultWallet) {
|
||||
log.d(_pin + ' || ' + _generateWalletProvider.pin.text);
|
||||
if (_pin.toUpperCase() == _generateWalletProvider.pin.text) {
|
||||
pinColor = Colors.green[500];
|
||||
_generateWalletProvider.storeHDWChest(
|
||||
NewWallet generatedWallet = await Dewif().generateDewif(
|
||||
_generateWalletProvider.generatedMnemonic!,
|
||||
_generateWalletProvider.pin.text,
|
||||
lang: appLang);
|
||||
await _generateWalletProvider.storeHDWChest(
|
||||
generatedWallet, 'Mon portefeuille courant', context);
|
||||
_myWalletProvider.readAllWallets(_currentChest);
|
||||
scheduleMicrotask(() {
|
||||
_walletOptions.reloadBuild();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
});
|
||||
// scheduleMicrotask(() {
|
||||
// _walletOptions.reloadBuild();
|
||||
_myWalletProvider.rebuildWidget();
|
||||
// });
|
||||
_generateWalletProvider.generatedMnemonic = '';
|
||||
Navigator.push(
|
||||
context,
|
||||
FaderTransition(
|
||||
|
|
|
@ -4,13 +4,14 @@ import 'package:flutter/services.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/myWallets/wallets_home.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class OnboardingStepFiveteen extends StatelessWidget {
|
||||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 12;
|
||||
|
||||
OnboardingStepFiveteen({Key key}) : super(key: key);
|
||||
OnboardingStepFiveteen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -33,28 +34,32 @@ class OnboardingStepFiveteen extends StatelessWidget {
|
|||
height: isTall ? 400 : 300,
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 62,
|
||||
child: ElevatedButton(
|
||||
key: const Key('goWalletHome'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: orangeC,
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/mywallets',
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
},
|
||||
child: const Text("Accéder à mes portefeuilles",
|
||||
style: TextStyle(fontSize: 20))),
|
||||
))),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 62,
|
||||
child: ElevatedButton(
|
||||
key: const Key('goWalletHome'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: orangeC,
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const WalletsHome();
|
||||
}),
|
||||
ModalRoute.withName('/'),
|
||||
);
|
||||
},
|
||||
child: const Text("Accéder à mes portefeuilles",
|
||||
style: TextStyle(fontSize: 20))),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 80),
|
||||
]),
|
||||
));
|
||||
|
|
|
@ -14,7 +14,7 @@ class OnboardingStepTwo extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 2;
|
||||
|
||||
OnboardingStepTwo({Key key}) : super(key: key);
|
||||
OnboardingStepTwo({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class OnboardingStepFor extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 3;
|
||||
|
||||
OnboardingStepFor({Key key}) : super(key: key);
|
||||
OnboardingStepFor({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class OnboardingStepFive extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 4;
|
||||
|
||||
OnboardingStepFive({Key key}) : super(key: key);
|
||||
OnboardingStepFive({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class OnboardingStepSeven extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 5;
|
||||
|
||||
OnboardingStepSeven({Key key}) : super(key: key);
|
||||
OnboardingStepSeven({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -43,8 +43,8 @@ class OnboardingStepSeven extends StatelessWidget {
|
|||
Container(
|
||||
padding: const EdgeInsets.only(bottom: 90),
|
||||
child: common.bubbleSpeak(
|
||||
"Moi, j’ai déjà essayé de\nmémoriser une phrase de\nrestauration, mais je n’ai\npas une mémoire\nd’éléphant.",
|
||||
),
|
||||
"Moi, j’ai déjà essayé de\nmémoriser une phrase de\nrestauration, mais je n’ai\npas une mémoire\nd’éléphant.",
|
||||
isMaxWidth: false),
|
||||
),
|
||||
Image.asset(
|
||||
'assets/onBoarding/chopp-gecko.png',
|
||||
|
|
|
@ -12,7 +12,7 @@ class OnboardingStepEight extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 6;
|
||||
|
||||
OnboardingStepEight({Key key}) : super(key: key);
|
||||
OnboardingStepEight({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -29,7 +29,7 @@ class OnboardingStepEight extends StatelessWidget {
|
|||
"J’ai généré votre phrase de restauration !\nTâchez de la garder bien secrète, car elle permet à quiconque la connaît d’accéder à tous vos portefeuilles.",
|
||||
textKey: const Key('step6'),
|
||||
),
|
||||
SizedBox(height: isTall ? 61 : 31),
|
||||
SizedBox(height: isTall ? 70 : 40),
|
||||
// SizedBox(height: 30),
|
||||
sentanceArray(context),
|
||||
// ),
|
||||
|
@ -63,9 +63,10 @@ class OnboardingStepEight extends StatelessWidget {
|
|||
}
|
||||
|
||||
Widget sentanceArray(BuildContext context) {
|
||||
return Container(
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 450),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black),
|
||||
color: Colors.grey[300],
|
||||
|
@ -116,7 +117,7 @@ Widget arrayCell(dataWord) {
|
|||
ImageFiltered(
|
||||
imageFilter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
|
||||
child: Text(dataWord.split(':')[1],
|
||||
style: const TextStyle(fontSize: 20, color: Colors.black)),
|
||||
style: const TextStyle(fontSize: 19, color: Colors.black)),
|
||||
)
|
||||
],
|
||||
));
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/onBoarding/8.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
@ -14,7 +14,7 @@ class OnboardingStepNine extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 6;
|
||||
|
||||
OnboardingStepNine({Key key}) : super(key: key);
|
||||
OnboardingStepNine({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -96,9 +96,7 @@ class OnboardingStepNine extends StatelessWidget {
|
|||
FaderTransition(
|
||||
page: OnboardingStepTen(
|
||||
generatedMnemonic:
|
||||
_generateWalletProvider.generatedMnemonic,
|
||||
generatedWallet:
|
||||
_generateWalletProvider.actualWallet),
|
||||
_generateWalletProvider.generatedMnemonic),
|
||||
isFast: true),
|
||||
);
|
||||
},
|
||||
|
@ -115,64 +113,48 @@ Widget sentanceArray(BuildContext context) {
|
|||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
|
||||
return FutureBuilder(
|
||||
future: _generateWalletProvider.generateWordList(),
|
||||
initialData: const [
|
||||
'1:...',
|
||||
'2:...',
|
||||
'3:...',
|
||||
'4:...',
|
||||
'5:...',
|
||||
'6:...',
|
||||
'7:...',
|
||||
'8:...',
|
||||
'9:...',
|
||||
'10:...',
|
||||
'11:...',
|
||||
'12:...',
|
||||
],
|
||||
builder: (context, formatedArray) {
|
||||
// print(formatedArray.data);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black),
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
)),
|
||||
// color: Colors.grey[300],
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray.data[0]),
|
||||
arrayCell(formatedArray.data[1]),
|
||||
arrayCell(formatedArray.data[2]),
|
||||
arrayCell(formatedArray.data[3]),
|
||||
]),
|
||||
const SizedBox(height: 15),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray.data[4]),
|
||||
arrayCell(formatedArray.data[5]),
|
||||
arrayCell(formatedArray.data[6]),
|
||||
arrayCell(formatedArray.data[7]),
|
||||
]),
|
||||
const SizedBox(height: 15),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray.data[8]),
|
||||
arrayCell(formatedArray.data[9]),
|
||||
arrayCell(formatedArray.data[10]),
|
||||
arrayCell(formatedArray.data[11]),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
});
|
||||
List formatedArray = _generateWalletProvider.generateWordList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 450),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.black),
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
)),
|
||||
// color: Colors.grey[300],
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray[0]),
|
||||
arrayCell(formatedArray[1]),
|
||||
arrayCell(formatedArray[2]),
|
||||
arrayCell(formatedArray[3]),
|
||||
]),
|
||||
const SizedBox(height: 15),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray[4]),
|
||||
arrayCell(formatedArray[5]),
|
||||
arrayCell(formatedArray[6]),
|
||||
arrayCell(formatedArray[7]),
|
||||
]),
|
||||
const SizedBox(height: 15),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(formatedArray[8]),
|
||||
arrayCell(formatedArray[9]),
|
||||
arrayCell(formatedArray[10]),
|
||||
arrayCell(formatedArray[11]),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget arrayCell(dataWord) {
|
||||
|
@ -195,9 +177,9 @@ Widget arrayCell(dataWord) {
|
|||
|
||||
// ignore: must_be_immutable
|
||||
class PrintWallet extends StatelessWidget {
|
||||
const PrintWallet(this.sentence, {Key key}) : super(key: key);
|
||||
const PrintWallet(this.sentence, {Key? key}) : super(key: key);
|
||||
|
||||
final String sentence;
|
||||
final String? sentence;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -206,6 +188,11 @@ class PrintWallet extends StatelessWidget {
|
|||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
toolbarHeight: 60 * ratio,
|
||||
title: const Text('Imprimer ce trousseau')),
|
||||
body: PdfPreview(
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// ignore_for_file: file_names
|
||||
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/generate_wallets.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
import 'package:gecko/screens/onBoarding/9.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -12,14 +10,11 @@ import 'package:provider/provider.dart';
|
|||
// ignore: must_be_immutable
|
||||
class OnboardingStepTen extends StatelessWidget {
|
||||
OnboardingStepTen({
|
||||
Key validationKey,
|
||||
@required this.generatedMnemonic,
|
||||
@required this.generatedWallet,
|
||||
Key? validationKey,
|
||||
required this.generatedMnemonic,
|
||||
}) : super(key: validationKey);
|
||||
|
||||
String generatedMnemonic;
|
||||
NewWallet generatedWallet;
|
||||
|
||||
String? generatedMnemonic;
|
||||
TextEditingController tplController = TextEditingController();
|
||||
TextEditingController wordController = TextEditingController();
|
||||
final TextEditingController _mnemonicController = TextEditingController();
|
||||
|
@ -32,7 +27,7 @@ class OnboardingStepTen extends StatelessWidget {
|
|||
GenerateWalletsProvider _generateWalletProvider =
|
||||
Provider.of<GenerateWalletsProvider>(context);
|
||||
CommonElements common = CommonElements();
|
||||
_mnemonicController.text = generatedMnemonic;
|
||||
_mnemonicController.text = generatedMnemonic!;
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
|
@ -75,7 +70,7 @@ class OnboardingStepTen extends StatelessWidget {
|
|||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(
|
||||
color: Colors.grey[600],
|
||||
color: Colors.grey[600]!,
|
||||
width: 3,
|
||||
)),
|
||||
width: 430,
|
||||
|
|
|
@ -11,7 +11,7 @@ class OnboardingStepEleven extends StatelessWidget {
|
|||
TextEditingController tplController = TextEditingController();
|
||||
final int progress = 8;
|
||||
|
||||
OnboardingStepEleven({Key key}) : super(key: key);
|
||||
OnboardingStepEleven({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/search.dart';
|
||||
import 'package:gecko/providers/search.dart';
|
||||
import 'package:gecko/screens/search_result.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
// import 'package:gecko/models/home.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
class SearchScreen extends StatelessWidget {
|
||||
const SearchScreen({Key key}) : super(key: key);
|
||||
const SearchScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SearchProvider _searchProvider = Provider.of<SearchProvider>(context);
|
||||
final double screenHeight = MediaQuery.of(context).size.height;
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () {
|
||||
|
@ -59,11 +60,11 @@ class SearchScreen extends StatelessWidget {
|
|||
),
|
||||
border: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.grey[500], width: 2),
|
||||
BorderSide(color: Colors.grey[500]!, width: 2),
|
||||
borderRadius: BorderRadius.circular(8)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.grey[500], width: 2.5),
|
||||
BorderSide(color: Colors.grey[500]!, width: 2.5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(20),
|
||||
|
@ -101,7 +102,7 @@ class SearchScreen extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 1),
|
||||
Spacer(flex: screenHeight <= 800 ? 1 : 2),
|
||||
]),
|
||||
),
|
||||
));
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/models/search.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/search.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SearchResultScreen extends StatelessWidget {
|
||||
const SearchResultScreen({Key key}) : super(key: key);
|
||||
const SearchResultScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -64,11 +64,11 @@ class SearchResultScreen extends StatelessWidget {
|
|||
const SizedBox(height: 20),
|
||||
FutureBuilder(
|
||||
future: _searchProvider.searchBlockchain(),
|
||||
builder: (context, snapshot) {
|
||||
builder: (context, AsyncSnapshot<List?> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Expanded(
|
||||
child: ListView(children: <Widget>[
|
||||
for (G1WalletsList g1Wallet in snapshot.data)
|
||||
for (G1WalletsList g1Wallet in snapshot.data ?? [])
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: ListTile(
|
||||
|
@ -81,13 +81,13 @@ class SearchResultScreen extends StatelessWidget {
|
|||
null
|
||||
? ClipOval(
|
||||
child: g1WalletsBox
|
||||
.get(g1Wallet.pubkey)
|
||||
.get(g1Wallet.pubkey)!
|
||||
.avatar)
|
||||
: FutureBuilder(
|
||||
future: _cesiumPlusProvider.getAvatar(
|
||||
g1Wallet.pubkey, _avatarSize),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Image> _avatar) {
|
||||
AsyncSnapshot<Image?> _avatar) {
|
||||
if (_avatar.connectionState !=
|
||||
ConnectionState.done ||
|
||||
_avatar.hasError) {
|
||||
|
@ -108,12 +108,12 @@ class SearchResultScreen extends StatelessWidget {
|
|||
}
|
||||
if (_avatar.hasData) {
|
||||
g1WalletsBox
|
||||
.get(g1Wallet.pubkey)
|
||||
.get(g1Wallet.pubkey)!
|
||||
.avatar = _avatar.data;
|
||||
return ClipOval(child: _avatar.data);
|
||||
} else {
|
||||
g1WalletsBox
|
||||
.get(g1Wallet.pubkey)
|
||||
.get(g1Wallet.pubkey)!
|
||||
.avatar =
|
||||
_cesiumPlusProvider
|
||||
.defaultAvatar(_avatarSize);
|
||||
|
@ -124,7 +124,7 @@ class SearchResultScreen extends StatelessWidget {
|
|||
title: Row(children: <Widget>[
|
||||
Text(
|
||||
_walletsProfilesClass
|
||||
.getShortPubkey(g1Wallet.pubkey),
|
||||
.getShortPubkey(g1Wallet.pubkey!),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontFamily: 'Monospace',
|
||||
|
@ -132,7 +132,7 @@ class SearchResultScreen extends StatelessWidget {
|
|||
textAlign: TextAlign.center),
|
||||
]),
|
||||
subtitle: Row(children: <Widget>[
|
||||
Text(g1Wallet?.id?.username ?? '',
|
||||
Text(g1Wallet.id?.username ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500),
|
||||
|
|
|
@ -1,28 +1,29 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:dubp/dubp.dart';
|
||||
import 'package:durt/durt.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/screens/myWallets/generate_wallets.dart';
|
||||
import 'dart:io';
|
||||
import 'package:gecko/screens/myWallets/import_cesium_wallet.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/screens/myWallets/restore_chest.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
String generatedMnemonic;
|
||||
String? generatedMnemonic;
|
||||
bool walletIsGenerated = false;
|
||||
NewWallet actualWallet;
|
||||
String newWalletName;
|
||||
NewWallet? actualWallet;
|
||||
String? newWalletName;
|
||||
|
||||
bool hasError = false;
|
||||
String validPin = 'NO PIN';
|
||||
String currentText = "";
|
||||
var pinColor = Colors.grey[300];
|
||||
Directory appPath;
|
||||
Directory? appPath;
|
||||
|
||||
final MyWalletsProvider _myWallets = MyWalletsProvider();
|
||||
|
||||
SettingsScreen({Key key}) : super(key: key);
|
||||
SettingsScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -39,43 +40,74 @@ class SettingsScreen extends StatelessWidget {
|
|||
body: Column(children: <Widget>[
|
||||
const SizedBox(height: 40),
|
||||
SizedBox(
|
||||
height: 70,
|
||||
width: 500,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const ImportWalletScreen();
|
||||
}),
|
||||
).then((value) => {
|
||||
if (value == true) {Navigator.pop(context)}
|
||||
}),
|
||||
child: const Text("Importer un portefeuille Cesium",
|
||||
style: TextStyle(fontSize: 16)))),
|
||||
height: 70,
|
||||
width: 500,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const ImportWalletScreen();
|
||||
}),
|
||||
).then((value) => {
|
||||
if (value == true) {Navigator.pop(context)}
|
||||
}),
|
||||
child: const Text(
|
||||
"Importer un portefeuille Cesium",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(
|
||||
height: 70,
|
||||
width: 500,
|
||||
child: ElevatedButton(
|
||||
key: const Key('generateKeychain'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return GenerateFastChestScreen();
|
||||
}),
|
||||
),
|
||||
child: const Text("Générer un nouveau trousseau",
|
||||
style: TextStyle(fontSize: 16)))),
|
||||
height: 70,
|
||||
width: 500,
|
||||
child: ElevatedButton(
|
||||
key: const Key('generateKeychain'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return GenerateFastChestScreen();
|
||||
}),
|
||||
),
|
||||
child: const Text(
|
||||
"Générer un nouveau trousseau",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
SizedBox(
|
||||
height: 70,
|
||||
width: 500,
|
||||
child: ElevatedButton(
|
||||
key: const Key('generateKeychain'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 5,
|
||||
primary: yellowC, // background
|
||||
onPrimary: Colors.black, // foreground
|
||||
),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return const RestoreChest();
|
||||
}),
|
||||
),
|
||||
child: const Text(
|
||||
"Restaurer un coffre",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
|
|||
class TemplateScreen extends StatelessWidget {
|
||||
TextEditingController tplController = TextEditingController();
|
||||
|
||||
TemplateScreen({Key key}) : super(key: key);
|
||||
TemplateScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/models/my_wallets.dart';
|
||||
import 'package:gecko/providers/cesium_plus.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/models/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/screens/avatar_fullscreen.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
|
@ -15,11 +15,11 @@ import 'package:provider/provider.dart';
|
|||
|
||||
class WalletViewScreen extends StatelessWidget {
|
||||
const WalletViewScreen(
|
||||
{@required this.pubkey, this.username, this.avatar, Key key})
|
||||
{required this.pubkey, this.username, this.avatar, Key? key})
|
||||
: super(key: key);
|
||||
final String pubkey;
|
||||
final String username;
|
||||
final Image avatar;
|
||||
final String? pubkey;
|
||||
final String? username;
|
||||
final Image? avatar;
|
||||
final double buttonSize = 100;
|
||||
final double buttonFontSize = 18;
|
||||
|
||||
|
@ -31,6 +31,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
CesiumPlusProvider _cesiumPlusProvider =
|
||||
Provider.of<CesiumPlusProvider>(context, listen: false);
|
||||
|
||||
_historyProvider.pubkey = pubkey!;
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
appBar: AppBar(
|
||||
|
@ -185,8 +187,9 @@ class WalletViewScreen extends StatelessWidget {
|
|||
// WalletsProfilesProvider _walletViewProvider =
|
||||
// Provider.of<WalletsProfilesProvider>(context);
|
||||
const double shapeSize = 20;
|
||||
MyWalletsProvider _myWalletProvider = MyWalletsProvider();
|
||||
WalletData defaultWallet =
|
||||
MyWalletsProvider _myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
WalletData? defaultWallet =
|
||||
_myWalletProvider.getDefaultWallet(configBox.get('currentChest'));
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
|
@ -199,111 +202,120 @@ class WalletViewScreen extends StatelessWidget {
|
|||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
child: Container(
|
||||
height: 400,
|
||||
decoration: const ShapeDecoration(
|
||||
color: Color(0xffffeed1),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(shapeSize),
|
||||
topLeft: Radius.circular(shapeSize),
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
child: Container(
|
||||
height: 400,
|
||||
decoration: const ShapeDecoration(
|
||||
color: Color(0xffffeed1),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(shapeSize),
|
||||
topLeft: Radius.circular(shapeSize),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'Effectuer un virement',
|
||||
style: TextStyle(
|
||||
fontSize: 26, fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'Saisissez dans le champ ci-dessous le montant à virer.',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[600]),
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Column(children: <Widget>[
|
||||
TextField(
|
||||
controller: _walletViewProvider.payAmount,
|
||||
autofocus: true,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (_) => setState(() {}),
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}')),
|
||||
],
|
||||
// onChanged: (v) => _searchProvider.rebuildWidget(),
|
||||
decoration: InputDecoration(
|
||||
hintText: '0.00',
|
||||
suffix: const Text('Ğ1'),
|
||||
filled: true,
|
||||
fillColor: Colors.transparent,
|
||||
// border: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// BorderSide(color: Colors.grey[500], width: 2),
|
||||
// borderRadius: BorderRadius.circular(8)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey[500]!, width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(20),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
// const Spacer(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed:
|
||||
_walletViewProvider.payAmount.text != ''
|
||||
? () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet,
|
||||
action: "pay");
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
child: const Text(
|
||||
'Effectuer le virement',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'Effectuer un virement',
|
||||
style: TextStyle(
|
||||
fontSize: 26, fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'Saisissez dans le champ ci-dessous le montant à virer de ... vers ...',
|
||||
style: TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[600]),
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Column(children: <Widget>[
|
||||
TextField(
|
||||
controller: _walletViewProvider.payAmount,
|
||||
autofocus: true,
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}')),
|
||||
],
|
||||
// onChanged: (v) => _searchProvider.rebuildWidget(),
|
||||
decoration: InputDecoration(
|
||||
hintText: '0.00',
|
||||
suffix: const Text('DU/Ğ1'),
|
||||
filled: true,
|
||||
fillColor: Colors.transparent,
|
||||
// border: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// BorderSide(color: Colors.grey[500], width: 2),
|
||||
// borderRadius: BorderRadius.circular(8)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey[500], width: 2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(20),
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
// const Spacer(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
primary: orangeC, // background
|
||||
onPrimary: Colors.white, // foreground
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return UnlockingWallet(
|
||||
wallet: defaultWallet, action: "pay");
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text(
|
||||
'Effectuer le virement',
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}).then((value) => _walletViewProvider.payAmount.text = '');
|
||||
}
|
||||
|
||||
|
@ -342,7 +354,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
_historyProvider.snackCopyKey(context);
|
||||
},
|
||||
child: Text(
|
||||
_historyProvider.getShortPubkey(pubkey),
|
||||
_historyProvider.getShortPubkey(pubkey!),
|
||||
style: const TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.w800,
|
||||
|
@ -361,20 +373,20 @@ class WalletViewScreen extends StatelessWidget {
|
|||
},
|
||||
),
|
||||
builder: (QueryResult result,
|
||||
{VoidCallback refetch, FetchMore fetchMore}) {
|
||||
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
||||
if (result.isLoading || result.hasException) {
|
||||
return const Text('...');
|
||||
} else if (result.data['idty'] == null ||
|
||||
result.data['idty']['username'] == null) {
|
||||
} else if (result.data!['idty'] == null ||
|
||||
result.data!['idty']['username'] == null) {
|
||||
g1WalletsBox.get(pubkey)?.username = '';
|
||||
return const Text('');
|
||||
} else {
|
||||
g1WalletsBox.get(pubkey)?.username =
|
||||
result?.data['idty']['username'] ?? '';
|
||||
result.data!['idty']['username'] ?? '';
|
||||
return SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
result?.data['idty']['username'] ?? '',
|
||||
result.data!['idty']['username'] ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 27,
|
||||
color: Color(0xff814C00),
|
||||
|
@ -389,7 +401,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
g1WalletsBox.get(pubkey)?.username,
|
||||
g1WalletsBox.get(pubkey)?.username ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 27,
|
||||
color: Color(0xff814C00),
|
||||
|
@ -400,7 +412,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
username,
|
||||
username!,
|
||||
style: const TextStyle(
|
||||
fontSize: 27,
|
||||
color: Color(0xff814C00),
|
||||
|
@ -415,7 +427,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
return SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
snapshot.data ?? '-',
|
||||
snapshot.data.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 18, color: Colors.black),
|
||||
),
|
||||
|
@ -429,7 +441,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
FutureBuilder(
|
||||
future: _cesiumPlusProvider.getAvatar(pubkey, _avatarSize),
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<Image> _avatar) {
|
||||
(BuildContext context, AsyncSnapshot<Image?> _avatar) {
|
||||
if (_avatar.connectionState != ConnectionState.done) {
|
||||
return Stack(children: [
|
||||
ClipOval(
|
||||
|
@ -461,7 +473,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
},
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
image: _avatar.data.image,
|
||||
image: _avatar.data!.image,
|
||||
height: _avatarSize,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
|
@ -485,7 +497,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
},
|
||||
child: ClipOval(
|
||||
child: Image(
|
||||
image: avatar.image,
|
||||
image: avatar!.image,
|
||||
height: _avatarSize,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
[package]
|
||||
name = "dubp_rs"
|
||||
version = "0.1.0"
|
||||
authors = ["Éloïs SANCHEZ <elois@duniter.org>"]
|
||||
license = "AGPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "dubp_rs"
|
||||
crate-type = ["rlib"]
|
||||
|
||||
[dependencies]
|
||||
allo-isolate = "0.1.6"
|
||||
dubp-client = { git = "https://git.duniter.org/libs/dubp-rs-client-lib", branch = "master", features = ["blocking"], default-features = false }
|
||||
#dubp-client= { path = "../dubp-rs-client-lib", features = ["blocking"], default-features = false }
|
||||
fast-threadpool = { version = "0.3.0", default-features = false }
|
||||
once_cell = { version = "1.3.1", default-features = false, features = ["std"] }
|
||||
parking_lot = "0.11.1"
|
||||
thiserror = "1.0.24"
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = "0.14.3"
|
||||
dart-bindgen = "0.1.7"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5.0"
|
||||
rusty-hook = "^0.11.2"
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use dart_bindgen::{config::*, Codegen};
|
||||
|
||||
fn main() {
|
||||
let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let config = cbindgen::Config {
|
||||
language: cbindgen::Language::C,
|
||||
braces: cbindgen::Braces::SameLine,
|
||||
cpp_compat: true,
|
||||
style: cbindgen::Style::Both,
|
||||
..Default::default()
|
||||
};
|
||||
cbindgen::Builder::new()
|
||||
.with_crate(crate_dir)
|
||||
.with_config(config)
|
||||
.generate()
|
||||
.expect("Unable to generate bindings")
|
||||
.write_to_file("binding.h");
|
||||
let config = DynamicLibraryConfig {
|
||||
ios: DynamicLibraryCreationMode::Executable.into(),
|
||||
android: DynamicLibraryCreationMode::open("libdubp_rs.so").into(),
|
||||
linux: DynamicLibraryCreationMode::open("libdubp_rs.so").into(),
|
||||
..Default::default()
|
||||
};
|
||||
// load the c header file, with config and lib name
|
||||
let codegen = Codegen::builder()
|
||||
.with_src_header("binding.h")
|
||||
.with_lib_name("libdubp")
|
||||
.with_config(config)
|
||||
.with_allo_isolate()
|
||||
.build()
|
||||
.unwrap();
|
||||
// generate the dart code and get the bindings back
|
||||
let bindings = codegen.generate().unwrap();
|
||||
// write the bindings to your dart package
|
||||
// and start using it to write your own high level abstraction.
|
||||
bindings
|
||||
.write_to_file("../../packages/dubp_rs/lib/ffi.dart")
|
||||
.unwrap();
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
static THREAD_POOL: Lazy<ThreadPoolSyncHandler<()>> = Lazy::new(|| {
|
||||
ThreadPool::start(ThreadPoolConfig::low().queue_size(Some(16)), ()).into_sync_handler()
|
||||
});
|
||||
|
||||
pub(crate) fn exec_async<F, F2, P, R>(port: i64, parse_params: F, async_job: F2)
|
||||
where
|
||||
P: 'static + Send + Sync,
|
||||
F: FnOnce() -> Result<P, DubpError>,
|
||||
F2: 'static + Send + Sync + FnOnce(P) -> R,
|
||||
DartRes: From<R>,
|
||||
{
|
||||
match parse_params() {
|
||||
Ok(parsed_params) => {
|
||||
if THREAD_POOL
|
||||
.launch(move |_| Isolate::new(port).post(DartRes::from(async_job(parsed_params))))
|
||||
.is_err()
|
||||
{
|
||||
Isolate::new(port).post(DartRes::err("thread pool panicked"));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
Isolate::new(port).post(DartRes::err(e));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod bip32;
|
||||
pub mod classic;
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub(super) fn change_secret_code(
|
||||
dewif: &str,
|
||||
old_secret_code: &str,
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
system_memory: i64,
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let new_log_n = log_n(system_memory);
|
||||
let new_secret_code = gen_secret_code(member_wallet, secret_code_type, new_log_n)?;
|
||||
|
||||
let new_dewif = dubp_client::crypto::dewif::change_dewif_passphrase(
|
||||
dewif,
|
||||
old_secret_code,
|
||||
&new_secret_code,
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
Ok(vec![new_dewif, new_secret_code])
|
||||
}
|
||||
|
||||
pub(super) fn gen_dewif(
|
||||
currency: &str,
|
||||
language: Language,
|
||||
mnemonic: &str,
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
system_memory: i64,
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let currency = parse_currency(currency)?;
|
||||
let mnemonic =
|
||||
Mnemonic::from_phrase(mnemonic, language).map_err(|_| DubpError::WrongLanguage)?;
|
||||
|
||||
let log_n = log_n(system_memory);
|
||||
let secret_code = gen_secret_code(member_wallet, secret_code_type, log_n)?;
|
||||
|
||||
let dewif =
|
||||
dubp_client::crypto::dewif::create_dewif_v1(currency, log_n, &mnemonic, &secret_code)
|
||||
.map_err(|_| DubpError::RandErr)?;
|
||||
|
||||
Ok(vec![dewif, secret_code])
|
||||
}
|
||||
|
||||
pub(super) fn get_dewif_meta(
|
||||
dewif: &str,
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let dubp_client::crypto::dewif::DewifMeta {
|
||||
algo,
|
||||
currency,
|
||||
log_n,
|
||||
version,
|
||||
} = dubp_client::crypto::dewif::read_dewif_meta(dewif).map_err(DubpError::DewifReadError)?;
|
||||
|
||||
let secret_code_len =
|
||||
crate::secret_code::compute_secret_code_len(member_wallet, secret_code_type, log_n)?;
|
||||
|
||||
Ok(vec![
|
||||
if algo == KeysAlgo::Bip32Ed25519 {
|
||||
"Bip32Ed25519".to_owned()
|
||||
} else {
|
||||
"Ed25519".to_owned()
|
||||
},
|
||||
currency.to_string(),
|
||||
secret_code_len.to_string(),
|
||||
version.to_string(),
|
||||
])
|
||||
}
|
||||
|
||||
pub(super) fn get_pubkey(
|
||||
account_index_opt: Option<u32>,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
if let Some(account_index) = account_index_opt {
|
||||
dewif::bip32::get_bip32_pubkey(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
)
|
||||
} else if address_index_opt.is_none() && external_opt.is_none() {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
match payload {
|
||||
DewifPayload::Ed25519(keypair) => Ok(keypair.public_key().to_base58()),
|
||||
DewifPayload::Bip32Ed25519(_) => Err(DubpError::GetMasterPubkeyOfHdWallet),
|
||||
}
|
||||
} else {
|
||||
Err(DubpError::GiveExternalBoolOrAddressIndexForLegacyWallet)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_secret_code_len(
|
||||
dewif: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
) -> Result<usize, DubpError> {
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let member_wallet = member_wallet != 0;
|
||||
let secret_code_type = SecretCodeType::from(secret_code_type);
|
||||
|
||||
let log_n = dubp_client::crypto::dewif::read_dewif_log_n(ExpectedCurrency::Any, dewif)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
crate::secret_code::compute_secret_code_len(member_wallet, secret_code_type, log_n)
|
||||
}
|
||||
|
||||
pub(crate) fn log_n(system_memory: i64) -> u8 {
|
||||
if system_memory > 3_000_000_000 {
|
||||
15
|
||||
} else {
|
||||
12
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn sign(
|
||||
account_index_opt: Option<u32>,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
msg: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
if let Some(account_index) = account_index_opt {
|
||||
dewif::bip32::sign_bip32(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msg,
|
||||
)
|
||||
} else {
|
||||
dewif::classic::sign(currency, dewif, secret_code, msg)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn sign_several(
|
||||
account_index_opt: Option<u32>,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
msgs: &[&str],
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
if let Some(account_index) = account_index_opt {
|
||||
dewif::bip32::sign_several_bip32(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msgs,
|
||||
)
|
||||
} else {
|
||||
dewif::classic::sign_several(currency, dewif, secret_code, msgs)
|
||||
}
|
||||
}
|
|
@ -1,436 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct OpaqueAccount {
|
||||
address_index: u32,
|
||||
chain_code: ChainCode,
|
||||
public_key: PublicKey,
|
||||
}
|
||||
|
||||
static CHAINING_EXTERNAL_PUBKEYS: Lazy<Arc<Mutex<HashMap<u32, OpaqueAccount>>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
pub(crate) fn get_accounts_pubkeys(
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
accounts_indexs: Vec<U31>,
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
if accounts_indexs.contains(&U31::new(0)?) {
|
||||
verify_member_secret_code(currency, dewif, secret_code)?;
|
||||
}
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
Ok(accounts_indexs
|
||||
.into_iter()
|
||||
.map(|account_index| {
|
||||
PrivateDerivationPath::transparent(account_index)
|
||||
.map(|path| master_keypair.derive(path).public_key().to_base58())
|
||||
})
|
||||
.collect::<Result<Vec<_>, InvalidAccountIndex>>()?)
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_bip32_keypair(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
) -> Result<KeyPairEnum, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
if account_index == 0 {
|
||||
verify_member_secret_code(currency, dewif, secret_code)?;
|
||||
}
|
||||
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
Ok(KeyPairEnum::Bip32Ed25519(master_keypair.derive(
|
||||
z_get_derivation_path(account_index, address_index_opt, external_opt)?,
|
||||
)))
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_bip32_pubkey(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
if account_index == 0 {
|
||||
verify_member_secret_code(currency, dewif, secret_code)?;
|
||||
}
|
||||
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
Ok(master_keypair
|
||||
.derive(z_get_derivation_path(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
external_opt,
|
||||
)?)
|
||||
.public_key()
|
||||
.to_base58())
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_opaque_account_next_external_address(
|
||||
account_index: U31,
|
||||
) -> Result<String, DubpError> {
|
||||
let mut guard = CHAINING_EXTERNAL_PUBKEYS.lock();
|
||||
if let Some(opaque_account) = guard.get_mut(&account_index.into_u32()) {
|
||||
let next_address = PublicKeyWithChainCode {
|
||||
chain_code: opaque_account.chain_code,
|
||||
public_key: opaque_account.public_key,
|
||||
}
|
||||
.derive(U31::new(opaque_account.address_index).expect("unreachable"))
|
||||
.expect("unreachable")
|
||||
.public_key;
|
||||
|
||||
opaque_account.address_index += 1;
|
||||
|
||||
Ok(next_address.to_base58())
|
||||
} else {
|
||||
Err(DubpError::OpaqueAccountNotLoaded)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_mnemonic(
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => Ok(mnemonic.phrase().to_owned()),
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn load_opaque_bip32_accounts(
|
||||
accounts_indexs: Vec<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
) -> Result<(), DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
for account_index in accounts_indexs {
|
||||
let external_path = PrivateDerivationPath::opaque(account_index, true, None)?;
|
||||
let external_kp = master_keypair.derive(external_path);
|
||||
let opaque_account = OpaqueAccount {
|
||||
address_index: 0,
|
||||
public_key: external_kp.public_key(),
|
||||
chain_code: external_kp.chain_code(),
|
||||
};
|
||||
|
||||
let mut guard = CHAINING_EXTERNAL_PUBKEYS.lock();
|
||||
guard.insert(account_index.into_u32(), opaque_account);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn sign_bip32(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
msg: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
if account_index == 0 {
|
||||
verify_member_secret_code(currency, dewif, secret_code)?;
|
||||
}
|
||||
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
sign_bip32_inner(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
external_opt,
|
||||
master_keypair,
|
||||
msg,
|
||||
)
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn sign_several_bip32(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
external_opt: Option<bool>,
|
||||
secret_code: &str,
|
||||
msgs: &[&str],
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
|
||||
if account_index == 0 {
|
||||
verify_member_secret_code(currency, dewif, secret_code)?;
|
||||
}
|
||||
|
||||
match payload {
|
||||
DewifPayload::Bip32Ed25519(mnemonic) => {
|
||||
let master_keypair = KeyPair::from_mnemonic(&mnemonic);
|
||||
sign_several_bip32_inner(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
external_opt,
|
||||
master_keypair,
|
||||
msgs,
|
||||
)
|
||||
}
|
||||
_ => Err(DubpError::NotHdWallet),
|
||||
}
|
||||
}
|
||||
|
||||
fn sign_bip32_inner(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
external_opt: Option<bool>,
|
||||
master_keypair: KeyPair,
|
||||
msg: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
Ok(master_keypair
|
||||
.derive(z_get_derivation_path(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
external_opt,
|
||||
)?)
|
||||
.generate_signator()
|
||||
.sign(msg.as_bytes())
|
||||
.to_base64())
|
||||
}
|
||||
|
||||
fn sign_several_bip32_inner(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
external_opt: Option<bool>,
|
||||
master_keypair: KeyPair,
|
||||
msgs: &[&str],
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let signator = master_keypair
|
||||
.derive(z_get_derivation_path(
|
||||
account_index,
|
||||
address_index_opt,
|
||||
external_opt,
|
||||
)?)
|
||||
.generate_signator();
|
||||
|
||||
Ok(msgs
|
||||
.iter()
|
||||
.map(|msg| signator.sign(msg.as_bytes()).to_base64())
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn verify_member_secret_code(
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
) -> Result<(), DubpError> {
|
||||
if crate::secret_code::is_ascii_letters(secret_code) {
|
||||
let log_n = dubp_client::crypto::dewif::read_dewif_log_n(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
let expected_secret_code_len =
|
||||
crate::secret_code::compute_secret_code_len(true, SecretCodeType::Letters, log_n)?;
|
||||
|
||||
if secret_code.len() < expected_secret_code_len {
|
||||
Err(DubpError::SecretCodeTooShort)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
} else {
|
||||
Err(DubpError::InvalidSecretCodeType)
|
||||
}
|
||||
}
|
||||
|
||||
fn z_get_derivation_path(
|
||||
account_index: u32,
|
||||
address_index_opt: Option<U31>,
|
||||
external_opt: Option<bool>,
|
||||
) -> Result<PrivateDerivationPath, DubpError> {
|
||||
let account_index_u31 = U31::new(account_index)?;
|
||||
match account_index % 3 {
|
||||
0 => Ok(PrivateDerivationPath::transparent(account_index_u31)?),
|
||||
1 => {
|
||||
if let Some(external) = external_opt {
|
||||
if external {
|
||||
if address_index_opt.is_none() {
|
||||
Ok(PrivateDerivationPath::semi_opaque_external(
|
||||
account_index_u31,
|
||||
)?)
|
||||
} else {
|
||||
Err(DubpError::InvalidAccountIndex(InvalidAccountIndex))
|
||||
}
|
||||
} else if address_index_opt.is_some() {
|
||||
Ok(PrivateDerivationPath::semi_opaque_internal(
|
||||
account_index_u31,
|
||||
address_index_opt,
|
||||
)?)
|
||||
} else {
|
||||
Err(DubpError::TryToSignWithInternalChainingAddress)
|
||||
}
|
||||
} else {
|
||||
Err(DubpError::MissingExternalBool)
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
if address_index_opt.is_some() {
|
||||
if let Some(external) = external_opt {
|
||||
Ok(PrivateDerivationPath::opaque(
|
||||
account_index_u31,
|
||||
external,
|
||||
address_index_opt,
|
||||
)?)
|
||||
} else {
|
||||
Err(DubpError::MissingExternalBool)
|
||||
}
|
||||
} else {
|
||||
Err(DubpError::TryToSignWithChainingAddress)
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use assert_matches::assert_matches;
|
||||
|
||||
const MNEMONIC: &str =
|
||||
"tongue cute mail fossil great frozen same social weasel impact brush kind";
|
||||
|
||||
#[test]
|
||||
fn test_get_accounts_pubkeys() -> Result<(), DubpError> {
|
||||
let vec = crate::dewif::gen_dewif(
|
||||
"g1",
|
||||
Language::English,
|
||||
MNEMONIC,
|
||||
false,
|
||||
SecretCodeType::Letters,
|
||||
1_000,
|
||||
)?;
|
||||
let dewif = &vec[0];
|
||||
let secret_code = &vec[1];
|
||||
//println!("TMP: secret_code={}", secret_code);
|
||||
|
||||
assert_matches!(
|
||||
get_accounts_pubkeys(
|
||||
Currency::from(G1_CURRENCY),
|
||||
dewif,
|
||||
secret_code,
|
||||
vec![U31::new(0).expect("unreachable")],
|
||||
),
|
||||
Err(DubpError::SecretCodeTooShort)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sign_bip32() {
|
||||
assert_matches!(
|
||||
z_get_derivation_path(1, None, None),
|
||||
Err(DubpError::MissingExternalBool)
|
||||
);
|
||||
assert_matches!(
|
||||
z_get_derivation_path(2, None, None),
|
||||
Err(DubpError::TryToSignWithChainingAddress)
|
||||
);
|
||||
assert_matches!(z_get_derivation_path(3, None, None), Ok(_));
|
||||
assert_matches!(
|
||||
z_get_derivation_path(1, None, Some(false)),
|
||||
Err(DubpError::TryToSignWithInternalChainingAddress)
|
||||
);
|
||||
assert_matches!(
|
||||
z_get_derivation_path(2, None, Some(true)),
|
||||
Err(DubpError::TryToSignWithChainingAddress)
|
||||
);
|
||||
assert_matches!(
|
||||
z_get_derivation_path(1, Some(U31::new(5).expect("unreachable")), Some(true),),
|
||||
Err(DubpError::InvalidAccountIndex(_))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub(crate) fn sign(
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
msg: &str,
|
||||
) -> Result<String, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
if let DewifPayload::Ed25519(keypair) = payload {
|
||||
Ok(keypair.generate_signator().sign(msg.as_bytes()).to_base64())
|
||||
} else {
|
||||
Err(DubpError::DewifReadError(DewifReadError::CorruptedContent))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn sign_several(
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
secret_code: &str,
|
||||
msgs: &[&str],
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let DewifContent { payload, .. } = dubp_client::crypto::dewif::read_dewif_content(
|
||||
ExpectedCurrency::Specific(currency),
|
||||
dewif,
|
||||
&secret_code.to_ascii_uppercase(),
|
||||
)
|
||||
.map_err(DubpError::DewifReadError)?;
|
||||
if let DewifPayload::Ed25519(keypair) = payload {
|
||||
let signator = keypair.generate_signator();
|
||||
Ok(msgs
|
||||
.iter()
|
||||
.map(|msg| signator.sign(msg.as_bytes()).to_base64())
|
||||
.collect())
|
||||
} else {
|
||||
Err(DubpError::DewifReadError(DewifReadError::CorruptedContent))
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// Dubp error
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Debug, Error)]
|
||||
pub(crate) enum DubpError {
|
||||
#[error("{0}")]
|
||||
DewifReadError(DewifReadError),
|
||||
#[error("Digits secret code forbid for member wallet")]
|
||||
DigitsCodeForbidForMemberWallet,
|
||||
#[error("It is forbidden to retrieve the master public key of an HD wallet.")]
|
||||
GetMasterPubkeyOfHdWallet,
|
||||
#[error("Give external bool or address index for legacy wallet.")]
|
||||
GiveExternalBoolOrAddressIndexForLegacyWallet,
|
||||
#[error("{0}")]
|
||||
GvaClientError(dubp_client::GvaClientError),
|
||||
#[error("I/O error: {0}")]
|
||||
IoErr(io::Error),
|
||||
#[error("{0}")]
|
||||
InvalidAccountIndex(InvalidAccountIndex),
|
||||
#[error("{0}")]
|
||||
InvalidPubkey(PublicKeyFromStrErr),
|
||||
#[error("{0}")]
|
||||
InvalidScript(dubp_client::documents_parser::TextParseError),
|
||||
#[error("{0}")]
|
||||
InvalidU31(U31Error),
|
||||
#[error("Invalid secret code type")]
|
||||
InvalidSecretCodeType,
|
||||
#[error("Missing external bool")]
|
||||
MissingExternalBool,
|
||||
#[error("this wallet is not an HD wallet")]
|
||||
NotHdWallet,
|
||||
#[error("A given parameter is null")]
|
||||
NullParamErr,
|
||||
#[error("Opaque account not loaded")]
|
||||
OpaqueAccountNotLoaded,
|
||||
#[error("Payment error: {0}")]
|
||||
PaymentError(String),
|
||||
#[error("Secret code too short: please change your secret code")]
|
||||
SecretCodeTooShort,
|
||||
#[error("The chaining address cannot be used to sign with opaque account")]
|
||||
TryToSignWithChainingAddress,
|
||||
#[error("The internal chaining address cannot be used to sign with semi-opaque account")]
|
||||
TryToSignWithInternalChainingAddress,
|
||||
#[error("fail to generate random bytes")]
|
||||
RandErr,
|
||||
#[error("Unknown currency name")]
|
||||
UnknownCurrencyName,
|
||||
#[error("Unknown language")]
|
||||
UnknownLanguage,
|
||||
//#[error("Unsupported DEWIF version")]
|
||||
//UnsupportedDewifVersion,
|
||||
#[error("{0}")]
|
||||
Utf8Error(std::str::Utf8Error),
|
||||
#[error("Wrong language")]
|
||||
WrongLanguage,
|
||||
}
|
||||
|
||||
impl From<io::Error> for DubpError {
|
||||
fn from(e: io::Error) -> Self {
|
||||
Self::IoErr(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InvalidAccountIndex> for DubpError {
|
||||
fn from(e: InvalidAccountIndex) -> Self {
|
||||
Self::InvalidAccountIndex(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<U31Error> for DubpError {
|
||||
fn from(e: U31Error) -> Self {
|
||||
Self::InvalidU31(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct DartRes(allo_isolate::ffi::DartCObject);
|
||||
impl DartRes {
|
||||
pub(crate) fn err<E: ToString>(e: E) -> allo_isolate::ffi::DartCObject {
|
||||
vec![format!("DUBP_RS_ERROR: {}", e.to_string())].into_dart()
|
||||
}
|
||||
}
|
||||
impl IntoDart for DartRes {
|
||||
fn into_dart(self) -> allo_isolate::ffi::DartCObject {
|
||||
self.0.into_dart()
|
||||
}
|
||||
}
|
||||
impl<E> From<Result<(), E>> for DartRes
|
||||
where
|
||||
E: ToString,
|
||||
{
|
||||
fn from(res: Result<(), E>) -> Self {
|
||||
match res {
|
||||
Ok(()) => Self("".into_dart()),
|
||||
Err(e) => Self(format!("DUBP_RS_ERROR: {}", e.to_string()).into_dart()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<E> From<Result<String, E>> for DartRes
|
||||
where
|
||||
E: ToString,
|
||||
{
|
||||
fn from(res: Result<String, E>) -> Self {
|
||||
match res {
|
||||
Ok(string) => Self(string.into_dart()),
|
||||
Err(e) => Self(format!("DUBP_RS_ERROR: {}", e.to_string()).into_dart()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<E> From<Result<Vec<String>, E>> for DartRes
|
||||
where
|
||||
E: ToString,
|
||||
{
|
||||
fn from(res: Result<Vec<String>, E>) -> Self {
|
||||
match res {
|
||||
Ok(vec_string) => Self(vec_string.into_dart()),
|
||||
Err(e) => Self(vec![format!("DUBP_RS_ERROR: {}", e.to_string())].into_dart()),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum SecretCodeType {
|
||||
Digits,
|
||||
Letters,
|
||||
}
|
||||
impl From<u32> for SecretCodeType {
|
||||
fn from(i: u32) -> Self {
|
||||
if i == 0 {
|
||||
SecretCodeType::Digits
|
||||
} else {
|
||||
SecretCodeType::Letters
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum WalletType {
|
||||
Ed25519,
|
||||
Bip32Ed25519,
|
||||
}
|
||||
impl From<u32> for WalletType {
|
||||
fn from(i: u32) -> Self {
|
||||
if i == 1 {
|
||||
WalletType::Bip32Ed25519
|
||||
} else {
|
||||
WalletType::Ed25519
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn char_ptr_to_str<'a>(c_char_ptr: *const raw::c_char) -> Result<&'a str, DubpError> {
|
||||
if c_char_ptr.is_null() {
|
||||
Err(DubpError::NullParamErr)
|
||||
} else {
|
||||
unsafe { CStr::from_ptr(c_char_ptr).to_str() }.map_err(DubpError::Utf8Error)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn char_ptr_to_opt_string(
|
||||
c_char_ptr: *const raw::c_char,
|
||||
) -> Result<Option<String>, DubpError> {
|
||||
Ok(if c_char_ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
unsafe { CStr::from_ptr(c_char_ptr).to_str() }
|
||||
.map_err(DubpError::Utf8Error)?
|
||||
.to_owned(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn char_ptr_prt_to_vec_u31(
|
||||
u32_ptr: *const u32,
|
||||
len: u32,
|
||||
) -> Result<Vec<U31>, DubpError> {
|
||||
u32_ptr_to_vec_u32(u32_ptr, len)
|
||||
.into_iter()
|
||||
.map(|ai| U31::new(ai).map_err(DubpError::InvalidU31))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn char_ptr_prt_to_vec_str<'a>(
|
||||
char_ptr_ptr: *const *const raw::c_char,
|
||||
len: u32,
|
||||
) -> Result<Vec<&'a str>, DubpError> {
|
||||
let len = len as usize;
|
||||
let char_ptr_slice: &[*const raw::c_char] =
|
||||
unsafe { std::slice::from_raw_parts(char_ptr_ptr, len) };
|
||||
let mut str_vec = Vec::with_capacity(len);
|
||||
for char_ptr in char_ptr_slice {
|
||||
str_vec.push(char_ptr_to_str(*char_ptr)?);
|
||||
}
|
||||
Ok(str_vec)
|
||||
}
|
||||
|
||||
pub(crate) fn i32_to_opt_bool(i: i32) -> Option<bool> {
|
||||
match i {
|
||||
1 => Some(true),
|
||||
0 => Some(false),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn i32_to_opt_u31(i: i32) -> Result<Option<U31>, DubpError> {
|
||||
if i >= 0 {
|
||||
Ok(Some(U31::new(i as u32)?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn i32_to_opt_u32(i: i32) -> Option<u32> {
|
||||
if i >= 0 {
|
||||
Some(i as u32)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_currency(currency: &str) -> Result<Currency, DubpError> {
|
||||
let currency_code = match currency {
|
||||
"g1" => G1_CURRENCY,
|
||||
"g1-test" | "gt" => G1_TEST_CURRENCY,
|
||||
_ => return Err(DubpError::UnknownCurrencyName),
|
||||
};
|
||||
Ok(Currency::from(currency_code))
|
||||
}
|
||||
|
||||
pub(crate) fn u32_ptr_to_vec_u32(u32_ptr: *const u32, len: u32) -> Vec<u32> {
|
||||
let len = len as usize;
|
||||
let u32_slice: &[u32] = unsafe { std::slice::from_raw_parts(u32_ptr, len) };
|
||||
let mut vec = Vec::with_capacity(len);
|
||||
for u32_ in u32_slice {
|
||||
vec.push(*u32_);
|
||||
}
|
||||
vec
|
||||
}
|
||||
|
||||
pub(crate) fn u32_to_language(i: u32) -> Result<Language, DubpError> {
|
||||
match i {
|
||||
0 => Ok(Language::English),
|
||||
1 => Ok(Language::French),
|
||||
_ => Err(DubpError::UnknownLanguage),
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
use dubp_client::crypto::keys::ed25519::{KeyPairFromSaltedPasswordGenerator, SaltedPassword};
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub(super) fn gen_dewif_from_legacy(
|
||||
currency: &str,
|
||||
salt: String,
|
||||
password: String,
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
system_memory: i64,
|
||||
) -> Result<Vec<String>, DubpError> {
|
||||
let currency = parse_currency(currency)?;
|
||||
let keypair = KeyPairFromSaltedPasswordGenerator::with_default_parameters()
|
||||
.generate(SaltedPassword::new(salt.clone(), password.clone()));
|
||||
|
||||
let log_n = crate::dewif::log_n(system_memory);
|
||||
let secret_code = gen_secret_code(member_wallet, secret_code_type, log_n)?;
|
||||
let dewif = dubp_client::crypto::dewif::create_dewif_v1_legacy(
|
||||
currency,
|
||||
log_n,
|
||||
password,
|
||||
salt,
|
||||
&secret_code,
|
||||
)
|
||||
.map_err(|_| DubpError::RandErr)?;
|
||||
let pubkey = keypair.public_key().to_base58();
|
||||
Ok(vec![dewif, secret_code, pubkey])
|
||||
}
|
||||
|
||||
pub(super) fn get_pubkey(salt: &str, password: &str) -> String {
|
||||
KeyPairFromSaltedPasswordGenerator::with_default_parameters()
|
||||
.generate(SaltedPassword::new(salt.to_owned(), password.to_owned()))
|
||||
.public_key()
|
||||
.to_base58()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_dewif_legacy() -> Result<(), DubpError> {
|
||||
let wallet = gen_dewif_from_legacy(
|
||||
"g1",
|
||||
"salt".to_owned(),
|
||||
"pass".to_owned(),
|
||||
false,
|
||||
SecretCodeType::Letters,
|
||||
1_000_000_000,
|
||||
)?;
|
||||
let dewif = &wallet[0];
|
||||
let secret_code = &wallet[1];
|
||||
let pubkey = &wallet[2];
|
||||
|
||||
assert_eq!(pubkey, "3YumN7F7D8c2hmkHLHf3ZD8wc3tBHiECEK9zLPkaJtAF");
|
||||
|
||||
assert_eq!(get_pubkey("salt", "pass"), pubkey.to_owned());
|
||||
|
||||
assert_eq!(
|
||||
crate::dewif::get_pubkey(
|
||||
None,
|
||||
None,
|
||||
Currency::from(G1_CURRENCY),
|
||||
&dewif,
|
||||
None,
|
||||
&secret_code
|
||||
)?,
|
||||
pubkey.to_owned()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,536 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(clippy::missing_safety_doc, clippy::not_unsafe_ptr_arg_deref)]
|
||||
|
||||
mod r#async;
|
||||
mod dewif;
|
||||
mod error;
|
||||
mod inputs;
|
||||
mod legacy;
|
||||
mod mnemonic;
|
||||
mod payment;
|
||||
mod pubkey;
|
||||
mod secret_code;
|
||||
|
||||
use crate::error::{DartRes, DubpError};
|
||||
use crate::inputs::*;
|
||||
use crate::r#async::exec_async;
|
||||
use crate::secret_code::gen_secret_code;
|
||||
use allo_isolate::{IntoDart, Isolate};
|
||||
use dubp_client::crypto::{
|
||||
bases::b58::ToBase58,
|
||||
dewif::{
|
||||
Currency, DewifContent, DewifPayload, DewifReadError, ExpectedCurrency, G1_CURRENCY,
|
||||
G1_TEST_CURRENCY,
|
||||
},
|
||||
keys::{
|
||||
ed25519::bip32::{
|
||||
ChainCode, InvalidAccountIndex, KeyPair, PrivateDerivationPath, PublicKeyWithChainCode,
|
||||
},
|
||||
ed25519::{KeyPairFromSeed32Generator, PublicKey, PublicKeyFromStrErr},
|
||||
KeyPair as _, KeyPairEnum, KeysAlgo, PublicKey as _, Signator as _, Signature as _,
|
||||
},
|
||||
mnemonic::{Language, Mnemonic, MnemonicType},
|
||||
utils::{U31Error, U31},
|
||||
};
|
||||
use fast_threadpool::{ThreadPool, ThreadPoolConfig, ThreadPoolSyncHandler};
|
||||
use once_cell::sync::Lazy;
|
||||
use parking_lot::Mutex;
|
||||
use std::{collections::HashMap, ffi::CStr, io, os::raw, sync::Arc};
|
||||
use thiserror::Error;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn change_dewif_secret_code(
|
||||
port: i64,
|
||||
dewif: *const raw::c_char,
|
||||
old_secret_code: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
system_memory: i64,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let old_secret_code = char_ptr_to_str(old_secret_code)?;
|
||||
let member_wallet = member_wallet != 0;
|
||||
let secret_code_type = SecretCodeType::from(secret_code_type);
|
||||
Ok((
|
||||
dewif,
|
||||
old_secret_code,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
))
|
||||
},
|
||||
|(dewif, old_secret_code, member_wallet, secret_code_type, system_memory)| {
|
||||
dewif::change_secret_code(
|
||||
dewif,
|
||||
old_secret_code,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn check_pubkey(port: i64, pubkey: *const raw::c_char) {
|
||||
exec_async(port, || char_ptr_to_str(pubkey), pubkey::check_pubkey)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn compute_checksum(port: i64, pubkey: *const raw::c_char) {
|
||||
exec_async(port, || char_ptr_to_str(pubkey), pubkey::compute_checksum)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gen_dewif(
|
||||
port: i64,
|
||||
currency: *const raw::c_char,
|
||||
language: u32,
|
||||
mnemonic: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
system_memory: i64,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let currency = char_ptr_to_str(currency)?;
|
||||
let language = u32_to_language(language)?;
|
||||
let mnemonic = char_ptr_to_str(mnemonic)?;
|
||||
let member_wallet = member_wallet != 0;
|
||||
let secret_code_type = SecretCodeType::from(secret_code_type);
|
||||
Ok((
|
||||
currency,
|
||||
language,
|
||||
mnemonic,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
))
|
||||
},
|
||||
|(currency, language, mnemonic, member_wallet, secret_code_type, system_memory)| {
|
||||
dewif::gen_dewif(
|
||||
currency,
|
||||
language,
|
||||
mnemonic,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gen_dewif_from_legacy(
|
||||
port: i64,
|
||||
currency: *const raw::c_char,
|
||||
salt: *const raw::c_char,
|
||||
password: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
system_memory: i64,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let currency = char_ptr_to_str(currency)?;
|
||||
let salt = char_ptr_to_str(salt)?.to_owned();
|
||||
let password = char_ptr_to_str(password)?.to_owned();
|
||||
let member_wallet = member_wallet != 0;
|
||||
let secret_code_type = SecretCodeType::from(secret_code_type);
|
||||
Ok((
|
||||
currency,
|
||||
salt,
|
||||
password,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
))
|
||||
},
|
||||
|(currency, salt, password, member_wallet, secret_code_type, system_memory)| {
|
||||
legacy::gen_dewif_from_legacy(
|
||||
currency,
|
||||
salt,
|
||||
password,
|
||||
member_wallet,
|
||||
secret_code_type,
|
||||
system_memory,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn gen_mnemonic(port: i64, language: u32) {
|
||||
exec_async(port, || u32_to_language(language), mnemonic::gen_mnemonic)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_bip32_dewif_accounts_pubkeys(
|
||||
port: i64,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
secret_code: *const raw::c_char,
|
||||
accounts_indexs_len: u32,
|
||||
accounts_indexs: *const u32,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
let accounts_indexs = char_ptr_prt_to_vec_u31(accounts_indexs, accounts_indexs_len)?;
|
||||
Ok((currency, dewif, secret_code, accounts_indexs))
|
||||
},
|
||||
|(currency, dewif, secret_code, accounts_indexs)| {
|
||||
dewif::bip32::get_accounts_pubkeys(currency, dewif, secret_code, accounts_indexs)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_bip32_dewif_mnemonic(
|
||||
port: i64,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
secret_code: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
Ok((currency, dewif, secret_code))
|
||||
},
|
||||
|(currency, dewif, secret_code)| dewif::bip32::get_mnemonic(currency, dewif, secret_code),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_dewif_meta(
|
||||
port: i64,
|
||||
dewif: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let member_wallet = member_wallet != 0;
|
||||
let secret_code_type = SecretCodeType::from(secret_code_type);
|
||||
Ok((dewif, member_wallet, secret_code_type))
|
||||
},
|
||||
|(dewif, member_wallet, secret_code_type)| {
|
||||
dewif::get_dewif_meta(dewif, member_wallet, secret_code_type)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_dewif_secret_code_len(
|
||||
dewif: *const raw::c_char,
|
||||
member_wallet: u32,
|
||||
secret_code_type: u32,
|
||||
) -> i32 {
|
||||
if let Ok(secret_code_len) = dewif::get_secret_code_len(dewif, member_wallet, secret_code_type)
|
||||
{
|
||||
secret_code_len as i32
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_dewif_pubkey(
|
||||
port: i64,
|
||||
account_index: i32,
|
||||
address_index: i32,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
external_opt: i32,
|
||||
pin: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let account_index_opt = i32_to_opt_u32(account_index);
|
||||
let address_index_opt = i32_to_opt_u31(address_index)?;
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let external_opt = i32_to_opt_bool(external_opt);
|
||||
let pin = char_ptr_to_str(pin)?;
|
||||
Ok((
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
pin,
|
||||
))
|
||||
},
|
||||
|(account_index_opt, address_index_opt, currency, dewif, external_opt, pin)| {
|
||||
dewif::get_pubkey(
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
pin,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_opaque_account_next_external_address(port: i64, account_index: u32) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let account_index = U31::new(account_index)?;
|
||||
Ok(account_index)
|
||||
},
|
||||
dewif::bip32::get_opaque_account_next_external_address,
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn load_opaque_bip32_accounts(
|
||||
port: i64,
|
||||
accounts_indexs_len: u32,
|
||||
accounts_indexs: *const u32,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
secret_code: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let accounts_indexs = char_ptr_prt_to_vec_u31(accounts_indexs, accounts_indexs_len)?;
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
Ok((accounts_indexs, currency, dewif, secret_code))
|
||||
},
|
||||
|(accounts_indexs, currency, dewif, secret_code)| {
|
||||
dewif::bip32::load_opaque_bip32_accounts(accounts_indexs, currency, dewif, secret_code)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_legacy_pubkey(
|
||||
port: i64,
|
||||
salt: *const raw::c_char,
|
||||
password: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let salt = char_ptr_to_str(salt)?;
|
||||
let password = char_ptr_to_str(password)?;
|
||||
Ok((salt, password))
|
||||
},
|
||||
|(salt, password)| Ok::<_, DubpError>(legacy::get_pubkey(salt, password)),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mnemonic_to_pubkey(
|
||||
port: i64,
|
||||
language: u32,
|
||||
mnemonic_phrase: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let language = u32_to_language(language)?;
|
||||
let mnemonic_phrase = char_ptr_to_str(mnemonic_phrase)?;
|
||||
Ok((language, mnemonic_phrase))
|
||||
},
|
||||
|(language, mnemonic_phrase)| mnemonic::mnemonic_to_pubkey(language, mnemonic_phrase),
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sign(
|
||||
port: i64,
|
||||
account_index: i32,
|
||||
address_index: i32,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
external_opt: i32,
|
||||
secret_code: *const raw::c_char,
|
||||
msg: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let account_index_opt = i32_to_opt_u32(account_index);
|
||||
let address_index_opt = i32_to_opt_u31(address_index)?;
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let external_opt = i32_to_opt_bool(external_opt);
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
let msg = char_ptr_to_str(msg)?;
|
||||
Ok((
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msg,
|
||||
))
|
||||
},
|
||||
|(
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msg,
|
||||
)| {
|
||||
dewif::sign(
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msg,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sign_several(
|
||||
port: i64,
|
||||
account_index: i32,
|
||||
address_index: i32,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
external_opt: i32,
|
||||
secret_code: *const raw::c_char,
|
||||
msgs_len: u32,
|
||||
msgs: *const *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let account_index_opt = i32_to_opt_u32(account_index);
|
||||
let address_index_opt = i32_to_opt_u31(address_index)?;
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let external_opt = i32_to_opt_bool(external_opt);
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
let msgs = char_ptr_prt_to_vec_str(msgs, msgs_len)?;
|
||||
Ok((
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msgs,
|
||||
))
|
||||
},
|
||||
|(
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
msgs,
|
||||
)| {
|
||||
dewif::sign_several(
|
||||
account_index_opt,
|
||||
address_index_opt,
|
||||
currency,
|
||||
dewif,
|
||||
external_opt,
|
||||
secret_code,
|
||||
&msgs,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn simple_payment_bip32(
|
||||
port: i64,
|
||||
account_index: u32,
|
||||
amount: f64,
|
||||
currency: *const raw::c_char,
|
||||
dewif: *const raw::c_char,
|
||||
gva_endpoint: *const raw::c_char,
|
||||
recipient: *const raw::c_char,
|
||||
secret_code: *const raw::c_char,
|
||||
tx_comment: *const raw::c_char,
|
||||
) {
|
||||
exec_async(
|
||||
port,
|
||||
|| {
|
||||
let currency = parse_currency(char_ptr_to_str(currency)?)?;
|
||||
let dewif = char_ptr_to_str(dewif)?;
|
||||
let gva_endpoint = char_ptr_to_str(gva_endpoint)?;
|
||||
let recipient = char_ptr_to_str(recipient)?;
|
||||
let secret_code = char_ptr_to_str(secret_code)?;
|
||||
let tx_comment = char_ptr_to_opt_string(tx_comment)?;
|
||||
Ok((
|
||||
account_index,
|
||||
amount,
|
||||
currency,
|
||||
dewif,
|
||||
gva_endpoint,
|
||||
secret_code,
|
||||
recipient,
|
||||
tx_comment,
|
||||
))
|
||||
},
|
||||
|(
|
||||
account_index,
|
||||
amount,
|
||||
currency,
|
||||
dewif,
|
||||
gva_endpoint,
|
||||
secret_code,
|
||||
recipient,
|
||||
tx_comment,
|
||||
)| {
|
||||
payment::simple_payment(
|
||||
account_index,
|
||||
amount,
|
||||
currency,
|
||||
dewif,
|
||||
gva_endpoint,
|
||||
secret_code,
|
||||
recipient,
|
||||
tx_comment,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub(super) fn gen_mnemonic(language: Language) -> Result<String, DubpError> {
|
||||
let mnemonic =
|
||||
Mnemonic::new(MnemonicType::Words12, language).map_err(|_| DubpError::RandErr)?;
|
||||
Ok(mnemonic.phrase().to_owned())
|
||||
}
|
||||
|
||||
pub(super) fn mnemonic_to_pubkey(language: Language, mnemonic: &str) -> Result<String, DubpError> {
|
||||
let mnemonic =
|
||||
Mnemonic::from_phrase(mnemonic, language).map_err(|_| DubpError::WrongLanguage)?;
|
||||
let seed = dubp_client::crypto::mnemonic::mnemonic_to_seed(&mnemonic);
|
||||
let keypair = KeyPairFromSeed32Generator::generate(seed);
|
||||
Ok(keypair.public_key().to_base58())
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
use dubp_client::wallet::prelude::*;
|
||||
use dubp_client::{GvaClient, NaiveGvaClient};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn simple_payment(
|
||||
account_index: u32,
|
||||
amount: f64,
|
||||
currency: Currency,
|
||||
dewif: &str,
|
||||
gva_endpoint: &str,
|
||||
secret_code: &str,
|
||||
recipient: &str,
|
||||
tx_comment: Option<String>,
|
||||
) -> Result<(), DubpError> {
|
||||
let keypair = crate::dewif::bip32::get_bip32_keypair(
|
||||
account_index,
|
||||
None,
|
||||
currency,
|
||||
dewif,
|
||||
None,
|
||||
secret_code,
|
||||
)?;
|
||||
|
||||
let gva_client = NaiveGvaClient::new(gva_endpoint).expect("invalid' endpoint");
|
||||
|
||||
let amount = dubp_client::Amount::Uds(amount);
|
||||
|
||||
let recipient = if let Ok(pubkey) = PublicKey::from_base58(recipient) {
|
||||
WalletScriptV10::single_sig(pubkey)
|
||||
} else {
|
||||
dubp_client::documents_parser::wallet_script_from_str(recipient)
|
||||
.map_err(DubpError::InvalidScript)?
|
||||
};
|
||||
|
||||
let res = match keypair.generate_signator() {
|
||||
dubp_client::crypto::keys::SignatorEnum::Ed25519(signator) => gva_client
|
||||
.simple_payment(amount, &signator, recipient, tx_comment, None)
|
||||
.map_err(DubpError::GvaClientError)?,
|
||||
dubp_client::crypto::keys::SignatorEnum::Schnorr() => unreachable!(),
|
||||
dubp_client::crypto::keys::SignatorEnum::Bip32Ed25519(signator) => gva_client
|
||||
.simple_payment(amount, &signator, recipient, tx_comment, None)
|
||||
.map_err(DubpError::GvaClientError)?,
|
||||
};
|
||||
|
||||
if let dubp_client::PaymentResult::Errors(errors) = res {
|
||||
Err(DubpError::PaymentError(format!("{:?}", errors)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub(crate) fn check_pubkey(pubkey: &str) -> Result<(), DubpError> {
|
||||
PublicKey::from_base58_with_checksum_opt(pubkey).map_err(DubpError::InvalidPubkey)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn compute_checksum(pubkey: &str) -> Result<String, DubpError> {
|
||||
Ok(PublicKey::from_base58(pubkey)
|
||||
.map_err(|e| DubpError::InvalidPubkey(PublicKeyFromStrErr::BaseConversionError(e)))?
|
||||
.checksum())
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::*;
|
||||
|
||||
pub(crate) fn compute_secret_code_len(
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
log_n: u8,
|
||||
) -> Result<usize, DubpError> {
|
||||
match secret_code_type {
|
||||
SecretCodeType::Digits => {
|
||||
if member_wallet {
|
||||
Err(DubpError::DigitsCodeForbidForMemberWallet)
|
||||
} else if log_n >= 15 {
|
||||
Ok(7)
|
||||
} else {
|
||||
Ok(8)
|
||||
}
|
||||
}
|
||||
SecretCodeType::Letters => {
|
||||
if member_wallet {
|
||||
if log_n >= 15 {
|
||||
Ok(7)
|
||||
} else {
|
||||
Ok(8)
|
||||
}
|
||||
} else if log_n >= 15 {
|
||||
Ok(5)
|
||||
} else {
|
||||
Ok(6)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn gen_secret_code(
|
||||
member_wallet: bool,
|
||||
secret_code_type: SecretCodeType,
|
||||
log_n: u8,
|
||||
) -> Result<String, DubpError> {
|
||||
let secret_code_len = compute_secret_code_len(member_wallet, secret_code_type, log_n)?;
|
||||
match secret_code_type {
|
||||
SecretCodeType::Digits => gen_random_digits(secret_code_len),
|
||||
SecretCodeType::Letters => gen_random_letters(secret_code_len),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_ascii_letters(secret_code: &str) -> bool {
|
||||
secret_code.len()
|
||||
== secret_code
|
||||
.chars()
|
||||
.filter(|char| char.is_ascii_alphabetic())
|
||||
.count()
|
||||
}
|
||||
|
||||
fn gen_random_digits(n: usize) -> Result<String, DubpError> {
|
||||
let mut digits_string = dubp_client::crypto::rand::gen_u32()
|
||||
.map_err(|_| DubpError::RandErr)?
|
||||
.to_string();
|
||||
digits_string.truncate(n);
|
||||
|
||||
if digits_string.len() == n {
|
||||
Ok(digits_string)
|
||||
} else {
|
||||
let missing_digits = n - digits_string.len();
|
||||
let mut digits_string_ = String::with_capacity(n);
|
||||
for _ in 0..missing_digits {
|
||||
digits_string_.push('0');
|
||||
}
|
||||
digits_string_.push_str(&digits_string);
|
||||
Ok(digits_string_)
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_random_letters(mut n: usize) -> Result<String, DubpError> {
|
||||
let mut letters = String::with_capacity(n);
|
||||
while n >= 6 {
|
||||
letters.push_str(&gen_random_letters_inner(6)?);
|
||||
n -= 6;
|
||||
}
|
||||
letters.push_str(&gen_random_letters_inner(n)?);
|
||||
|
||||
Ok(letters)
|
||||
}
|
||||
|
||||
fn gen_random_letters_inner(n: usize) -> Result<String, DubpError> {
|
||||
let mut i = dubp_client::crypto::rand::gen_u32().map_err(|_| DubpError::RandErr)?;
|
||||
let mut letters = String::new();
|
||||
|
||||
for _ in 0..n {
|
||||
letters.push(to_char(i));
|
||||
i /= 26;
|
||||
}
|
||||
|
||||
Ok(letters)
|
||||
}
|
||||
|
||||
fn to_char(i: u32) -> char {
|
||||
match i % 26 {
|
||||
0 => 'A',
|
||||
1 => 'B',
|
||||
2 => 'C',
|
||||
3 => 'D',
|
||||
4 => 'E',
|
||||
5 => 'F',
|
||||
6 => 'G',
|
||||
7 => 'H',
|
||||
8 => 'I',
|
||||
9 => 'J',
|
||||
10 => 'K',
|
||||
11 => 'L',
|
||||
12 => 'M',
|
||||
13 => 'N',
|
||||
14 => 'O',
|
||||
15 => 'P',
|
||||
16 => 'Q',
|
||||
17 => 'R',
|
||||
18 => 'S',
|
||||
19 => 'T',
|
||||
20 => 'U',
|
||||
21 => 'V',
|
||||
22 => 'W',
|
||||
23 => 'X',
|
||||
24 => 'Y',
|
||||
25 => 'Z',
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_gen_random_digits() -> Result<(), DubpError> {
|
||||
assert_eq!(gen_random_digits(8)?.len(), 8);
|
||||
//println!("TMP: {}", gen_random_digits(8)?);
|
||||
Ok(())
|
||||
}
|
||||
#[test]
|
||||
fn test_gen_random_letters() -> Result<(), DubpError> {
|
||||
assert_eq!(gen_random_letters(6)?.len(), 6);
|
||||
//println!("TMP: {}", gen_random_letters(6)?);
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: f7a6a7906be96d2288f5d63a5a54c515a6e987fe
|
||||
channel: stable
|
||||
|
||||
project_type: plugin
|
|
@ -1,661 +0,0 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
|
@ -1,198 +0,0 @@
|
|||
# dubp
|
||||
|
||||
Flutter package that bind [dubp-rs-libs] Rust crates.
|
||||
|
||||
## Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* Android SDK
|
||||
* Android **N**DK (**Native** Development Kit)
|
||||
* Rust and cargo
|
||||
* Cargo plugin cargo-make: `cargo install cargo-make`
|
||||
* LLVM/Clang (see dedicated section below)
|
||||
|
||||
You must indicate where the SDK and NDK are located via the `ANDROID_SDK_ROOT` and `ANDROID_NDK_HOME` environment variables.
|
||||
For example:
|
||||
|
||||
export ANDROID_SDK_ROOT="/home/user/dev/android_sdk"
|
||||
export ANDROID_NDK_HOME="/home/user/dev/android_sdk/ndk/22.0.7026061"
|
||||
|
||||
You will also need to add targets for all Android architectures:
|
||||
|
||||
```sh
|
||||
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
|
||||
```
|
||||
|
||||
If you develop on mac, you can also add targets for iOS:
|
||||
|
||||
```sh
|
||||
rustup target add aarch64-apple-ios x86_64-apple-ios
|
||||
```
|
||||
|
||||
### LLVM/Clang
|
||||
|
||||
The project use [`dart-bindgen`](https://github.com/sunshine-protocol/dart-bindgen) which requires LLVM/Clang. Install LLVM (10+) in the following way:
|
||||
|
||||
#### ubuntu/linux
|
||||
|
||||
1. Install libclangdev - `sudo apt-get install libclang-dev`.
|
||||
|
||||
#### Windows
|
||||
|
||||
1. Install Visual Studio with C++ development support.
|
||||
2. Install [LLVM](https://releases.llvm.org/download.html) or `winget install -e --id LLVM.LLVM`.
|
||||
|
||||
#### MacOS
|
||||
|
||||
1. Install Xcode.
|
||||
2. Install LLVM - `brew install llvm`.
|
||||
|
||||
## Compile
|
||||
|
||||
### For development
|
||||
|
||||
**To reduce the compilation time of the Rust code** during your development, you can **compile only for the target corresponding to your android emulator**. Here is how to do it **depending on the architecture of your emulator**:
|
||||
|
||||
* 32bit emulator (`x86`/`i686` architecture)
|
||||
|
||||
```sh
|
||||
cargo bd
|
||||
```
|
||||
|
||||
* 64bit emulator (`x86_64` architecture)
|
||||
|
||||
```sh
|
||||
cargo make android-dev
|
||||
```
|
||||
|
||||
### For release
|
||||
|
||||
In the Root of the project simply run:
|
||||
|
||||
```sh
|
||||
cargo br
|
||||
```
|
||||
|
||||
WARNING: This will take a lot of time because the Rust code will have to be recompiled for each different architecture, 4 times for android and 2 times for iOS!
|
||||
|
||||
## Use
|
||||
|
||||
You must execute this instruction at startup of your application:
|
||||
|
||||
```dart
|
||||
DubpRust.setup();
|
||||
```
|
||||
|
||||
### Generate a random Mnemonic
|
||||
|
||||
#### Function signature
|
||||
|
||||
```dart
|
||||
static Future<String> DubpRust.genMnemonic({Language language = Language.english});
|
||||
```
|
||||
|
||||
#### Usage example
|
||||
|
||||
```dart
|
||||
String mnemonic = await DubpRust.genMnemonic();
|
||||
```
|
||||
|
||||
You can choose a language (english by default):
|
||||
|
||||
```dart
|
||||
String mnemonic = await DubpRust.genMnemonic(language: Language.french);
|
||||
```
|
||||
|
||||
### Generate a wallet
|
||||
|
||||
#### Function signature
|
||||
|
||||
```dart
|
||||
static Future<NewWallet> genWalletFromMnemonic({
|
||||
String currency = "g1",
|
||||
Language language = Language.english,
|
||||
String mnemonic,
|
||||
SecretCodeType secretCodeType = SecretCodeType.letters
|
||||
});
|
||||
```
|
||||
|
||||
If the mnemonic is not in english, you must indicate the language of the mnemonic (necessary for the verification of its validity).
|
||||
If the wallet to be generated is not dedicated to the Ğ1 currency, you must indicate the currency for which this wallet will be used.
|
||||
|
||||
#### Usage example
|
||||
|
||||
```dart
|
||||
NewWallet new_wallet = await DubpRust.genWalletFromMnemonic(
|
||||
language: Language.english,
|
||||
mnemonic: "tongue cute mail fossil great frozen same social weasel impact brush kind"
|
||||
);
|
||||
```
|
||||
|
||||
You can choose a different secret code type:
|
||||
|
||||
```dart
|
||||
NewWallet new_wallet = await DubpRust.genWalletFromMnemonic(
|
||||
language: Language.english,
|
||||
mnemonic: "tongue cute mail fossil great frozen same social weasel impact brush kind",
|
||||
secretCodeType: SecretCodeType.digits
|
||||
);
|
||||
```
|
||||
|
||||
### Sign a message
|
||||
|
||||
#### Function signature
|
||||
|
||||
```dart
|
||||
static Future<String> sign({
|
||||
int accountIndex,
|
||||
int addressIndexOpt,
|
||||
String currency = "g1",
|
||||
String dewif,
|
||||
bool externalOpt,
|
||||
String secretCode,
|
||||
String message
|
||||
});
|
||||
```
|
||||
|
||||
If the wallet is not dedicated to the Ğ1 currency, you must indicate the currency.
|
||||
|
||||
#### Usage example
|
||||
|
||||
```dart
|
||||
String signature = await DubpRust.sign(
|
||||
accountIndex: 3,
|
||||
dewif: "AAAAARAAAAGfFDAs+jVZYkfhBlHZZ2fEQIvBqnG16g5+02cY18wSOjW0cUg2JV3SUTJYN2CrbQeRDwGazWnzSFBphchMmiL0",
|
||||
pin: "CDJ4UB",
|
||||
message: "toto"
|
||||
);
|
||||
```
|
||||
|
||||
### Change secret code
|
||||
|
||||
You can change the secret code that encrypts the [DEWIF].
|
||||
|
||||
#### Function signature
|
||||
|
||||
```dart
|
||||
static Future<NewWallet> changeDewifPin({
|
||||
String currency = "g1",
|
||||
String dewif,
|
||||
String oldPin,
|
||||
SecretCodeType secretCodeType = SecretCodeType.letters
|
||||
});
|
||||
```
|
||||
|
||||
If the wallet is not dedicated to the Ğ1 currency, you must indicate the currency.
|
||||
|
||||
#### Usage example
|
||||
|
||||
```dart
|
||||
NewWallet new_wallet = await DubpRust.changeDewifPin(
|
||||
dewif: "AAAAARAAAAGfFDAs+jVZYkfhBlHZZ2fEQIvBqnG16g5+02cY18wSOjW0cUg2JV3SUTJYN2CrbQeRDwGazWnzSFBphchMmiL0",
|
||||
oldPin: "CDJAUB",
|
||||
);
|
||||
```
|
||||
|
||||
[dubp-rs-libs]: https://git.duniter.org/libs/dubp-rs-libs
|
||||
[DEWIF]: https://git.duniter.org/documents/rfcs/blob/dewif/rfc/0013_Duniter_Encrypted_Wallet_Import_Format.md
|
|
@ -1,12 +0,0 @@
|
|||
include: package:effective_dart/analysis_options.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- lib/ffi.dart
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
|
||||
linter:
|
||||
rules:
|
||||
omit_local_variable_types: false
|
|
@ -1,8 +0,0 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
|
@ -1,25 +0,0 @@
|
|||
package io.flutter.plugins;
|
||||
|
||||
import io.flutter.plugin.common.PluginRegistry;
|
||||
import com.example.dubp.DubpPlugin;
|
||||
|
||||
/**
|
||||
* Generated file. Do not edit.
|
||||
*/
|
||||
public final class GeneratedPluginRegistrant {
|
||||
public static void registerWith(PluginRegistry registry) {
|
||||
if (alreadyRegisteredWith(registry)) {
|
||||
return;
|
||||
}
|
||||
DubpPlugin.registerWith(registry.registrarFor("com.example.dubp.DubpPlugin"));
|
||||
}
|
||||
|
||||
private static boolean alreadyRegisteredWith(PluginRegistry registry) {
|
||||
final String key = GeneratedPluginRegistrant.class.getCanonicalName();
|
||||
if (registry.hasPlugin(key)) {
|
||||
return true;
|
||||
}
|
||||
registry.registrarFor(key);
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
group 'com.example.dubp'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.50'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
}
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
org.gradle.jvmargs=-Xmx1536M
|
||||
android.enableR8=true
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
|
@ -1,5 +0,0 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
|
@ -1 +0,0 @@
|
|||
rootProject.name = 'dubp'
|
|
@ -1,3 +0,0 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.dubp">
|
||||
</manifest>
|
|
@ -1,53 +0,0 @@
|
|||
package com.example.dubp
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar
|
||||
|
||||
/** DubpPlugin */
|
||||
public class DubpPlugin: FlutterPlugin, MethodCallHandler {
|
||||
/// The MethodChannel that will the communication between Flutter and native Android
|
||||
///
|
||||
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
|
||||
/// when the Flutter Engine is detached from the Activity
|
||||
private lateinit var channel : MethodChannel
|
||||
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "dubp")
|
||||
channel.setMethodCallHandler(this);
|
||||
}
|
||||
|
||||
// This static function is optional and equivalent to onAttachedToEngine. It supports the old
|
||||
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
|
||||
// plugin registration via this function while apps migrate to use the new Android APIs
|
||||
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
|
||||
//
|
||||
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
|
||||
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
|
||||
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
|
||||
// in the same class.
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun registerWith(registrar: Registrar) {
|
||||
val channel = MethodChannel(registrar.messenger(), "dubp")
|
||||
channel.setMethodCallHandler(DubpPlugin())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
|
||||
if (call.method == "getPlatformVersion") {
|
||||
result.success("Android ${android.os.Build.VERSION.RELEASE}")
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
.idea/
|
||||
.vagrant/
|
||||
.sconsign.dblite
|
||||
.svn/
|
||||
|
||||
.DS_Store
|
||||
*.swp
|
||||
profile
|
||||
|
||||
DerivedData/
|
||||
build/
|
||||
GeneratedPluginRegistrant.h
|
||||
GeneratedPluginRegistrant.m
|
||||
|
||||
.generated/
|
||||
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.mode2v3
|
||||
*.perspectivev3
|
||||
|
||||
!default.pbxuser
|
||||
!default.mode1v3
|
||||
!default.mode2v3
|
||||
!default.perspectivev3
|
||||
|
||||
xcuserdata
|
||||
|
||||
*.moved-aside
|
||||
|
||||
*.pyc
|
||||
*sync/
|
||||
Icon?
|
||||
.tags*
|
||||
|
||||
/Flutter/Generated.xcconfig
|
||||
/Flutter/flutter_export_environment.sh
|
|
@ -1,4 +0,0 @@
|
|||
#import <Flutter/Flutter.h>
|
||||
|
||||
@interface DubpPlugin : NSObject<FlutterPlugin>
|
||||
@end
|
|
@ -1,15 +0,0 @@
|
|||
#import "DubpPlugin.h"
|
||||
#if __has_include(<dubp/dubp-Swift.h>)
|
||||
#import <dubp/dubp-Swift.h>
|
||||
#else
|
||||
// Support project import fallback if the generated compatibility header
|
||||
// is not copied when this plugin is created as a library.
|
||||
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
|
||||
#import "dubp-Swift.h"
|
||||
#endif
|
||||
|
||||
@implementation DubpPlugin
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
[SwiftDubpPlugin registerWithRegistrar:registrar];
|
||||
}
|
||||
@end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue