diff --git a/Cargo.lock b/Cargo.lock index 8711810..9f74304 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2838,6 +2838,7 @@ dependencies = [ "anyhow", "base64-url", "bytes", + "duration-str", "env_logger", "log", "ng-wallet", diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index f3b4e46..3ea221f 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -115,6 +115,7 @@ export const NG_EU_BSP_REGISTER = "https://account.nextgraph.eu/#/create"; export const NG_EU_BSP_REGISTERED = "https://nextgraph.eu/#/user/registered"; export const APP_ACCOUNT_REGISTERED_SUFFIX = "/#/user/registered"; +export const APP_WALLET_CREATE_SUFFIX = "/#/wallet/create"; export const NG_NET_BSP = "https://nextgraph.net"; export const NG_NET_BSP_REGISTER = "https://account.nextgraph.net/#/create"; diff --git a/ng-app/src/routes/WalletCreate.svelte b/ng-app/src/routes/WalletCreate.svelte index cbb7cd2..a2c51c7 100644 --- a/ng-app/src/routes/WalletCreate.svelte +++ b/ng-app/src/routes/WalletCreate.svelte @@ -21,7 +21,7 @@ NG_NET_BSP, NG_EU_BSP_REGISTER, NG_EU_BSP_REGISTERED, - APP_ACCOUNT_REGISTERED_SUFFIX, + APP_WALLET_CREATE_SUFFIX, default as ng, } from "../api"; import { display_pazzle } from "../wallet_emojis"; @@ -85,6 +85,8 @@ }; let intro = false; + let registration_error; + let registration_success; let pin = []; let pin_confirm = []; let security_txt = ""; @@ -129,23 +131,44 @@ : "http://localhost:3030/api/v1/"; async function bootstrap() { - console.log(await ng.client_info()); - invitation = await ng.get_local_bootstrap_with_public( - location.href, - param.get("i") - ); - console.log(invitation); - // TODO: implement this error screen and link button - if (!invitation && param.get("i")) { - console.error( - "got an invitation for another broker. click on the link below to be redirected to the right broker" - ); + //console.log(await ng.client_info()); + if (!tauri_platform) { + if (param.get("skipintro") || param.get("rs")) { + intro = false; + } + if (param.get("re")) { + registration_error = param.get("re"); + } + if (param.get("rs")) { + registration_success = param.get("rs"); + invitation = await ng.decode_invitation(param.get("i")); + } else { + invitation = await ng.get_local_bootstrap_with_public( + location.href, + param.get("i") + ); + } + console.log(invitation); + if (!invitation && param.get("i")) { + let redirect = await ng.get_ngone_url_of_invitation(param.get("i")); + if (redirect) { + console.error("got an invitation for another broker. redirecting"); + window.location.href = redirect; + } else { + //let i = await ng.decode_invitation(param.get("i")); + console.error("invalid invitation. ignoring it"); + } + } } scrollToTop(); } function create_wallet() { intro = false; + if (invitation && invitation.V0.url) { + // we redirect to the TOS url of the invitation. + window.location.href = invitation.V0.url; + } scrollToTop(); } @@ -163,6 +186,15 @@ async function do_wallet() { creating = true; + let local_invitation = await ng.get_local_bootstrap(location.href); + let additional_bootstrap; + if (local_invitation) { + additional_bootstrap = local_invitation.V0.bootstrap; + } + let core_registration; + if (invitation.V0.code) { + core_registration = invitation.V0.code.ChaCha20Key; + } let params = { security_img: security_img, security_txt, @@ -172,19 +204,25 @@ send_wallet: options.cloud, local_save: options.trusted, // this is only used for tauri apps result_with_wallet_file: false, // this will be automatically changed to true for browser app + core_bootstrap: invitation.V0.bootstrap, + core_registration, + additional_bootstrap, }; console.log(params); try { let res = await ng.wallet_create_wallet(params); console.log(res); - wallets.set(Object.fromEntries(await ng.get_wallets_from_localstorage())); - set_active_session(res[1]); - + wallets.set( + Object.fromEntries((await ng.get_wallets_from_localstorage()) || []) + ); + if (res[1]) { + set_active_session(res[1]); + } ready = res[0]; console.log(display_pazzle(ready.pazzle)); download_name = "wallet-" + ready.wallet_name + ".ngw"; if (options.cloud) { - cloud_link = "https://nextgraph.one/#/w/" + res.wallet_name; + cloud_link = "https://nextgraph.one/#/w/" + ready.wallet_name; } if (ready.wallet_file.length) { const blob = new Blob([ready.wallet_file]); @@ -240,18 +278,10 @@ const selectEU = async (event) => { if (!tauri_platform) { - let local_invitation = await ng.get_local_bootstrap(location.href); - let additional_bootstrap; - if (local_invitation) { - additional_bootstrap = local_invitation.V0.bootstrap; - } let local_url = await ng.get_local_url(location.href); let create = { V0: { - additional_bootstrap, - invitation: undefined, - user: ready.user, - redirect_url: local_url + APP_ACCOUNT_REGISTERED_SUFFIX, + redirect_url: local_url + APP_WALLET_CREATE_SUFFIX, }, }; let ca = await ng.encode_create_account(create); @@ -260,9 +290,6 @@ } else { let create = { V0: { - additional_bootstrap: undefined, - invitation: undefined, - user: ready.user, redirect_url: undefined, }, }; @@ -283,7 +310,51 @@