Feature update

-- Added option to edit and delete saved IDs
This commit is contained in:
sairaj mote 2022-04-14 02:02:04 +05:30
parent 9dd23f6151
commit c701c5d3b3
7 changed files with 316 additions and 137 deletions

View File

@ -669,34 +669,53 @@ h3 {
#saved_ids_list { #saved_ids_list {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); grid-template-columns: minmax(0, 1fr);
gap: 1rem; gap: 1rem;
margin-top: 1.5rem; margin-top: 1.5rem;
} }
.saved-id { .saved-id {
display: grid;
gap: 1rem;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
gap: 0 0.8rem;
border-radius: 0.3rem;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
align-items: center; align-items: center;
color: inherit; }
padding: 0.5rem 0; .saved-id.highlight {
box-shadow: 0 0 0.1rem 0.1rem var(--accent-color) inset;
}
.saved-id .edit-saved {
padding: 0.3rem;
position: relative;
justify-self: center;
}
.saved-id .edit-saved .icon {
position: absolute;
height: 1.2rem;
width: 1.2rem;
right: 0;
bottom: 0;
border-radius: 0.5rem;
padding: 0.2rem;
background-color: rgba(var(--background-color), 1);
} }
.saved-id__initials { .saved-id__initials {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
height: 2.5rem; height: 2.4rem;
width: 2.5rem; width: 2.4rem;
color: rgba(var(--background-color), 1); font-size: 1.2rem;
background-color: var(--accent-color);
border-radius: 1rem;
text-transform: uppercase; text-transform: uppercase;
color: rgba(var(--background-color), 1);
font-weight: 700; font-weight: 700;
} line-height: 1;
.saved-id__title { background-color: var(--accent-color);
font-size: 0.9rem; justify-self: flex-start;
color: rgba(var(--text-color), 1); border-radius: 2rem;
} }
.card { .card {
@ -705,7 +724,10 @@ h3 {
padding: 1rem; padding: 1rem;
} }
#history { #cashier,
#contact,
#history,
#settings {
height: 100%; height: 100%;
align-content: flex-start; align-content: flex-start;
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
@ -718,6 +740,15 @@ h3 {
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
} }
#contact {
display: grid;
grid-template-rows: auto 1fr auto;
}
#contact__transactions {
overflow-y: auto;
}
#payments_history_wrapper, #payments_history_wrapper,
#wallet_history_wrapper { #wallet_history_wrapper {
padding-bottom: 4rem; padding-bottom: 4rem;
@ -741,7 +772,7 @@ h3 {
color: rgba(var(--text-color), 0.8); color: rgba(var(--text-color), 0.8);
} }
.transaction.sent .transaction__amount::before { .transaction.sent .transaction__amount::before {
content: "-"; content: "- ";
} }
.transaction.received .icon { .transaction.received .icon {
fill: var(--green); fill: var(--green);
@ -750,7 +781,7 @@ h3 {
color: var(--green); color: var(--green);
} }
.transaction.received .transaction__amount::before { .transaction.received .transaction__amount::before {
content: "-"; content: "+ ";
} }
.transaction__icon { .transaction__icon {
display: flex; display: flex;
@ -950,17 +981,24 @@ h3 {
#user { #user {
gap: 1rem; gap: 1rem;
padding: 1.5rem 8vmax; padding: 0 8vmax;
grid-template-columns: 1fr 22rem; grid-template-columns: 1fr 22rem;
align-content: flex-start; align-content: flex-start;
align-items: flex-start; align-items: flex-start;
} }
#saved_ids_list {
grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
}
.saved-id { .saved-id {
padding: 1rem; padding: 1rem;
border-radius: 0.5rem; border-radius: 0.5rem;
background-color: rgba(var(--text-color), 0.03); background-color: rgba(var(--text-color), 0.03);
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
justify-content: center;
text-align: center;
gap: 0.5rem;
} }
#wallet_section { #wallet_section {

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -624,32 +624,48 @@ h3 {
#saved_ids_list { #saved_ids_list {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); grid-template-columns: minmax(0, 1fr);
gap: 1rem; gap: 1rem;
margin-top: 1.5rem; margin-top: 1.5rem;
} }
.saved-id { .saved-id {
display: grid;
gap: 1rem;
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
gap: 0 0.8rem;
border-radius: 0.3rem;
user-select: none;
align-items: center; align-items: center;
color: inherit; &.highlight {
padding: 0.5rem 0; box-shadow: 0 0 0.1rem 0.1rem var(--accent-color) inset;
}
.edit-saved {
padding: 0.3rem;
position: relative;
justify-self: center;
.icon {
position: absolute;
height: 1.2rem;
width: 1.2rem;
right: 0;
bottom: 0;
border-radius: 0.5rem;
padding: 0.2rem;
background-color: rgba(var(--background-color), 1);
}
}
&__initials { &__initials {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
height: 2.5rem; height: 2.4rem;
width: 2.5rem; width: 2.4rem;
color: rgba(var(--background-color), 1); font-size: 1.2rem;
background-color: var(--accent-color);
border-radius: 1rem;
text-transform: uppercase; text-transform: uppercase;
color: rgba(var(--background-color), 1);
font-weight: 700; font-weight: 700;
} line-height: 1;
&__title { background-color: var(--accent-color);
font-size: 0.9rem; justify-self: flex-start;
color: rgba(var(--text-color), 1); border-radius: 2rem;
} }
} }
@ -658,7 +674,10 @@ h3 {
border-radius: 0.5rem; border-radius: 0.5rem;
padding: 1rem; padding: 1rem;
} }
#history { #cashier,
#contact,
#history,
#settings {
height: 100%; height: 100%;
align-content: flex-start; align-content: flex-start;
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
@ -670,6 +689,13 @@ h3 {
border-radius: 0.5rem; border-radius: 0.5rem;
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
} }
#contact {
display: grid;
grid-template-rows: auto 1fr auto;
}
#contact__transactions {
overflow-y: auto;
}
#payments_history_wrapper, #payments_history_wrapper,
#wallet_history_wrapper { #wallet_history_wrapper {
padding-bottom: 4rem; padding-bottom: 4rem;
@ -690,7 +716,7 @@ h3 {
.transaction__amount { .transaction__amount {
color: rgba(var(--text-color), 0.8); color: rgba(var(--text-color), 0.8);
&::before { &::before {
content: "-"; content: "- ";
} }
} }
} }
@ -701,7 +727,7 @@ h3 {
.transaction__amount { .transaction__amount {
color: var(--green); color: var(--green);
&::before { &::before {
content: "-"; content: "+ ";
} }
} }
} }
@ -880,16 +906,22 @@ h3 {
} }
#user { #user {
gap: 1rem; gap: 1rem;
padding: 1.5rem 8vmax; padding: 0 8vmax;
grid-template-columns: 1fr 22rem; grid-template-columns: 1fr 22rem;
align-content: flex-start; align-content: flex-start;
align-items: flex-start; align-items: flex-start;
} }
#saved_ids_list {
grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
}
.saved-id { .saved-id {
padding: 1rem; padding: 1rem;
border-radius: 0.5rem; border-radius: 0.5rem;
background-color: rgba(var(--text-color), 0.03); background-color: rgba(var(--text-color), 0.03);
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
justify-content: center;
text-align: center;
gap: 0.5rem;
} }
#wallet_section { #wallet_section {
grid-area: 1/2/3/3; grid-area: 1/2/3/3;

View File

@ -147,57 +147,52 @@
</div> </div>
<section id="home" class="page hide"> <section id="home" class="page hide">
<div id="user" class="hide grid user-element"> <div id="user" class="hide grid user-element">
<div class="card grid gap-1-5"> <div id="quick_actions_container" class="card">
<div class="flex align-center space-between"> <button class="primary-action" onclick="showTokenTransfer('send')">
<h4>Quick actions </h4> <svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
</div> width="24px" fill="#000000">
<div id="quick_actions_container"> <path d="M0 0h24v24H0z" fill="none" />
<button class="primary-action" onclick="showTokenTransfer('send')"> <path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" />
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" </svg>
width="24px" fill="#000000"> Send rupee
<path d="M0 0h24v24H0z" fill="none" /> </button>
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" /> <button class="primary-action" onclick="showTokenTransfer('request')">
</svg> <svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24"
Send rupee height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
</button> <g>
<button class="primary-action" onclick="showTokenTransfer('request')"> <rect fill="none" height="24" width="24" />
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" </g>
height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <g>
<path
d="M20,2H4.01c-1.1,0-2,0.9-2,2L2,22l4-4h14c1.1,0,2-0.9,2-2V4C22,2.9,21.1,2,20,2z M12,6c1.1,0,2,0.9,2,2s-0.9,2-2,2 s-2-0.9-2-2S10.9,6,12,6z M16,14H8v-0.57c0-0.81,0.48-1.53,1.22-1.85C10.07,11.21,11.01,11,12,11c0.99,0,1.93,0.21,2.78,0.58 C15.52,11.9,16,12.62,16,13.43V14z" />
</g>
</svg>
Request rupee
</button>
<button class="primary-action" onclick="">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24"
height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<g>
<rect fill="none" height="24" width="24" />
</g>
<g>
<g> <g>
<rect fill="none" height="24" width="24" /> <path d="M3,11h8V3H3V11z M5,5h4v4H5V5z" />
<path d="M3,21h8v-8H3V21z M5,15h4v4H5V15z" />
<path d="M13,3v8h8V3H13z M19,9h-4V5h4V9z" />
<rect height="2" width="2" x="19" y="19" />
<rect height="2" width="2" x="13" y="13" />
<rect height="2" width="2" x="15" y="15" />
<rect height="2" width="2" x="13" y="17" />
<rect height="2" width="2" x="15" y="19" />
<rect height="2" width="2" x="17" y="17" />
<rect height="2" width="2" x="17" y="13" />
<rect height="2" width="2" x="19" y="15" />
</g> </g>
<g> </g>
<path </svg>
d="M20,2H4.01c-1.1,0-2,0.9-2,2L2,22l4-4h14c1.1,0,2-0.9,2-2V4C22,2.9,21.1,2,20,2z M12,6c1.1,0,2,0.9,2,2s-0.9,2-2,2 s-2-0.9-2-2S10.9,6,12,6z M16,14H8v-0.57c0-0.81,0.48-1.53,1.22-1.85C10.07,11.21,11.01,11,12,11c0.99,0,1.93,0.21,2.78,0.58 C15.52,11.9,16,12.62,16,13.43V14z" /> Scan FLO QR
</g> </button>
</svg>
Request rupee
</button>
<button class="primary-action" onclick="">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24"
height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<g>
<rect fill="none" height="24" width="24" />
</g>
<g>
<g>
<path d="M3,11h8V3H3V11z M5,5h4v4H5V5z" />
<path d="M3,21h8v-8H3V21z M5,15h4v4H5V15z" />
<path d="M13,3v8h8V3H13z M19,9h-4V5h4V9z" />
<rect height="2" width="2" x="19" y="19" />
<rect height="2" width="2" x="13" y="13" />
<rect height="2" width="2" x="15" y="15" />
<rect height="2" width="2" x="13" y="17" />
<rect height="2" width="2" x="15" y="19" />
<rect height="2" width="2" x="17" y="17" />
<rect height="2" width="2" x="17" y="13" />
<rect height="2" width="2" x="19" y="15" />
</g>
</g>
</svg>
Scan FLO QR
</button>
</div>
</div> </div>
<section id="wallet_section" class="card grid gap-1-5"> <section id="wallet_section" class="card grid gap-1-5">
<div class="flex align-center space-between"> <div class="flex align-center space-between">
@ -220,10 +215,10 @@
<h5>Balance</h5> <h5>Balance</h5>
<h1 class="h1" id="rupee_balance"></h1> <h1 class="h1" id="rupee_balance"></h1>
</div> </div>
<div class="grid gap-1"> <!-- <div class="grid gap-1">
<sm-input id="request_cashier_amount" type="number" name="amount" placeholder="Amount" animate> <sm-input id="request_cashier_amount" type="number" name="amount" placeholder="Amount" animate>
</sm-input> </sm-input>
</div> </div> -->
<div class="grid gap-0-5"> <div class="grid gap-0-5">
<div class="flex"> <div class="flex">
<button class="wallet-action" onclick="userUI.requestTokenFromCashier()"> <button class="wallet-action" onclick="userUI.requestTokenFromCashier()">
@ -320,6 +315,23 @@
<h4>No transactions</h4> <h4>No transactions</h4>
</div> </div>
</section> </section>
<section id="contact" class="page hide">
<div class="flex align-center">
<a href="#/home" class="button icon-only margin-right-0-5">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" />
</svg>
</a>
<h4 id="contact__title"></h4>
</div>
<div id="contact__transactions"></div>
<div class="flex">
<button class="button flex-1">Pay</button>
<button class="button flex-1">Request</button>
</div>
</section>
<section id="activity" class="page page-layout hide"> <section id="activity" class="page page-layout hide">
<h4>Activity</h4> <h4>Activity</h4>
<ul id="user-money-requests" class="observe-empty-state"></ul> <ul id="user-money-requests" class="observe-empty-state"></ul>
@ -327,7 +339,7 @@
<h4>No requests</h4> <h4>No requests</h4>
</div> </div>
</section> </section>
<section id="settings" class="page page-layout hide"> <section id="settings" class="page hide">
<h4>Settings</h4> <h4>Settings</h4>
<section class="grid gap-1"> <section class="grid gap-1">
<div class="grid"> <div class="grid">
@ -366,9 +378,43 @@
autofocus> autofocus>
</sm-input> </sm-input>
<sm-input id="flo_id_title_to_save" placeholder="Title" animate required></sm-input> <sm-input id="flo_id_title_to_save" placeholder="Title" animate required></sm-input>
<button class="button button--primary cta" onclick="userUI.saveId()" type="submit">Save</button> <button class="button button--primary cta" onclick="saveId()" type="submit">Save</button>
</sm-form> </sm-form>
</sm-popup> </sm-popup>
<sm-popup id="edit_saved_popup">
<header slot="header" class="popup__header">
<div class="flex align-center">
<button class="popup__header__close" onclick="hidePopup()">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" />
</svg>
</button>
<h3>Edit</h3>
</div>
</header>
<section class="grid gap-1-5">
<div class="grid gap-0-5">
<h5>FLO ID</h5>
<sm-copy id="edit_saved_id"></sm-copy>
</div>
<sm-form>
<sm-input id="newAddrLabel" placeholder="Name" autofocus animate required></sm-input>
<div class="flex align-center space-between">
<button class="button icon-only" title="Delete this FLO ID?" onclick="deleteSaved()">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
width="24px" fill="#000000">
<path d="M0 0h24v24H0z" fill="none" />
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" />
</svg>
</button>
<button class="button button--primary cta" type="submit" onclick="saveChanges()">Save</button>
</div>
</sm-form>
</section>
</sm-popup>
<sm-popup id="token_transfer_popup"> <sm-popup id="token_transfer_popup">
<header slot="header" class="popup__header"> <header slot="header" class="popup__header">
<button class="popup__header__close justify-self-start" onclick="hidePopup()"> <button class="popup__header__close justify-self-start" onclick="hidePopup()">
@ -409,12 +455,17 @@
<!-- templates --> <!-- templates -->
<template id="saved_id_template"> <template id="saved_id_template">
<li> <li class="saved-id grid interact" tabindex="0">
<a class="saved-id interact" href=""> <button class="interact edit-saved" title="Edit saved ID">
<div class="saved-id__initials"></div> <div class="saved-id__initials"></div>
<span class="saved-id__title"></span> <svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
<!-- <sm-copy class="saved-id__flo-id"></sm-copy> --> fill="#000000">
</a> <path d="M0 0h24v24H0z" fill="none" />
<path
d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z" />
</svg>
</button>
<h4 class="saved-id__title"></h4>
</li> </li>
</template> </template>
<template id="transaction_template"> <template id="transaction_template">

View File

@ -2368,14 +2368,19 @@ customElements.define('strip-select', class extends HTMLElement {
this.slottedOptions = undefined; this.slottedOptions = undefined;
this._value = undefined; this._value = undefined;
this.scrollDistance = 0; this.scrollDistance = 0;
this.assignedElements = [];
this.scrollLeft = this.scrollLeft.bind(this); this.scrollLeft = this.scrollLeft.bind(this);
this.scrollRight = this.scrollRight.bind(this); this.scrollRight = this.scrollRight.bind(this);
this.fireEvent = this.fireEvent.bind(this); this.fireEvent = this.fireEvent.bind(this);
this.setSelectedOption = this.setSelectedOption.bind(this);
} }
get value() { get value() {
return this._value; return this._value;
} }
set value(val) {
this.setSelectedOption(val);
}
scrollLeft() { scrollLeft() {
this.stripSelect.scrollBy({ this.stripSelect.scrollBy({
left: -this.scrollDistance, left: -this.scrollDistance,
@ -2389,6 +2394,19 @@ customElements.define('strip-select', class extends HTMLElement {
behavior: 'smooth' behavior: 'smooth'
}); });
} }
setSelectedOption(value) {
if (this._value === value) return
this._value = value;
this.assignedElements.forEach(elem => {
if (elem.value === value) {
elem.setAttribute('active', '');
elem.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
}
else
elem.removeAttribute('active')
});
}
fireEvent() { fireEvent() {
this.dispatchEvent( this.dispatchEvent(
new CustomEvent("change", { new CustomEvent("change", {
@ -2409,17 +2427,17 @@ customElements.define('strip-select', class extends HTMLElement {
const navButtonLeft = this.shadowRoot.querySelector('.nav-button--left'); const navButtonLeft = this.shadowRoot.querySelector('.nav-button--left');
const navButtonRight = this.shadowRoot.querySelector('.nav-button--right'); const navButtonRight = this.shadowRoot.querySelector('.nav-button--right');
slot.addEventListener('slotchange', e => { slot.addEventListener('slotchange', e => {
const assignedElements = slot.assignedElements(); this.assignedElements = slot.assignedElements();
assignedElements.forEach(elem => { this.assignedElements.forEach(elem => {
if (elem.hasAttribute('selected')) { if (elem.hasAttribute('selected')) {
elem.setAttribute('active', ''); elem.setAttribute('active', '');
this._value = elem.value; this._value = elem.value;
} }
}); });
if (!this.hasAttribute('multiline')) { if (!this.hasAttribute('multiline')) {
if (assignedElements.length > 0) { if (this.assignedElements.length > 0) {
firstOptionObserver.observe(slot.assignedElements()[0]); firstOptionObserver.observe(this.assignedElements[0]);
lastOptionObserver.observe(slot.assignedElements()[slot.assignedElements().length - 1]); lastOptionObserver.observe(this.assignedElements[this.assignedElements.length - 1]);
} }
else { else {
navButtonLeft.classList.add('hide'); navButtonLeft.classList.add('hide');
@ -2446,10 +2464,7 @@ customElements.define('strip-select', class extends HTMLElement {
resObs.observe(this); resObs.observe(this);
this.stripSelect.addEventListener('option-clicked', e => { this.stripSelect.addEventListener('option-clicked', e => {
if (this._value !== e.target.value) { if (this._value !== e.target.value) {
this._value = e.target.value; this.setSelectedOption(e.target.value);
slot.assignedElements().forEach(elem => elem.removeAttribute('active'));
e.target.setAttribute('active', '');
e.target.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
this.fireEvent(); this.fireEvent();
} }
}); });

View File

@ -97,8 +97,7 @@ userUI.renderSavedIds = async function () {
if (savedIds.length && await compactIDB.readData('savedIds', 'lastSyncTime') !== savedIds[0].time) { if (savedIds.length && await compactIDB.readData('savedIds', 'lastSyncTime') !== savedIds[0].time) {
await compactIDB.clearData('savedIds'); await compactIDB.clearData('savedIds');
const dataToDecrypt = floCloudAPI.util.decodeMessage(savedIds[0].message) const dataToDecrypt = floCloudAPI.util.decodeMessage(savedIds[0].message)
const data = JSON.parse(floCrypto.decryptData(dataToDecrypt, myPrivKey)); const data = JSON.parse(Crypto.AES.decrypt(dataToDecrypt, myPrivKey));
console.log(data)
for (let key in data) { for (let key in data) {
floGlobals.savedIds[key] = data[key]; floGlobals.savedIds[key] = data[key];
compactIDB.addData('savedIds', data[key], key); compactIDB.addData('savedIds', data[key], key);
@ -111,29 +110,12 @@ userUI.renderSavedIds = async function () {
floGlobals.savedIds[key] = idsToRender[key]; floGlobals.savedIds[key] = idsToRender[key];
} }
} }
console.log(floGlobals.savedIds)
for (const key in floGlobals.savedIds) { for (const key in floGlobals.savedIds) {
frag.append(render.savedId(key, floGlobals.savedIds[key])); frag.append(render.savedId(key, floGlobals.savedIds[key]));
} }
getRef('saved_ids_list').append(frag); getRef('saved_ids_list').append(frag);
} }
userUI.saveId = async function () {
const floID = getRef('flo_id_to_save').value.trim();
const title = getRef('flo_id_title_to_save').value.trim();
const dataToSend = floCrypto.encryptData(JSON.stringify({ ...floGlobals.savedIds, [floID]: { title } }), myPubKey)
floCloudAPI.sendApplicationData(dataToSend, 'savedIds', { receiverID: myFloID }).then(result => {
console.log(result);
floGlobals.savedIds[floID] = { title }
notify(`Saved ${floID}`, 'success');
getRef('saved_ids_list').append(render.savedId(floID, { title }));
hidePopup();
}).catch(error => {
console.error(error);
notify(error, 'error');
})
}
userUI.payRequest = function (reqID) { userUI.payRequest = function (reqID) {
let request = User.moneyRequests[reqID]; let request = User.moneyRequests[reqID];
getConfirmation('Pay?', { message: `Do you want to pay ${request.message.amount} to ${request.senderID}?` }).then(confirmation => { getConfirmation('Pay?', { message: `Do you want to pay ${request.message.amount} to ${request.senderID}?` }).then(confirmation => {
@ -231,7 +213,7 @@ function completeTokenToCashRequest(request) {
}) })
} }
function getFloIdName(floID) { function getFloIdTitle(floID) {
return floGlobals.savedIds[floID] ? floGlobals.savedIds[floID].title : floID; return floGlobals.savedIds[floID] ? floGlobals.savedIds[floID].title : floID;
} }
@ -257,7 +239,6 @@ const render = {
const { title } = details.hasOwnProperty('title') ? details : { title: details }; const { title } = details.hasOwnProperty('title') ? details : { title: details };
const clone = getRef('saved_id_template').content.cloneNode(true).firstElementChild; const clone = getRef('saved_id_template').content.cloneNode(true).firstElementChild;
clone.dataset.floId = floID; clone.dataset.floId = floID;
clone.querySelector('a').href = `#/saved&id=${floID}`;
clone.querySelector('.saved-id__initials').textContent = title.charAt(0); clone.querySelector('.saved-id__initials').textContent = title.charAt(0);
clone.querySelector('.saved-id__title').textContent = title; clone.querySelector('.saved-id__title').textContent = title;
return clone; return clone;
@ -270,11 +251,11 @@ const render = {
clone.querySelector('.transaction__amount').textContent = formatAmount(tokenAmount); clone.querySelector('.transaction__amount').textContent = formatAmount(tokenAmount);
if (sender === myFloID) { if (sender === myFloID) {
clone.classList.add('sent'); clone.classList.add('sent');
clone.querySelector('.transaction__receiver').textContent = `Sent to ${getFloIdName(receiver) || 'Myself'}`; clone.querySelector('.transaction__receiver').textContent = `Sent to ${getFloIdTitle(receiver) || 'Myself'}`;
clone.querySelector('.transaction__icon').innerHTML = `<svg class="icon sent" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/></svg>`; clone.querySelector('.transaction__icon').innerHTML = `<svg class="icon sent" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/></svg>`;
} else if (receiver === myFloID) { } else if (receiver === myFloID) {
clone.classList.add('received'); clone.classList.add('received');
clone.querySelector('.transaction__receiver').textContent = `Received from ${getFloIdName(sender)}`; clone.querySelector('.transaction__receiver').textContent = `Received from ${getFloIdTitle(sender)}`;
clone.querySelector('.transaction__icon').innerHTML = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"/></svg>`; clone.querySelector('.transaction__icon').innerHTML = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"/></svg>`;
} else { //This should not happen unless API returns transaction that does not involve myFloID } else { //This should not happen unless API returns transaction that does not involve myFloID
row.insertCell().textContent = tx.sender; row.insertCell().textContent = tx.sender;
@ -297,8 +278,7 @@ const render = {
return clone; return clone;
}, },
walletRequestCard(details) { walletRequestCard(details) {
const { time, receiverID, message: { mode, amount }, note, tag, vectorClock } = details; const { time, message: { mode, amount }, note, tag, vectorClock } = details;
console.log(details);
const clone = getRef('wallet_request_template').content.cloneNode(true).firstElementChild; const clone = getRef('wallet_request_template').content.cloneNode(true).firstElementChild;
clone.id = vectorClock; clone.id = vectorClock;
clone.querySelector('.wallet-request__details').textContent = `${mode === 'cash-to-token' ? 'Deposit' : 'Withdraw'} ${formatAmount(amount)}`; clone.querySelector('.wallet-request__details').textContent = `${mode === 'cash-to-token' ? 'Deposit' : 'Withdraw'} ${formatAmount(amount)}`;
@ -309,11 +289,8 @@ const render = {
case 'COMPLETED': case 'COMPLETED':
clone.children[1].append( clone.children[1].append(
createElement('div', { createElement('div', {
className: 'grid', className: 'flex flex-wrap align-center wallet-request__note',
innerHTML: ` innerHTML: `<b>Transaction ID:</b><sm-copy value="${note}"></sm-copy>`
<h5 style="margin-bottom: 0.3rem;">Transaction ID</h5>
<sm-copy class="wallet-request__note" value="${note}"></sm-copy>
`
}) })
); );
icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"/></svg>` icon = `<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z"/></svg>`
@ -375,6 +352,52 @@ function showTokenTransfer(type) {
showPopup('token_transfer_popup'); showPopup('token_transfer_popup');
} }
saveId = async function () {
const floID = getRef('flo_id_to_save').value.trim();
const title = getRef('flo_id_title_to_save').value.trim();
floGlobals.savedIds[floID] = { title }
getRef('saved_ids_list').append(render.savedId(floID, { title }));
syncSavedIds().then(() => {
notify(`Saved ${floID}`, 'success');
hidePopup();
}).catch(error => {
notify(error, 'error');
})
}
function syncSavedIds() {
const dataToSend = Crypto.AES.encrypt(JSON.stringify(floGlobals.savedIds), myPrivKey);
return floCloudAPI.sendApplicationData(dataToSend, 'savedIds', { receiverID: myFloID });
}
delegate(getRef('saved_ids_list'), 'click', '.saved-id', e => {
if (e.target.closest('.edit-saved')) {
const target = e.target.closest('.saved-id');
getRef('edit_saved_id').setAttribute('value', target.dataset.floId);
getRef('newAddrLabel').value = getFloIdTitle(target.dataset.floId);
showPopup('edit_saved_popup');
} else {
const target = e.target.closest('.saved-id');
window.location.hash = `#/contact?floId=${target.dataset.floId}`;
}
});
function deleteSaved() {
getConfirmation('Do you want delete this FLO ID?', {
confirmText: 'Delete',
}).then(res => {
if (res) {
const toDelete = getRef('saved_ids_list').querySelector(`.saved-id[data-flo-id="${getRef('edit_saved_id').value}"]`);
if (toDelete)
toDelete.remove();
delete floGlobals.savedIds[getRef('edit_saved_id').value];
hidePopup();
syncSavedIds().then(() => {
notify(`Deleted saved ID`, 'success');
}).catch(error => {
notify(error, 'error');
});
}
});
}
function executeUserAction() { function executeUserAction() {
const floID = getRef('tt_flo_id').value.trim(), const floID = getRef('tt_flo_id').value.trim(),
amount = parseFloat(getRef('tt_amount').value), amount = parseFloat(getRef('tt_amount').value),

View File

@ -186,7 +186,7 @@ function getFormattedTime(time, format) {
return `${month} ${date}, ${year}`; return `${month} ${date}, ${year}`;
break; break;
default: default:
return `${month} ${date} ${year}, ${finalHours}`; return `${month} ${date}, ${year} at ${finalHours}`;
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -307,6 +307,9 @@ async function showPage(targetPage, options = {}) {
getRef('generated_private_key').value = privKey getRef('generated_private_key').value = privKey
targetPage = 'sign_up' targetPage = 'sign_up'
break; break;
case 'contact':
getRef('contact__title').textContent = getFloIdTitle(params.floId)
break;
case 'history': case 'history':
let transactionsList = [] let transactionsList = []
if (!params.hasOwnProperty('type')) { if (!params.hasOwnProperty('type')) {
@ -351,12 +354,13 @@ async function showPage(targetPage, options = {}) {
walletHistoryLoader.update(transactionsList) walletHistoryLoader.update(transactionsList)
} else { } else {
walletHistoryLoader = new LazyLoader('#wallet_history', transactionsList, render.walletRequestCard); walletHistoryLoader = new LazyLoader('#wallet_history', transactionsList, render.walletRequestCard);
// to-do: set value of history type selector
} }
walletHistoryLoader.init() walletHistoryLoader.init()
break;
default: default:
break; break;
} }
getRef('history_type_selector').value = params.type
break; break;
default: default:
break; break;
@ -365,7 +369,23 @@ async function showPage(targetPage, options = {}) {
if (pagesData.lastPage !== pageId) { if (pagesData.lastPage !== pageId) {
document.querySelectorAll('.page').forEach(page => page.classList.add('hide')) document.querySelectorAll('.page').forEach(page => page.classList.add('hide'))
getRef(pageId).classList.remove('hide') getRef(pageId).classList.remove('hide')
getRef(pageId).animate([{ opacity: 0 }, { opacity: 1 }], { duration: 300, fill: 'forwards', easing: 'ease' }) getRef('pages_container').style.overflowY = "hidden";
getRef(pageId).animate([
{
opacity: 0,
transform: 'translateY(1rem)'
},
{
opacity: 1,
transform: 'translateY(0)'
},
],
{
duration: 300,
easing: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)'
}).onfinish = () => {
getRef('pages_container').style.overflowY = "";
}
pagesData.lastPage = pageId pagesData.lastPage = pageId
} }
if (params) if (params)