Skip to content

Commit

Permalink
feat: removing action.js from store
Browse files Browse the repository at this point in the history
  • Loading branch information
konradodo committed Sep 19, 2023
1 parent ebf8712 commit 8e78599
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 45 deletions.
5 changes: 3 additions & 2 deletions src/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
useUi,
useViewport,
} from '@/composables';
import { useAeTippingBackend } from '@/protocols/aeternity/composables';
import Header from '@/popup/components/Header.vue';
import NodeConnectionStatus from '@/popup/components/NodeConnectionStatus.vue';
import Close from '@/icons/close.svg?vue-component';
Expand All @@ -98,6 +98,7 @@ export default defineComponent({
const store = useStore();
const route = useRoute();
const { t } = useI18n();
const { getCacheChainNames } = useAeTippingBackend();
const { watchConnectionStatus } = useConnection();
const { initVisibilityListeners } = useUi();
Expand Down Expand Up @@ -161,7 +162,7 @@ export default defineComponent({
}
async function fetchAndSetChainNames() {
store.commit('setChainNames', await store.dispatch('getCacheChainNames'));
store.commit('setChainNames', await getCacheChainNames());
}
watch(isLoggedIn, (val) => {
Expand Down
4 changes: 3 additions & 1 deletion src/popup/pages/DonateError.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</template>

<script>
import { useAeTippingBackend } from '@/protocols/aeternity/composables';
import { useModals } from '../../composables';
import FormTextarea from '../components/form/FormTextarea.vue';
import BtnMain from '../components/buttons/BtnMain.vue';
Expand All @@ -65,9 +66,10 @@ export default {
methods: {
async donate() {
const { openDefaultModal } = useModals();
const { donateError } = useAeTippingBackend();
try {
await this.$store.dispatch('donateError', { ...this.entry, description: this.description });
await donateError({ ...this.entry, description: this.description });
await openDefaultModal({
title: this.$t('modals.donate-errors.title'),
msg: this.$t('modals.donate-errors.msg'),
Expand Down
5 changes: 3 additions & 2 deletions src/popup/pages/Retip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import { AE_COIN_PRECISION, AE_CONTRACT_ID } from '@/protocols/aeternity/config'
import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory';
import { PROTOCOL_AETERNITY } from '@/constants';
import { useAeTippingBackend } from '@/protocols/aeternity/composables';
import { useGetter } from '../../composables/vuex';
import InputAmount from '../components/InputAmount.vue';
import UrlStatus from '../components/UrlStatus.vue';
Expand All @@ -123,7 +124,7 @@ export default defineComponent({
const formModel = ref<IFormModel>({
amount: '',
});
const { getCacheTip } = useAeTippingBackend();
const { isTippingSupported } = useAeSdk({ store });
const { openDefaultModal } = useModals();
const { marketData } = useCurrencies({ store });
Expand Down Expand Up @@ -229,7 +230,7 @@ export default defineComponent({
if (!tipId) throw new Error('"id" param is missing');
try {
tip.value = await store.dispatch('getCacheTip', tipId);
tip.value = await getCacheTip(tipId as string);
} catch (error: any) {
error.payload = tipId;
throw error;
Expand Down
18 changes: 12 additions & 6 deletions src/popup/pages/TipsClaim.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<BtnMain
:disabled="!normalizedUrl || !isTippingSupported"
extend
@click="claimTips"
@click="handleClaimTips"
>
{{ $t('common.confirm') }}
</BtnMain>
Expand Down Expand Up @@ -66,6 +66,7 @@ import { ROUTE_ACCOUNT } from '@/popup/router/routeNames';
import { AE_BLOG_CLAIM_TIP_URL } from '@/protocols/aeternity/config';
import { aettosToAe } from '@/protocols/aeternity/helpers';
import { useAeTippingBackend } from '@/protocols/aeternity/composables';
import InputField from '../components/InputField.vue';
import BtnMain from '../components/buttons/BtnMain.vue';
import BtnHelp from '../components/buttons/BtnHelp.vue';
Expand All @@ -83,6 +84,11 @@ export default defineComponent({
const { t } = useI18n();
const store = useStore();
const router = useRouter();
const {
claimTips,
cacheInvalidateOracle,
cacheInvalidateTips,
} = useAeTippingBackend();
const { isTippingSupported } = useAeSdk({ store });
const { activeAccount } = useAccounts({ store });
Expand All @@ -96,7 +102,7 @@ export default defineComponent({
() => isUrlValid(tipUrl.value) ? toURL(tipUrl.value).toString() : '',
);
async function claimTips() {
async function handleClaimTips() {
const url = normalizedUrl.value;
loading.value = true;
try {
Expand All @@ -111,10 +117,10 @@ export default defineComponent({
if (!claimAmount) {
throw new Error('NO_ZERO_AMOUNT_PAYOUT');
}
await store.dispatch('claimTips', { url, address: activeAccount.value.address });
await claimTips(url, activeAccount.value.address);
await Promise.all([
store.dispatch('cacheInvalidateOracle'),
store.dispatch('cacheInvalidateTips'),
cacheInvalidateOracle,
cacheInvalidateTips,
]);
openModal(MODAL_CLAIM_SUCCESS, { url, claimAmount });
Expand Down Expand Up @@ -159,12 +165,12 @@ export default defineComponent({
return {
activeAccount,
claimTips,
loading,
normalizedUrl,
tipUrl,
isTippingSupported,
AE_BLOG_CLAIM_TIP_URL,
handleClaimTips,
};
},
});
Expand Down
40 changes: 40 additions & 0 deletions src/protocols/aeternity/composables/aeTippingBackend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useAeNetworkSettings } from '@/protocols/aeternity/composables/aeNetworkSettings';
import { fetchJson, postJson } from '@/utils';

export function useAeTippingBackend() {
const { aeActiveNetworkSettings } = useAeNetworkSettings();
const { backendUrl } = aeActiveNetworkSettings.value;

function claimTips(url: string, address: string) {
return postJson(`${backendUrl}/claim/submit`, { body: { url, address } });
}

function cacheInvalidateOracle() {
return fetchJson(`${backendUrl}/cache/invalidate/oracle`);
}

function cacheInvalidateTips() {
return fetchJson(`${backendUrl}/cache/invalidate/tips`);
}

function donateError(error: Record<string, any>) {
return postJson(`${backendUrl}/errorreport`, { body: error });
}

function getCacheChainNames() {
return fetchJson(`${backendUrl}/cache/chainnames`);
}

function getCacheTip(id: string) {
return fetchJson(`${backendUrl}/tips/single/${id}`);
}

return {
claimTips,
cacheInvalidateOracle,
cacheInvalidateTips,
donateError,
getCacheChainNames,
getCacheTip,
};
}
1 change: 1 addition & 0 deletions src/protocols/aeternity/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './aeNetworkSettings';
export * from './aeTippingBackend';
32 changes: 0 additions & 32 deletions src/store/actions.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Vuex from 'vuex';
import getters from './getters';
import mutations from './mutations';
import actions from './actions';
import persistState from './plugins/persistState';
import tipUrl from './plugins/tipUrl';
import namesPlugin from './plugins/names';
Expand Down Expand Up @@ -30,7 +29,6 @@ export default new Vuex.Store({
},
getters,
mutations,
actions,
plugins: [
persistState(
runMigrations,
Expand Down

0 comments on commit 8e78599

Please sign in to comment.