Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chg: hide top-up button on dashboard's footer dependng on the ``topUp… #402

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion public/config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@
},
"css": ".nav-item {color: red !important} .refresh {background-color: #009688;}",
"accountsRefreshInterval": 90,
"transactionsRefreshInterval": 47
"transactionsRefreshInterval": 47,
"disableReconversion": true,
"disableTopUp": false
}
5 changes: 4 additions & 1 deletion src/components/BankAccountItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
</a>
<a
href="#"
v-if="account?.safeWalletRecipient && $config?.reconversion"
v-if="
account?.safeWalletRecipient &&
!$config?.disableReconversion
"
class="dropdown-item is-flex"
@click="
$modal.open('MoneyTransferModal', {
Expand Down
68 changes: 37 additions & 31 deletions src/components/ConfirmPaymentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
transactionDetail: $gettext("Transaction details"),
paymentConfirmation: $gettext("Payment confirmation"),
topup: $gettext("Top-up details"),
reconversion: $gettext("Reconversion details"),
}[$modal.args?.value[0].type]
}}
</p>
Expand Down Expand Up @@ -39,6 +40,9 @@
: $gettext("Transaction processed"),
paymentConfirmation: $gettext("Payment sent"),
topup: $gettext("Top-up requested"),
reconversion: $modal.args?.value[0].transaction.pending
? $gettext("Reconversion sent")
: $gettext("Reconversion processed"),
}[$modal.args?.value[0].type]
}}
</p>
Expand Down Expand Up @@ -88,37 +92,39 @@
}))($modal.args?.value[0].transaction)
}}
</p>
<h2
v-if="$modal.args?.value[0].type == 'topup'"
class="frame3-sub-title"
>
{{
$modal.args?.value[0].transaction.paid
? $gettext(
"This top-up request is waiting for an administrator of your local currency to validate it"
)
: $gettext(
"This top-up request is waiting for you to pay it or delete it"
)
}}
</h2>
<h2 v-else class="frame3-sub-title">
{{
$modal.args?.value[0].transaction.amount < 0
? $gettext("to")
: $gettext("from")
}}
</h2>
<p
class="
frame3-sub-title
has-text-weight-bold
is-size-3
hide-overflow
"
>
{{ $modal.args?.value[0].transaction.related }}
</p>
<div v-if="$modal.args?.value[0].type !== 'reconversion'">
<h2
v-if="$modal.args?.value[0].type == 'topup'"
class="frame3-sub-title"
>
{{
$modal.args?.value[0].transaction.paid
? $gettext(
"This top-up request is waiting for an administrator of your local currency to validate it"
)
: $gettext(
"This top-up request is waiting for you to pay it or delete it"
)
}}
</h2>
<h2 v-else class="frame3-sub-title">
{{
$modal.args?.value[0].transaction.amount < 0
? $gettext("to")
: $gettext("from")
}}
</h2>
<p
class="
frame3-sub-title
has-text-weight-bold
is-size-3
hide-overflow
"
>
{{ $modal.args?.value[0].transaction.related }}
</p>
</div>

<p class="frame3-sub-title mb-3">
{{ dateFormat }}
Expand Down
45 changes: 43 additions & 2 deletions src/components/MoneyTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<template v-slot:name>{{ account.name() }}</template>
</BankAccountItem>
</div>
<div v-if="selectedRecipient">
<div v-if="selectedRecipient && !isReconversion">
<h2 class="frame3-sub-title mb-3">
{{ $gettext("To") }}
</h2>
Expand Down Expand Up @@ -51,6 +51,7 @@
{{ parentErrors }}
</div>
<textarea
v-if="!isReconversion"
@input="handleMessageInput()"
v-model="message"
class="custom-textarea textarea mt-5"
Expand All @@ -59,7 +60,10 @@
}"
:placeholder="$gettext('Add a memo (optional)')"
></textarea>
<div class="notification is-danger is-light mt-2" v-if="errors.message">
<div
class="notification is-danger is-light mt-2"
v-if="!isReconversion && errors.message"
>
{{ errors.message }}
</div>
</div>
Expand Down Expand Up @@ -131,6 +135,43 @@
)
return
}

const amountStrRaw = this.$refs.amountRequested.value
const amountStr = this.amount.toString()
// XXXvlab: this is the maximum size of a XXXX.YY that
// is safely converted to a number in javascript. (We
// can garantee that what the user typed in is
// eauivalent to what we get in the code.
const maxValue = Number.MAX_SAFE_INTEGER / 2 ** 7
if (this.amount > maxValue) {
this.errors.amount = this.$gettext(
"Amount to send is too large (<= %{ maxValue })",
{ maxValue }
)
return
}

const amountParts = amountStrRaw.split(".")

if (amountParts.length > 1) {
if (amountParts[1].length > 2) {
this.errors.amount = this.$gettext(
"Amount to send must be a number with not more than 2 decimals"
)
return
}
}
if (
!(
amountStr == this.$refs.amountRequested.value ||
(amountParts.length > 1 && /0+$/.test(amountParts[1]))
)
) {
this.errors.amount = this.$gettext(
"Unexpected amount received. Try to reenter your amount, and if the problem persists please contact your administator."
)
return
}
this.errors.amountLength = this.amount.length === 0
this.$emit("update:amount", parseFloat(this.amount).toFixed(2))
this.errors.amount = false
Expand Down
17 changes: 5 additions & 12 deletions src/components/MoneyTransferModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,11 @@
return
}
this.transferOngoing = true

this.errors = false

if (this.ownSelectedAccount._obj.getGlobalBalance) {
if (this.ownSelectedAccount._obj.getBalance) {
let realBal
try {
realBal = await this.ownSelectedAccount._obj.getGlobalBalance(
"latest"
)
realBal = await this.ownSelectedAccount._obj.getBalance("latest")
} catch (err) {
this.$msg.error(
this.$gettext(
Expand All @@ -351,21 +347,18 @@
"please contact your administrator."
)
)
console.error("getGlobalBalance failed:", err)
console.error("getBalance failed:", err)
this.transferOngoing = false
return
}
// ensure realBal is the correct format
if (!(realBal.includes(".") && realBal.split(".")[1].length === 2)) {
throw new Error(
"Invalid amount returned by getGlobalBalance",
realBal
)
throw new Error("Invalid amount returned by getBalance", realBal)
}
const amount_cents = parseInt(this.amount.replace(".", ""))
const realBal_cents = parseInt(realBal.replace(".", ""))
const bal_cents = parseInt(
this.ownSelectedAccount.bal.toFixed(2).replace(".", "")
this.ownSelectedAccount.bal.replace(".", "")
)
// ensure we are in safe limits (we could use BigInt if needed)
Object.entries({ amount_cents, realBal_cents, bal_cents }).forEach(
Expand Down
5 changes: 4 additions & 1 deletion src/components/TheDashboardFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
</span>
</button>
</div>
<div class="column has-text-centered mb-2">
<div
v-if="!$config?.disableTopUp"
class="column has-text-centered mb-2"
>
<button
:disabled="!account"
class="
Expand Down
31 changes: 28 additions & 3 deletions src/components/TransactionItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="pb-3 pt-3 shadow-bottom cursor-pointer">
<div
class="p-3 shadow-bottom cursor-pointer"
:class="{ reconversion: isReconversion }"
>
<div class="is-pulled-right">
<h5 class="custom-card-destinataire has-text-right">
{{ dateFormat(transaction.date) }}
Expand All @@ -26,9 +29,8 @@
{{ numericFormat(parseFloat(transaction.amount)) }}
{{ transaction.currency }}
</h3>

<h4 class="custom-card-destinataire">
{{ transaction.related }}
{{ isReconversion ? $gettext("Reconversion") : transaction.related }}
</h4>
<h5 class="has-text-grey-light transaction-desc">
{{ transaction.description }}
Expand All @@ -48,6 +50,24 @@
props: {
transaction: Object,
},
data() {
return {
isReconversion: false,
}
},
mounted() {
let safeWalletRecipient
try {
safeWalletRecipient = this.transaction.parent.parent.safeWalletRecipient
} catch (e: any) {
// XXXvlab: already reported this error in service/lokapiService.ts
// console.error(e.message)
this.isReconversion = false
return
}
this.isReconversion =
safeWalletRecipient?.name === this.transaction.related
},
computed: {
...mapGetters(["numericFormat", "relativeDateFormat", "dateFormat"]),
},
Expand Down Expand Up @@ -91,4 +111,9 @@
.cursor-pointer {
cursor: pointer;
}
.reconversion {
background-color: $inner-card-background-color;
margin-top: 3px;
border-radius: 1em;
}
</style>
6 changes: 5 additions & 1 deletion src/components/TransactionListModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@
@click="
$modal.open('ConfirmPaymentModal', {
transaction,
type: 'transactionDetail',
type:
$modal.args.value[0].account.safeWalletRecipient?.name ===
transaction.related
? 'reconversion'
: 'transactionDetail',
})
"
/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/TransactionListRecent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
@click="
$modal.open('ConfirmPaymentModal', {
transaction,
type: 'transactionDetail',
type:
account.safeWalletRecipient?.name === transaction.related
? 'reconversion'
: 'transactionDetail',
})
"
/>
Expand Down
Loading
Loading