-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/swap-layout
- Loading branch information
Showing
51 changed files
with
868 additions
and
972 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { mixins, WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web'; | ||
import isEqual from 'lodash/fp/isEqual'; | ||
import { Component, Mixins } from 'vue-property-decorator'; | ||
|
||
import { type FetchVariables } from '@/types/indexers'; | ||
import { debouncedInputHandler } from '@/utils'; | ||
|
||
@Component | ||
export default class IndexerDataFetchMixin extends Mixins(mixins.LoadingMixin, mixins.PaginationSearchMixin) { | ||
totalCount = 0; | ||
items: any[] = []; | ||
|
||
intervalTimestamp = 0; | ||
private interval: Nullable<ReturnType<typeof setInterval>> = null; | ||
private updateItems = debouncedInputHandler(this.updateData, 250, { leading: false }); | ||
|
||
updateInterval = 24_000; // 4 blocks | ||
|
||
get loadingState(): boolean { | ||
return this.parentLoading || this.loading; | ||
} | ||
|
||
// override PaginationSearchMixin | ||
get total(): number { | ||
return this.totalCount; | ||
} | ||
|
||
get hasItems(): boolean { | ||
return this.total > 0; | ||
} | ||
|
||
get dataVariables(): FetchVariables { | ||
return {}; | ||
} | ||
|
||
get updateVariables(): FetchVariables { | ||
return {}; | ||
} | ||
|
||
checkTriggerUpdate(current: any, prev: any) { | ||
if (!isEqual(current)(prev)) { | ||
this.resetPage(); | ||
this.updateItems(); | ||
} | ||
} | ||
|
||
async requestData(variables: FetchVariables): Promise<{ items: any[]; totalCount: number }> { | ||
console.info('[IndexerDataFetchMixin]: requestData is not implemented'); | ||
return { items: [], totalCount: 0 }; | ||
} | ||
|
||
getItemTimestamp(item: any): number { | ||
console.info('[IndexerDataFetchMixin]: getItemTimestamp is not implemented'); | ||
return 0; | ||
} | ||
|
||
async onPaginationClick(button: WALLET_CONSTS.PaginationButton): Promise<void> { | ||
this.handlePaginationClick(button); | ||
this.updateItems(); | ||
} | ||
|
||
public handlePaginationClick(button: WALLET_CONSTS.PaginationButton): void { | ||
let current = 1; | ||
|
||
switch (button) { | ||
case WALLET_CONSTS.PaginationButton.Prev: | ||
current = this.currentPage - 1; | ||
break; | ||
case WALLET_CONSTS.PaginationButton.Next: | ||
current = this.currentPage + 1; | ||
break; | ||
case WALLET_CONSTS.PaginationButton.Last: | ||
current = this.lastPage; | ||
break; | ||
} | ||
|
||
this.currentPage = current; | ||
} | ||
|
||
private async updateData(): Promise<void> { | ||
this.resetDataSubscription(); | ||
|
||
await this.fetchData(); | ||
|
||
if (this.currentPage === 1) { | ||
this.updateIntervalTimestamp(); | ||
this.subscribeOnData(); | ||
} | ||
} | ||
|
||
private async fetchData(): Promise<void> { | ||
await this.withLoading(async () => { | ||
await this.withParentLoading(async () => { | ||
const { totalCount, items } = await this.requestData(this.dataVariables); | ||
this.totalCount = totalCount; | ||
this.items = items; | ||
}); | ||
}); | ||
} | ||
|
||
private async fetchDataUpdates(): Promise<void> { | ||
const { items, totalCount } = await this.requestData(this.updateVariables); | ||
this.items = [...items, ...this.items].slice(0, this.pageAmount); | ||
this.totalCount = this.totalCount + totalCount; | ||
this.updateIntervalTimestamp(); | ||
} | ||
|
||
private updateIntervalTimestamp(): void { | ||
this.intervalTimestamp = Math.floor(this.getItemTimestamp(this.items[0]) / 1000); | ||
} | ||
|
||
private subscribeOnData(): void { | ||
this.resetDataSubscription(); | ||
this.interval = setInterval(() => this.fetchDataUpdates(), this.updateInterval); | ||
} | ||
|
||
private resetDataSubscription(): void { | ||
if (this.interval) { | ||
clearInterval(this.interval); | ||
} | ||
this.interval = null; | ||
} | ||
|
||
beforeDestroy(): void { | ||
this.resetDataSubscription(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<dialog-base :visible.sync="isVisible"> | ||
<div id="cede-widget" /> | ||
</dialog-base> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { renderSendWidget } from '@cedelabs/widgets-universal'; | ||
import { components, mixins, WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web'; | ||
import Theme from '@soramitsu-ui/ui-vue2/lib/types/Theme'; | ||
import { Component, Mixins, Watch } from 'vue-property-decorator'; | ||
import { getter, state } from '@/store/decorators'; | ||
@Component({ | ||
components: { | ||
DialogBase: components.DialogBase, | ||
}, | ||
}) | ||
export default class CedeStoreWidget extends Mixins(mixins.DialogMixin, mixins.LoadingMixin, mixins.TranslationMixin) { | ||
@state.wallet.settings.soraNetwork soraNetwork!: Nullable<WALLET_CONSTS.SoraNetwork>; | ||
@state.wallet.account.address accountAddress!: string; | ||
@getter.libraryTheme libraryTheme!: Theme; | ||
rootSelector = '#cede-widget'; | ||
@Watch('isVisible', { immediate: true }) | ||
private loadCedeWidget(): void { | ||
if (this.isVisible) { | ||
// NOTE: the line should be removed after extension update. | ||
localStorage.removeItem('SendStore'); | ||
try { | ||
this.$nextTick(() => { | ||
renderSendWidget(this.rootSelector, { | ||
config: { | ||
tokenSymbol: 'XOR', | ||
network: 'sora', | ||
address: this.accountAddress, | ||
lockNetwork: true, | ||
}, | ||
theme: { | ||
mode: this.libraryTheme, | ||
logoTheme: this.libraryTheme, | ||
fontFamily: 'Sora', | ||
width: '450px', | ||
accentColor: '#f8087b', | ||
logoBorderColor: '#f8087b', | ||
warningColor: '#eba332', | ||
errorColor: '#f754a3', | ||
}, | ||
}); | ||
}); | ||
} catch (error) { | ||
console.error("[CEDE STORE] wasn't loaded.", error); | ||
} | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.