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

Prototype/tip endpoint adjustments #1038

Merged
merged 27 commits into from
Jun 17, 2021
Merged
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
290 changes: 170 additions & 120 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
chainNames, topics, verifiedUrls, graylistedUrls, tokenInfo, wordRegistry,
] = await Promise.all([
Backend.getCacheChainNames(),
Backend.getTopicsCache(),
Backend.getTopics(),
Backend.getVerifiedUrls(),
Backend.getGrayListedUrls(),
Backend.getTokenInfo(),
Expand All @@ -87,7 +87,7 @@ export default {
this.setChainNames(chainNames);
this.setGraylistedUrls(graylistedUrls);
this.setVerifiedUrls(verifiedUrls);
this.setTokenInfo(tokenInfo);
this.setTokenInfo(tokenInfo || {});
this.setWordRegistry(wordRegistry);
},
async initWallet() {
Expand All @@ -101,7 +101,6 @@ export default {
} else {
this.setAddress(address);
}
await this.$store.dispatch('initMiddleware');
await this.$store.dispatch('fetchUserInfo');
},
},
Expand Down
3 changes: 1 addition & 2 deletions src/components/AeAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default {
props: {
amount: { type: [String, Number], default: 0 },
round: { type: Number, default: 2 },
aettos: { type: Boolean, required: false },
token: { type: String, default: null },
noSymbol: { type: Boolean },
},
Expand All @@ -31,7 +30,7 @@ export default {
return this.amountTokenInfo ? this.amountTokenInfo.symbol : null;
},
roundedAmount() {
return this.roundedTokenAmount(this.amount || 0, this.token, this.round, this.aettos);
return this.roundedTokenAmount(this.amount || 0, this.token, this.round, true);
},
},
};
Expand Down
4 changes: 1 addition & 3 deletions src/components/FiatValue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { shiftDecimalPlaces } from '../utils';
export default {
props: {
amount: { type: [String, Number], default: 0 },
aettos: { type: Boolean },
token: { type: String, default: null },
noParentheses: { type: Boolean },
noSymbol: { type: Boolean },
Expand All @@ -39,12 +38,11 @@ export default {
}

const decimals = this.token ? -this.tokenData.decimals : -18;
const shiftBy = this.aettos ? decimals : 0;
const price = this.token
? shiftDecimalPlaces(this.tokenData.price, -this.tokenData.decimals)
: 1;

const fiatValue = new BigNumber(shiftDecimalPlaces(this.amount, shiftBy))
const fiatValue = new BigNumber(shiftDecimalPlaces(this.amount, decimals))
.multipliedBy(price).multipliedBy(this.rate)
.toNumber() || 0;

Expand Down
35 changes: 23 additions & 12 deletions src/components/TipInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class="button"
:class="{ tipped: tipUrlStats.isTipped }"
:title="title"
:disabled="!tipUrl"
@click="useSdkWallet && (showModal = true)"
>
<IconTip />
Expand All @@ -16,7 +17,7 @@
/>
</Component>
<Dropdown
v-if="!userAddress && tipUrlStats && tipUrlStats.tokenTotalAmount.length"
v-if="showTokenDropdown"
v-slot="{ option }"
:options="tipUrlStats.tokenTotalAmount"
show-right
Expand All @@ -25,7 +26,6 @@
:key="option.token"
:amount="option.amount"
:token="option.token"
:aettos="!!option.token"
/>
</Dropdown>
<Modal
Expand All @@ -50,7 +50,7 @@
<div class="input-group">
<!-- TODO: Remove this wrapper after removing bootstrap -->
<input
v-if="!tip"
v-if="!isRetippable"
v-model="message"
maxlength="280"
class="message form-control"
Expand All @@ -63,7 +63,7 @@
:select-token-f="token => (inputToken = token)"
/>
<AeButton :disabled="!isValid || v1TipWarning">
{{ tip ? $t('retip') : $t('tip') }}
{{ isRetippable ? $t('retip') : $t('tip') }}
</AeButton>
</div>
</form>
Expand All @@ -75,7 +75,6 @@
<script>
import { mapState, mapGetters } from 'vuex';
import IconTip from '../assets/iconTip.svg?icon-component';
import Backend from '../utils/backend';
import { EventBus } from '../utils/eventBus';
import { createDeepLinkUrl, shiftDecimalPlaces } from '../utils';
import AeInputAmount from './AeInputAmount.vue';
Expand Down Expand Up @@ -114,14 +113,24 @@ export default {
...mapGetters('backend', ['minTipAmount']),
...mapState('backend', {
tipUrlStats({ stats }) {
const urlStats = stats && stats.by_url.find(({ url }) => url === this.tipUrl);
const urlStats = stats && this.tipUrl
&& stats.urlStats.find(({ url }) => url === this.tipUrl);

const tipTokenAmount = this.tip?.token
? [{ token: this.tip.token, amount: this.tip.tokenAmount }] : [];

return {
isTipped: urlStats ? urlStats.senders.includes(this.address) : false,
totalAmountAe: urlStats ? urlStats.total_amount_ae : '0',
tokenTotalAmount: urlStats ? urlStats.token_total_amount : [],
totalAmount: urlStats ? urlStats.totalAmount : this.tip?.amount || '0',
tokenTotalAmount: urlStats ? urlStats.totalTokenAmount : tipTokenAmount,
};
},
}),
showTokenDropdown() {
return !this.userAddress
&& this.tipUrlStats
&& this.tipUrlStats.tokenTotalAmount.length > (this.tipAmount.token ? 1 : 0);
},
largestFtTipAmount() {
return this.tipUrlStats.tokenTotalAmount.length
? this.tipUrlStats.tokenTotalAmount.reduce(
Expand All @@ -131,9 +140,9 @@ export default {
: null;
},
tipAmount() {
return +this.tipUrlStats.totalAmountAe !== 0
return +this.tipUrlStats.totalAmount !== '0'
? {
value: this.tipUrlStats.totalAmountAe,
value: this.tipUrlStats.totalAmount,
token: null,
}
: {
Expand All @@ -148,6 +157,9 @@ export default {
&& this.inputToken !== null
);
},
isRetippable() {
return this.tip && this.tip.type !== 'POST_WITHOUT_TIP';
},
tipUrl() {
if (this.comment) {
return `https://superhero.com/tip/${this.comment.tipId}/comment/${this.comment.id}`;
Expand Down Expand Up @@ -194,7 +206,7 @@ export default {
: 18,
).toFixed();

if (!this.tip) {
if (!this.isRetippable) {
await this.$store.dispatch('aeternity/tip', {
url: this.tipUrl,
title: this.message,
Expand All @@ -211,7 +223,6 @@ export default {
}

if (!this.userAddress) {
await Backend.cacheInvalidateTips();
EventBus.$emit('reloadData');
}
this.hideModal();
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopicList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="text-ellipsis"
:topic="topic"
/>
<AeAmountFiat :amount="data.amount_ae" />
<AeAmountFiat :amount="data.amount" />
</div>
</div>
</template>
Expand Down
28 changes: 8 additions & 20 deletions src/components/UserInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
<script>
import { mapState, mapActions } from 'vuex';
import Backend from '../utils/backend';
import { atomsToAe } from '../utils';
import AeAmountFiat from './AeAmountFiat.vue';
import Avatar from './Avatar.vue';
import { EventBus } from '../utils/eventBus';
Expand Down Expand Up @@ -298,25 +297,20 @@ export default {
tipStats() {
return [
{
value: this.userStats.tipsLength + this.userStats.retipsLength,
value: this.userStats.totalTipsLength,
title: this.$t('views.UserProfileView.TipsSent'),
amount: this.userStats.totalTipAmountAe,
amount: this.userStats.totalAmount,
},
{
title: this.$t('views.UserProfileView.ClaimedAmount'),
amount: this.userStats.claimedAmountAe,
value: this.userStats.urlStats?.totaltipslength,
title: this.$t('views.UserProfileView.TipsReceived'),
amount: this.userStats.urlStats?.totalAmount,
},
...this.currentAddress === this.address ? [{
title: this.$t('views.UserProfileView.UnclaimedAmount'),
amount: this.userStats.unclaimedAmountAe,
}] : [],
];
},
showedStats() {
return [
{ value: this.userStats.userComments, title: this.$t('views.UserProfileView.Comments') },
{ value: this.userStats.tipsLength, title: this.$t('views.UserProfileView.TipsReceived') },
{ value: this.userStats.retipsLength, title: this.$t('views.UserProfileView.RetipsSent') },
{ value: this.userStats.commentCount, title: this.$t('views.UserProfileView.Comments') },
{
value: this.userStats.claimedUrlsLength,
image: SuccessIcon,
Expand Down Expand Up @@ -349,7 +343,7 @@ export default {
...mapActions('backend', ['setCookies']),
async reloadBalance() {
await this.$watchUntilTruly(() => this.sdk);
this.balance = atomsToAe(await this.sdk.balance(this.address).catch(() => 0)).toFixed(2);
this.balance = await this.sdk.balance(this.address).catch(() => 0);
},
async resetEditedValues() {
this.editMode = false;
Expand All @@ -374,17 +368,11 @@ export default {
},
reloadData() {
this.getProfile();
Backend.getCacheUserStats(this.address).then((stats) => {
Backend.getSenderStats(this.address).then((stats) => {
this.userStats = stats;
});
},
async getProfile() {
Backend.getCommentCountForAddress(this.address)
.then((userComment) => {
this.userCommentCount = userComment.count;
})
.catch(console.error);

Backend.getProfile(this.address)
.then((profile) => {
if (!profile) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/WordInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ import FiatValue from './FiatValue.vue';
import TabBar from './TabBar.vue';
import Loader from './Loader.vue';
import Dropdown from './Dropdown.vue';
import { shiftDecimalPlaces, aeToAtoms } from '../utils';
import { shiftDecimalPlaces } from '../utils';

export default {
name: 'WordInfo',
Expand Down Expand Up @@ -288,7 +288,7 @@ export default {
},
chartData() {
const decimals = this.tokenInfo[this.data.tokenAddress]?.decimals ?? 18;
const initialPrice = new BigNumber(aeToAtoms(1)); // currently supports only hardcoded 1AE
const initialPrice = new BigNumber(shiftDecimalPlaces(1, -18));
const sellPrice = new BigNumber(this.data.sellPrice);
const buyPrice = new BigNumber(this.data.buyPrice);
const totalSupply = new BigNumber(this.data.totalSupply);
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout/RightSectionWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
:token="(selectedToken || aeternityTokenData).token"
/>
</template>
<template v-slot="{ option }">
<template #default="{ option }">
<TokenAvatarAndSymbol :address="option.token" />
</template>
</Dropdown>
Expand All @@ -59,7 +59,7 @@
</span>
{{ selectedCurrency.toUpperCase() }}
</template>
<template v-slot="{ option }">
<template #default="{ option }">
<span class="currency-value">
<FiatValue
:amount="(selectedToken || aeternityTokenData).balance"
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/sendTip/SendPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
title: this.$t('components.layout.SendTip.SuccessHeader'),
body: 'Post sent!',
});
setTimeout(() => EventBus.$emit('reloadData'), 5000);
EventBus.$emit('reloadData');
} catch (error) {
console.error(error);
this.$store.dispatch('modals/open', {
Expand Down
41 changes: 19 additions & 22 deletions src/components/layout/sendTip/SendTip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import { mapState, mapGetters } from 'vuex';
import AeInputAmount from '../../AeInputAmount.vue';
import { createDeepLinkUrl, shiftDecimalPlaces, validateTipUrl } from '../../../utils';
import { EventBus } from '../../../utils/eventBus';
import Backend from '../../../utils/backend';
import AeButton from '../../AeButton.vue';
import IconDiamond from '../../../assets/iconDiamond.svg?icon-component';
import IconClose from '../../../assets/iconClose.svg?icon-component';
Expand Down Expand Up @@ -125,28 +124,26 @@ export default {
title: this.sendTipForm.title,
amount,
tokenAddress: this.inputToken,
})
.then(async () => {
await Backend.cacheInvalidateTips().catch(console.error);
this.clearTipForm();
this.$store.dispatch('modals/open', {
name: 'success',
title: this.$t('components.layout.SendTip.SuccessHeader'),
body: this.$t('components.layout.SendTip.SuccessText'),
});
setTimeout(() => EventBus.$emit('reloadData'), 5000);
}).catch((e) => {
this.sendingTip = false;
if (e.code && e.code === 4) {
return;
}
console.error(e);
this.$store.dispatch('modals/open', {
name: 'failure',
title: this.$t('components.layout.SendTip.ErrorHeader'),
body: this.$t('components.layout.SendTip.ErrorText'),
});
}).then(async () => {
this.clearTipForm();
this.$store.dispatch('modals/open', {
name: 'success',
title: this.$t('components.layout.SendTip.SuccessHeader'),
body: this.$t('components.layout.SendTip.SuccessText'),
});
EventBus.$emit('reloadData');
}).catch((e) => {
this.sendingTip = false;
if (e.code && e.code === 4) {
return;
}
console.error(e);
this.$store.dispatch('modals/open', {
name: 'failure',
title: this.$t('components.layout.SendTip.ErrorHeader'),
body: this.$t('components.layout.SendTip.ErrorText'),
});
});
},
clearTipForm() {
this.sendTipForm = { amount: 0, url: '', title: '' };
Expand Down
Loading