From 90a5b91a694f3426107a1443278012d172072c60 Mon Sep 17 00:00:00 2001 From: Olivier Sarrouy Date: Fri, 3 Apr 2020 13:28:21 +0200 Subject: [PATCH] End up first cleaning phase --- example/App.svelte | 11 +- .../{ => Button/components}/Button.svelte | 7 +- .../Button/components/Loader.svelte | 45 + example/components/Button/index.js | 3 + .../Profile/components/Profile.svelte | 62 +- example/public/bundle.js | 323370 +++++++++++++++ example/public/bundle.js.map | 1 + src/lib/index.js | 5 +- src/lib/profile.js | 29 +- src/lib/storage.js | 29 +- src/lib/wallet.js | 14 +- src/stores/index.js | 1 + src/stores/isLoggedIn.js | 3 + 13 files changed, 323562 insertions(+), 18 deletions(-) rename example/components/{ => Button/components}/Button.svelte (93%) create mode 100644 example/components/Button/components/Loader.svelte create mode 100644 example/components/Button/index.js create mode 100644 example/public/bundle.js create mode 100644 example/public/bundle.js.map create mode 100644 src/stores/isLoggedIn.js diff --git a/example/App.svelte b/example/App.svelte index ccf89a3..a5e1f55 100644 --- a/example/App.svelte +++ b/example/App.svelte @@ -4,7 +4,7 @@ import Profile from "./components/Profile"; import Dapp from "../src"; import { dapp } from "../src"; - import { infra, profile, settings, wallet } from "../src/stores"; + import { infra, isLoggedIn, profile, settings, wallet } from "../src/stores"; import { fly } from "svelte/transition"; let isLogging = false; @@ -14,6 +14,11 @@ console.log(_infra); }); + isLoggedIn.subscribe(_isLoggedIn => { + console.log("[isLoggedIn:update]"); + console.log(_isLoggedIn); + }); + profile.subscribe(_profile => { console.log("[profile:update]"); console.log(_profile); @@ -65,8 +70,8 @@ (isLogging = false)} /> {/if}
- {#if $profile} - + {#if $isLoggedIn} + dapp.logout()} /> {:else}
diff --git a/example/components/Button.svelte b/example/components/Button/components/Button.svelte similarity index 93% rename from example/components/Button.svelte rename to example/components/Button/components/Button.svelte index 72d5f19..0442a9c 100644 --- a/example/components/Button.svelte +++ b/example/components/Button/components/Button.svelte @@ -1,4 +1,5 @@
+
+
+
+
diff --git a/example/components/Button/index.js b/example/components/Button/index.js new file mode 100644 index 0000000..4825f15 --- /dev/null +++ b/example/components/Button/index.js @@ -0,0 +1,3 @@ +import Button from "./components/Button.svelte"; + +export default Button; diff --git a/example/components/Profile/components/Profile.svelte b/example/components/Profile/components/Profile.svelte index f72aee2..9660e32 100644 --- a/example/components/Profile/components/Profile.svelte +++ b/example/components/Profile/components/Profile.svelte @@ -1,14 +1,47 @@
- avatar + avatar
@@ -51,4 +93,12 @@ bind:value={motto} placeholder="All State Sailors Are Bastards" />
+
+ +

+ or + logout +

+
+
diff --git a/example/public/bundle.js b/example/public/bundle.js new file mode 100644 index 0000000..2c1511a --- /dev/null +++ b/example/public/bundle.js @@ -0,0 +1,323370 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./example/App.svelte": +/*!****************************!*\ + !*** ./example/App.svelte ***! + \****************************/ +/*! exports provided: default */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var svelte_internal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! svelte/internal */ "./node_modules/svelte/internal/index.mjs"); +/* harmony import */ var _components_Button__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/Button */ "./example/components/Button.svelte"); +/* harmony import */ var _components_Login__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./components/Login */ "./example/components/Login/index.js"); +/* harmony import */ var _src__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../src */ "./src/index.js"); +/* harmony import */ var _src_stores__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../src/stores */ "./src/stores/index.js"); +/* harmony import */ var _Users_osarrouy_Code_osarrouy_svelte_dapp_example_App_svelte_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./example/App.svelte.css */ "./example/App.svelte.css"); +/* harmony import */ var _Users_osarrouy_Code_osarrouy_svelte_dapp_example_App_svelte_css__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_Users_osarrouy_Code_osarrouy_svelte_dapp_example_App_svelte_css__WEBPACK_IMPORTED_MODULE_5__); +/* example/App.svelte generated by Svelte v3.20.1 */ + + + + + + + + +function create_if_block_2(ctx) { + let current; + const login = new _components_Login__WEBPACK_IMPORTED_MODULE_2__["default"]({}); + login.$on("close", /*close_handler*/ ctx[2]); + + return { + c() { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["create_component"])(login.$$.fragment); + }, + m(target, anchor) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["mount_component"])(login, target, anchor); + current = true; + }, + p: svelte_internal__WEBPACK_IMPORTED_MODULE_0__["noop"], + i(local) { + if (current) return; + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_in"])(login.$$.fragment, local); + current = true; + }, + o(local) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_out"])(login.$$.fragment, local); + current = false; + }, + d(detaching) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["destroy_component"])(login, detaching); + } + }; +} + +// (78:6) {:else} +function create_else_block_1(ctx) { + let p; + + return { + c() { + p = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["element"])("p"); + p.textContent = "Hi, please login to move on."; + }, + m(target, anchor) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["insert"])(target, p, anchor); + }, + p: svelte_internal__WEBPACK_IMPORTED_MODULE_0__["noop"], + d(detaching) { + if (detaching) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["detach"])(p); + } + }; +} + +// (72:6) {#if $profile} +function create_if_block_1(ctx) { + let img; + let img_src_value; + let t0; + let div; + let a; + let t1_value = /*$profile*/ ctx[1].name + ""; + let t1; + let a_href_value; + let t2; + let p; + let t3_value = /*$profile*/ ctx[1].address + ""; + let t3; + + return { + c() { + img = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["element"])("img"); + t0 = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["space"])(); + div = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["element"])("div"); + a = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["element"])("a"); + t1 = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["text"])(t1_value); + t2 = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["space"])(); + p = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["element"])("p"); + t3 = Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["text"])(t3_value); + if (img.src !== (img_src_value = /*$profile*/ ctx[1].avatar)) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(img, "src", img_src_value); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(img, "alt", "avatar"); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(img, "class", "svelte-15pw5lv"); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(a, "href", a_href_value = /*$profile*/ ctx[1].url); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(a, "target", "_blank"); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(p, "class", "small svelte-15pw5lv"); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(div, "class", "data"); + }, + m(target, anchor) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["insert"])(target, img, anchor); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["insert"])(target, t0, anchor); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["insert"])(target, div, anchor); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["append"])(div, a); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["append"])(a, t1); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["append"])(div, t2); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["append"])(div, p); + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["append"])(p, t3); + }, + p(ctx, dirty) { + if (dirty & /*$profile*/ 2 && img.src !== (img_src_value = /*$profile*/ ctx[1].avatar)) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(img, "src", img_src_value); + } + + if (dirty & /*$profile*/ 2 && t1_value !== (t1_value = /*$profile*/ ctx[1].name + "")) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["set_data"])(t1, t1_value); + + if (dirty & /*$profile*/ 2 && a_href_value !== (a_href_value = /*$profile*/ ctx[1].url)) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["attr"])(a, "href", a_href_value); + } + + if (dirty & /*$profile*/ 2 && t3_value !== (t3_value = /*$profile*/ ctx[1].address + "")) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["set_data"])(t3, t3_value); + }, + d(detaching) { + if (detaching) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["detach"])(img); + if (detaching) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["detach"])(t0); + if (detaching) Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["detach"])(div); + } + }; +} + +// (85:6) {:else} +function create_else_block(ctx) { + let current; + + const button = new _components_Button__WEBPACK_IMPORTED_MODULE_1__["default"]({ + props: { + $$slots: { default: [create_default_slot_2] }, + $$scope: { ctx } + } + }); + + button.$on("click", /*click_handler_1*/ ctx[4]); + + return { + c() { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["create_component"])(button.$$.fragment); + }, + m(target, anchor) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["mount_component"])(button, target, anchor); + current = true; + }, + p(ctx, dirty) { + const button_changes = {}; + + if (dirty & /*$$scope*/ 32) { + button_changes.$$scope = { dirty, ctx }; + } + + button.$set(button_changes); + }, + i(local) { + if (current) return; + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_in"])(button.$$.fragment, local); + current = true; + }, + o(local) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_out"])(button.$$.fragment, local); + current = false; + }, + d(detaching) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["destroy_component"])(button, detaching); + } + }; +} + +// (83:6) {#if $profile} +function create_if_block(ctx) { + let current; + + const button = new _components_Button__WEBPACK_IMPORTED_MODULE_1__["default"]({ + props: { + $$slots: { default: [create_default_slot_1] }, + $$scope: { ctx } + } + }); + + button.$on("click", /*click_handler*/ ctx[3]); + + return { + c() { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["create_component"])(button.$$.fragment); + }, + m(target, anchor) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["mount_component"])(button, target, anchor); + current = true; + }, + p(ctx, dirty) { + const button_changes = {}; + + if (dirty & /*$$scope*/ 32) { + button_changes.$$scope = { dirty, ctx }; + } + + button.$set(button_changes); + }, + i(local) { + if (current) return; + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_in"])(button.$$.fragment, local); + current = true; + }, + o(local) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["transition_out"])(button.$$.fragment, local); + current = false; + }, + d(detaching) { + Object(svelte_internal__WEBPACK_IMPORTED_MODULE_0__["destroy_component"])(button, detaching); + } + }; +} + +// (86:8)