Adding trusted banker UI

This commit is contained in:
sairaj mote 2023-09-06 16:45:00 +05:30
parent fb41ba1617
commit 5afc2dc984
5 changed files with 218 additions and 151 deletions

View File

@ -779,6 +779,7 @@ h3 {
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
padding: max(1rem, 1.5vw); padding: max(1rem, 1.5vw);
border-radius: 0.5rem; border-radius: 0.5rem;
--progress-line-thickness: 0.15rem;
} }
.loan-process ul { .loan-process ul {
display: grid; display: grid;
@ -798,22 +799,24 @@ h3 {
grid-area: 1/1/2/2; grid-area: 1/1/2/2;
} }
.loan-process li.done .circle { .loan-process li.done .circle {
background-color: var(--green); border-width: 0.3rem;
border: solid 0.1rem var(--green); border-color: var(--green);
} }
.loan-process li.done .line { .loan-process li.done .line {
background-color: var(--green); background-color: var(--green);
} }
.loan-process .circle { .loan-process .circle {
width: 1rem; margin-top: 0.2rem;
height: 1rem; width: 0.8rem;
height: 0.8rem;
border-radius: 50%; border-radius: 50%;
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
z-index: 1; z-index: 1;
border: solid 0.1rem rgba(var(--text-color), 0.5); border: solid var(--progress-line-thickness) rgba(var(--text-color), 0.5);
} }
.loan-process .line { .loan-process .line {
width: 0.1rem; margin-top: 0.2rem;
width: var(--progress-line-thickness);
height: 100%; height: 100%;
background-color: rgba(var(--text-color), 0.5); background-color: rgba(var(--text-color), 0.5);
} }

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -735,6 +735,7 @@ h3 {
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
padding: max(1rem, 1.5vw); padding: max(1rem, 1.5vw);
border-radius: 0.5rem; border-radius: 0.5rem;
--progress-line-thickness: 0.15rem;
ul { ul {
display: grid; display: grid;
li { li {
@ -754,23 +755,25 @@ h3 {
} }
li.done { li.done {
.circle { .circle {
background-color: var(--green); border-width: 0.3rem;
border: solid 0.1rem var(--green); border-color: var(--green);
} }
.line { .line {
background-color: var(--green); background-color: var(--green);
} }
} }
.circle { .circle {
width: 1rem; margin-top: 0.2rem;
height: 1rem; width: 0.8rem;
height: 0.8rem;
border-radius: 50%; border-radius: 50%;
background-color: rgba(var(--foreground-color), 1); background-color: rgba(var(--foreground-color), 1);
z-index: 1; z-index: 1;
border: solid 0.1rem rgba(var(--text-color), 0.5); border: solid var(--progress-line-thickness) rgba(var(--text-color), 0.5);
} }
.line { .line {
width: 0.1rem; margin-top: 0.2rem;
width: var(--progress-line-thickness);
height: 100%; height: 100%;
background-color: rgba(var(--text-color), 0.5); background-color: rgba(var(--text-color), 0.5);
} }

View File

@ -559,9 +559,11 @@
setIsLending(true) setIsLending(true)
btcMortgage.respondLoan(vectorClock, borrower, coborrower).then(() => { btcMortgage.respondLoan(vectorClock, borrower, coborrower).then(() => {
floCloudAPI.sendApplicationData({ loan_opening_process_id }, 'in_process_loan_request') floCloudAPI.sendApplicationData({ loan_opening_process_id }, 'in_process_loan_request')
.catch(error => console.log(error)) .then(() => {
notify('Lending process started successfully.', 'success') notify('Lending process started successfully.', 'success')
router.routeTo(location.hash) router.routeTo(location.hash)
})
.catch(error => console.log(error))
}).catch(err => { }).catch(err => {
console.error(err) console.error(err)
notify('There was error starting lending process. please try again after some time.', 'error') notify('There was error starting lending process. please try again after some time.', 'error')
@ -999,17 +1001,106 @@
let userAddressTimeInterval; let userAddressTimeInterval;
function renderHome(appState) { function renderHome(appState) {
const { lastPage, page, params: { } = {}, wildcards: [section = 'my-loans'] = [] } = appState || {}; const { lastPage, page, params: { } = {}, wildcards: [section = 'my-loans'] = [] } = appState || {};
if (floGlobals.isSubAdmin) { const balanceCard = Component(() => {
renderElem(getRef('sub_page_container'), html` const [btcBalance, setBtcBalance] = useState(floGlobals.memoBalance['BTC'])
<section> const [floBalance, setFloBalance] = useState(floGlobals.memoBalance['FLO'])
<h1>Sub Admin Dashboard</h1> const [usdBalance, setUsdBalance] = useState(floGlobals.memoBalance['USD'])
</section> const [isRefreshing, setIsRefreshing] = useState(false)
`); function fetchBalance() {
} else if (floGlobals.isAdmin) { setIsRefreshing(true)
renderElem(getRef('sub_page_container'), html` Promise.allSettled([
btcOperator.getBalance(floGlobals.myBtcID),
floBlockchainAPI.getBalance(floGlobals.myFloID),
floTokenAPI.getBalance(floGlobals.myFloID, 'usd')
]).then(result => {
const [btcBalance, floBalance, usdBalance] = result.map(({ value }) => value)
floGlobals.memoBalance = {
'FLO': floBalance,
'BTC': btcBalance,
'USD': usdBalance
}
setBtcBalance(btcBalance)
setFloBalance(floBalance)
setUsdBalance(usdBalance)
}).catch(error => {
console.error(error)
}).finally(() => {
setIsRefreshing(false)
})
}
useEffect(() => {
if (lastPage !== page)
fetchBalance()
}, [])
return html`
<div class="grid gap-1-5">
<div class="flex align-center space-between gap-1">
<h4>My balances</h4>
<button class="button button--colored button--small" disabled=${isRefreshing} onclick=${fetchBalance}>
${isRefreshing ? html`
Refreshing <sm-spinner class="margin-left-0-5"></sm-spinner>
`: html`
Refresh
`}
</button>
</div>
<ul id="balance_list">
<li class="balance-card">
<span>BTC</span>
<span>${formatAmount(btcBalance)}</span>
</li>
<li class="balance-card">
<span>FLO</span>
<span>${formatAmount(floBalance, 'FLO')}</span>
</li>
<li class="balance-card">
<span>USD</span>
<span>${formatAmount(usdBalance, 'usd')}</span>
</li>
</ul>
</div>
`
})
if (floCrypto.isSameAddr(btcMortgage.banker.id, floDapps.user.id)) {
const bankerInbox = Component(() => {
const requests = Object.entries(floGlobals.bankerRequests || {}).map(([requestId, requestDetails]) => {
switch (requestDetails.type) {
case 'type_unlock_collateral_request':
break;
case 'type_refund_collateral_request':
break;
case 'type_liquate_collateral_request':
break;
case 'type_preliquate_collateral_request':
break;
default:
return html``
}
})
return html`
<section class="grid gap-1"> <section class="grid gap-1">
<h1>Admin Dashboard</h1> <h3>Banker Inbox</h3>
${requests.length ? html`
<ul id="banker_inbox_list">
${requests}
</ul>
`: html`
<strong>
No requests
</strong>
`}
</section> </section>
`
})
renderElem(getRef('sub_page_container'), html`
<div id="main_page" class="grid gap-2">
${balanceCard()}
${bankerInbox()}
</div>
`); `);
} else { } else {
// user homepage // user homepage
@ -1111,66 +1202,6 @@
</section> </section>
` `
}) })
const balanceCard = Component(() => {
const [btcBalance, setBtcBalance] = useState(floGlobals.memoBalance['BTC'])
const [floBalance, setFloBalance] = useState(floGlobals.memoBalance['FLO'])
const [usdBalance, setUsdBalance] = useState(floGlobals.memoBalance['USD'])
const [isRefreshing, setIsRefreshing] = useState(false)
function fetchBalance() {
setIsRefreshing(true)
Promise.allSettled([
btcOperator.getBalance(floGlobals.myBtcID),
floBlockchainAPI.getBalance(floGlobals.myFloID),
floTokenAPI.getBalance(floGlobals.myFloID, 'usd')
]).then(result => {
const [btcBalance, floBalance, usdBalance] = result.map(({ value }) => value)
floGlobals.memoBalance = {
'FLO': floBalance,
'BTC': btcBalance,
'USD': usdBalance
}
setBtcBalance(btcBalance)
setFloBalance(floBalance)
setUsdBalance(usdBalance)
}).catch(error => {
console.error(error)
}).finally(() => {
setIsRefreshing(false)
})
}
useEffect(() => {
if (lastPage !== page)
fetchBalance()
}, [])
return html`
<div class="grid gap-1-5">
<div class="flex align-center space-between gap-1">
<h4>My balances</h4>
<button class="button button--colored button--small" disabled=${isRefreshing} onclick=${fetchBalance}>
${isRefreshing ? html`
Refreshing <sm-spinner class="margin-left-0-5"></sm-spinner>
`: html`
Refresh
`}
</button>
</div>
<ul id="balance_list">
<li class="balance-card">
<span>BTC</span>
<span>${formatAmount(btcBalance)}</span>
</li>
<li class="balance-card">
<span>FLO</span>
<span>${formatAmount(floBalance, 'FLO')}</span>
</li>
<li class="balance-card">
<span>USD</span>
<span>${formatAmount(usdBalance, 'usd')}</span>
</li>
</ul>
</div>
`
})
renderElem(getRef('sub_page_container'), html` renderElem(getRef('sub_page_container'), html`
<div id="main_page" class="grid gap-2"> <div id="main_page" class="grid gap-2">
${balanceCard()} ${balanceCard()}
@ -1365,9 +1396,38 @@
setInterval(() => { setInterval(() => {
fetchBtcRate() fetchBtcRate()
}, 1000 * 60 * 5) // check BTC rate every 5 minutes }, 1000 * 60 * 5) // check BTC rate every 5 minutes
btcMortgage.init().then(result => { btcMortgage.init().then(async result => {
console.info(result) console.info(result)
Promise.allSettled([ try {
if (floCrypto.isSameAddr(floDapps.user.id, btcMortgage.banker.id)) {
floCloudAPI.requestApplicationData(null, {
callback: (d, e) => {
if (e) return
for (const key in d) {
if (
d[key].type === 'type_unlock_collateral_request' ||
d[key].type === 'type_unlock_collateral_ack' ||
d[key].type === 'type_refund_collateral_request' ||
d[key].type === 'type_refund_collateral_ack' ||
d[key].type === 'type_liquate_collateral_request' ||
d[key].type === 'type_liquate_collateral_ack' ||
d[key].type === 'type_preliquate_collateral_request' ||
d[key].type === 'type_preliquate_collateral_ack'
) {
floGlobals.bankerRequests = {
...floGlobals.bankerRequests || {},
[key]: d[key]
}
}
}
console.log('LOAN REQUESTS', d)
if (floGlobals.loaded) {
router.routeTo(window.location.hash)
}
}
})
} else {
const result = await Promise.allSettled([
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
btcMortgage.viewMyInbox((d, e) => { btcMortgage.viewMyInbox((d, e) => {
if (e) return if (e) return
@ -1435,7 +1495,8 @@
} }
}) })
}) })
]).then(result => { ])
}
console.log(result) console.log(result)
if (['#/landing', '#/sign_in', '#/sign_up'].includes(window.location.hash)) { if (['#/landing', '#/sign_in', '#/sign_up'].includes(window.location.hash)) {
history.replaceState(null, null, '#/home') history.replaceState(null, null, '#/home')
@ -1444,10 +1505,9 @@
router.routeTo(window.location.hash) router.routeTo(window.location.hash)
} }
floGlobals.loaded = true floGlobals.loaded = true
}).catch(error => { } catch (error) {
console.error(error)
notify(error, 'error') notify(error, 'error')
}) }
}).catch(error => { }).catch(error => {
let isBrave = navigator.brave !== undefined let isBrave = navigator.brave !== undefined
if (error === 'Cloud offline') { if (error === 'Cloud offline') {

View File

@ -6,6 +6,7 @@
const APP_NAME = "BTCMortgage"; const APP_NAME = "BTCMortgage";
const APP_IDENTIFIER = "BTC Mortgage"; const APP_IDENTIFIER = "BTC Mortgage";
const BANKER_ID = "F6uMddaTDCZgojENbqRnFo5PCknArE7dKz"; const BANKER_ID = "F6uMddaTDCZgojENbqRnFo5PCknArE7dKz";
// const BANKER_ID = "FPFeL5PXzW9bGosUjQYCxTHSMHidnygvvd";
const BANKER_PUBKEY = '03EE0FB1868EE7D03BC741B10CD56057769445C7D37703115E428A93236C714E61'; const BANKER_PUBKEY = '03EE0FB1868EE7D03BC741B10CD56057769445C7D37703115E428A93236C714E61';
const CURRENCY = "usd"; const CURRENCY = "usd";