register BSP when import wallet

refactor
Niko PLP 8 hours ago
parent 158169af27
commit bc04abf526
  1. 2
      app/nextgraph/src/main-web.ts
  2. 6
      app/ui-common/src/api.ts
  3. 2
      app/ui-common/src/locales/en.json
  4. 21
      app/ui-common/src/routes/WalletCreate.svelte
  5. 64
      app/ui-common/src/routes/WalletLogin.svelte
  6. 14
      app/ui-common/src/routes/index.ts
  7. 20
      engine/net/src/bsps.rs
  8. 2
      engine/wallet/src/types.rs
  9. 2
      infra/ngaccount/web/vite.config.js
  10. 10
      infra/ngnet/bootstrap/src/App.svelte
  11. 8
      sdk/rust/src/local_broker.rs

@ -11,7 +11,7 @@ import * as web_api from "@ng-org/lib-wasm";
import {init_api} from "@ng-org/ui-common/api";
init_api(web_api);
const NEW_VERSION = "0.1.2-alpha.1";
const NEW_VERSION = "0.1.2-alpha.2";
// cleaning old wallets :(
try {

@ -23,14 +23,14 @@ let api = createAsyncProxy({},{
export default api;
export const NG_EU_BSP = "https://nextgraph.eu";
export const NG_EU_BSP = import.meta.env.NG_ENV_ALT ? "https://"+import.meta.env.NG_ENV_ALT : "https://nextgraph.eu";
export const NG_EU_BSP_REGISTER = import.meta.env.PROD
? import.meta.env.NG_ENV_ALT ? "https://pnm.allelo.eco" : "https://account.nextgraph.eu/#/create"
? import.meta.env.NG_ENV_ALT_ACCOUNT ? import.meta.env.NG_ENV_ALT_ACCOUNT : "https://account.nextgraph.eu/#/create"
: "http://account-dev.nextgraph.eu:5173/#/create";
export const NG_ONE_BSP = "https://nextgraph.one";
export const NG_ONE_BSP_REGISTER = import.meta.env.PROD
? import.meta.env.NG_ENV_ALT ? "https://account.allelo.eco/#/create" : "https://account.nextgraph.one/#/create"
? "https://account.nextgraph.one/#/create"
: "http://account-dev.nextgraph.one:5173/#/create";
export const APP_ACCOUNT_REGISTERED_SUFFIX = "/#/user/registered";

@ -342,7 +342,7 @@
},
"no_wallet": {
"welcome": "Welcome to NextGraph",
"description": "We could not find a wallet saved on this device.",
"description": "We could not find a wallet on this device.",
"instructions_login": "If you already have a wallet, select \"Login\"",
"instructions_create": ", otherwise, select \"Create Wallet\" here below.",
"instructions_nocreate": ". Creation of a Wallet is not possible while<br/> logging-in to a third-party app.",

@ -23,6 +23,7 @@
import { t } from "svelte-i18n";
import CenteredLayout from "../lib/CenteredLayout.svelte";
import PasswordInput from "../lib/components/PasswordInput.svelte";
import { redirect_server, bootstrap_redirect, base64UrlEncode } from "./index";
// @ts-ignore
import Logo from "../assets/nextgraph.svg?component";
@ -39,11 +40,6 @@
const param = new URLSearchParams($querystring);
function base64UrlEncode(str) {
const base64 = btoa(str); // Standard Base64 encoding
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}
let tauri_platform = import.meta.env.TAURI_PLATFORM;
let wait: any = false;
@ -80,15 +76,6 @@
top.scrollIntoView();
}
const redirect_server = import.meta.env.NG_REDIR_SERVER || "nextgraph.net";
const bootstrap_redirect = import.meta.env.NG_DEV
? "http://localhost:1421/bootstrap.html#/?b="
: import.meta.env.DEV
? "http://localhost:14403/#/?b="
: import.meta.env.NG_DEV3
? "http://127.0.0.1:3033/bootstrap/#/?b="
: `https://${redirect_server}/bootstrap/#/?b=`;
async function bootstrap() {
//console.log(await ng.client_info());
if (!tauri_platform || tauri_platform == "android") {
@ -236,10 +223,6 @@
unsub_register = undefined;
});
onDestroy(async () => {
unsub_register();
});
const select_bsp = async (bsp_url, bsp_name) => {
if (!tauri_platform || tauri_platform == "android") {
let redirect_url;
@ -306,7 +289,7 @@
const selectEU = async (event) => {
await select_bsp(
NG_EU_BSP_REGISTER,
import.meta.env.NG_ENV_ALT ? "pnm.allelo.eco" : "nextgraph.eu"
import.meta.env.NG_ENV_ALT ? import.meta.env.NG_ENV_ALT : "nextgraph.eu"
);
};
</script>

@ -23,6 +23,11 @@
import CenteredLayout from "../lib/CenteredLayout.svelte";
import ng from "../api";
import { Fileupload, Button } from "flowbite-svelte";
import {
redirect_server,
bootstrap_redirect,
base64UrlEncode,
} from "./index";
// @ts-ignore
import Logo from "../assets/nextgraph.svg?component";
import {
@ -162,21 +167,22 @@
$redirect_after_login = undefined;
$redirect_if_wallet_is = undefined;
let in_memory = !event.detail.trusted;
//console.log("IMPORTING", in_memory, event.detail.wallet, wallet);
// TODO : register bootstrap when importing
// if (!in_memory && !tauri_platform) {
// let bootstrap_iframe_msgs =
// await ng.get_bootstrap_iframe_msgs_for_brokers(
// event.detail.wallet.V0.brokers
// );
// let res = await register_bootstrap(bootstrap_iframe_msgs);
// if (res !== true) {
// throw new Error(
// "We could not save your bootstrap information at nextgraph.net. This is needed for links and third-party webapps to work properly. so we are stopping here. Reason: " +
// res
// );
// }
// }
console.log("IMPORTING", in_memory, event.detail.wallet, wallet);
//register bootstrap when importing
if (!in_memory && !tauri_platform) {
let bootstrap_iframe_msgs =
await ng.get_bootstrap_iframe_msgs_for_brokers(
event.detail.wallet.V0.brokers
);
let encoded = base64UrlEncode(JSON.stringify(bootstrap_iframe_msgs));
let register_bootstrap_url =
bootstrap_redirect +
encoded +
"&close=1&m=add&ab=" +
encodeURIComponent(window.location.href);
console.log(register_bootstrap_url);
window.open(register_bootstrap_url, "_blank");
}
let client = await ng.wallet_import(
wallet,
event.detail.wallet,
@ -328,14 +334,38 @@
on:click={start_login_from_import}
on:keypress={start_login_from_import}
>
{#if $wallet_from_import.V0.content.password}
<div class="pt-5">
<ArrowRightEndOnRectangle
class="w-16 h-16"
style="display:inline;"
/>
<div>
{#if mobile}Tap{:else}Click{/if} here to login with your wallet
</div>
</div>
<div class="p-5">
<button
tabindex="-1"
style="overflow-wrap: anywhere;"
class="mt-1 text-white bg-primary-700 hover:bg-primary-700/90 focus:ring-4 focus:ring-primary-100/50 font-medium rounded-lg text-lg px-5 py-1.5 text-center inline-flex items-center dark:focus:ring-primary-700/55 mb-2"
>
{$wallet_from_import.V0.content.security_txt}
</button>
</div>
{:else}
<span class="securitytxt"
>{$wallet_from_import.V0.content.security_txt}
</span>
<img
alt={$wallet_from_import.V0.content.security_txt}
class="securityimg"
src={convert_img_to_url($wallet_from_import.V0.content.security_img)}
src={convert_img_to_url(
$wallet_from_import.V0.content.security_img
)}
/>
{/if}
</div>
<!-- Login to finish import instructions-->
@ -361,7 +391,9 @@
/>
{:else if !$active_wallet && !selected}
<div class="row">
<a href="#/">
<Logo class="logo block h-40" alt="NextGraph Logo" />
</a>
</div>
<h2 class="pb-5 text-xl">{$t("pages.wallet_login.select_wallet")}</h2>
<div class="flex flex-wrap justify-center gap-5 mb-10">

@ -12,3 +12,17 @@ export { default as WalletLogin} from "./WalletLogin.svelte";
export { default as WalletLoginQr} from "./WalletLoginQr.svelte";
export { default as WalletLoginTextCode} from "./WalletLoginTextCode.svelte";
export { default as WalletLoginUsername} from "./WalletLoginUsername.svelte";
export const redirect_server = import.meta.env.NG_REDIR_SERVER || "nextgraph.net";
export const bootstrap_redirect = import.meta.env.NG_DEV
? "http://localhost:1421/bootstrap.html#/?b="
: import.meta.env.DEV
? "http://localhost:14403/#/?b="
: import.meta.env.NG_DEV3
? "http://127.0.0.1:3033/bootstrap/#/?b="
: `https://${redirect_server}/bootstrap/#/?b=`;
export function base64UrlEncode(str) {
const base64 = btoa(str); // Standard Base64 encoding
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

@ -37,6 +37,26 @@ lazy_static! {
},
);
if let Some(alt) = option_env!("NG_ENV_ALT") {
let s: &'static str = Box::leak(format!("https://{alt}").into_boxed_str());
assert!(d
.insert(
s,
BSPDetail {
domain: alt,
country: "us",
sysadmin: "team@nextgraph.org",
owned: false,
since: Date::from_calendar_date(2025, Month::November, 1).unwrap(),
has_free: true,
has_paid: false,
official: true,
description: "Alternative BSP"
}
)
.is_none());
}
assert!(d.insert("https://nextgraph.one", BSPDetail {
domain: "nextgraph.one",
country: "de",

@ -421,7 +421,7 @@ impl ClientV0 {
}
}
/// Save to nextgraph.one
/// Save to nextgraph.net
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SaveToNGOne {
No,

@ -7,7 +7,7 @@ import svelteSVG from "vite-plugin-svelte-svg";
export default defineConfig({
envPrefix: ["VITE_", "NG_"],
server: {
allowedHosts: ["account-dev.nextgraph.eu","account-dev.nextgraph.one"]
allowedHosts: ["account-dev.nextgraph.eu"]
},
plugins: [svelte({
preprocess: [

@ -33,12 +33,16 @@
routes.set("*", NotFound);
// TODO: take this list from local API
const bsp_list = [
let bsp_list = [
"https://nextgraph.eu",
"https://nextgraph.one",
"https://stage1.nextgraph.eu"
];
if (import.meta.env.NG_ENV_ALT) {
bsp_list.push("https://"+import.meta.env.NG_ENV_ALT);
}
let channel;
try {
channel = new BroadcastChannel("ng_bootstrap");
@ -172,7 +176,11 @@
// url.searchParams.set('i', param.get("i"));
// url.searchParams.set('rs', param.get("rs"));
// url.searchParams.set('ab', "1");
if (param.get("close")) {
window.close();
} else {
window.location.href = u + "&ab=1";
}
}catch {}
});

@ -1856,12 +1856,14 @@ lazy_static! {
#[cfg(not(debug_assertions))]
lazy_static! {
static ref DOMAIN: &'static str = option_env!("NG_ENV_ALT").unwrap_or("nextgraph.eu");
static ref PEERID: &'static str =
option_env!("NG_ENV_ALT_PEERID").unwrap_or("LZn-rQD_NUNxrWT_hBXeHk6cjI6WAy-knRVOdovIjwsA");
static ref NEXTGRAPH_EU: BrokerServerV0 = BrokerServerV0 {
server_type: BrokerServerTypeV0::Domain("nextgraph.eu".to_string()),
server_type: BrokerServerTypeV0::Domain(DOMAIN.to_string()),
can_verify: false,
can_forward: false,
peer_id: ng_repo::utils::decode_key("LZn-rQD_NUNxrWT_hBXeHk6cjI6WAy-knRVOdovIjwsA")
.unwrap(),
peer_id: ng_repo::utils::decode_key(&PEERID).unwrap(),
};
}

Loading…
Cancel
Save