Files
wallet-web/src/components/wallet-header/WalletHeaderElement.ts
Fran Jurmanović 6b152d320c changes to structure
2021-10-11 19:54:26 +02:00

58 lines
1.2 KiB
TypeScript

import { TemplateResult, attr, controller } from 'core/utils';
import { BaseComponentElement } from 'common/';
import { findMethod } from 'core/utils';
import { WalletHeaderElementTemplate } from 'components/wallet-header';
@controller
class WalletHeaderElement extends BaseComponentElement {
@attr currentBalance: number;
@attr lastMonth: number;
@attr nextMonth: number;
@attr currency: string;
@attr custom: string;
initial: boolean = false;
fetchFunc: Function = () => {};
constructor() {
super();
}
elementConnected = (): void => {
this.executeFetch();
this.update();
};
attributeChangedCallback(): void {
this.update();
}
get submitFunc() {
return findMethod(this.custom, this.appMain);
}
executeFetch = async (options?): Promise<void> => {
try {
this.loader?.start?.();
await this.submitFunc(options);
this.loader?.stop?.();
} catch (err) {
this.loader?.stop?.();
console.error(err);
} finally {
this.initial = true;
}
};
render = (): TemplateResult =>
WalletHeaderElementTemplate({
currentBalance: this.currentBalance,
currency: this.currency,
lastMonth: this.lastMonth,
nextMonth: this.nextMonth,
loader: this.loader,
initial: this.initial,
});
}
export type { WalletHeaderElement };