Skip to content

Commit

Permalink
Merge branch 'rmrk-lite' of github.com:kodadot/nft-gallery into rmrk-…
Browse files Browse the repository at this point in the history
…lite
  • Loading branch information
yangwao committed Feb 10, 2021
2 parents 42812e6 + c749ece commit ccdcd4d
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 151 deletions.
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@polkadot/vue-identicon": "^0.68.1",
"@polkadot/wasm-crypto": "^3.2.2",
"@polkadot/wasm-crypto-wasm": "^3.2.2",
"@textile/hub": "^4.0.0",
"@textile/hub": "^6.0.1",
"@types/file-saver": "^2.0.1",
"@vue-polkadot/vue-api": "^0.0.27",
"@vue-polkadot/vue-identicon": "^0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Dashboard extends Vue {
keyring.loadAll({
ss58Format: this.ss58Format || 42,
type: 'sr25519',
isDevelopment: Boolean(process.env.VUE_APP_KEYRING) || false,
isDevelopment: process.env.VUE_APP_KEYRING === 'true' || false,
});
}
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/rmrk/Create/CreateItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface NFTAndMeta extends NFT {
})
export default class CreateItem extends Vue {
@Prop() public index!: number;
@Prop() public alreadyMinted!: number;
@Prop() public view!: NFTAndMeta;
private tooltip: object = {
name: 'Name of your token',
Expand All @@ -92,7 +93,7 @@ export default class CreateItem extends Vue {
}
get serialNumber(): string {
return String(this.index + 1).padStart(16, '0');
return String(this.index + 1 + this.alreadyMinted).padStart(16, '0');
}
private async m() {
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/rmrk/Create/CreateToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<CreateItem
v-for="(item, index) in added"
:key="index"
:index="index + alreadyMinted"
:index="index"
:alreadyMinted="alreadyMinted"
:view="item"
@update="handleUpdate"
@upload="uploadFile"
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/components/rmrk/Gallery/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import { fetchNFTMetadata, sanitizeIpfsUrl } from '../utils';
type NFTType = NFT | NFTWithMeta;
const nftSort = (a: any, b: any) => b._mod - a._mod
@Component({})
export default class Gallery extends Vue {
private nfts: NFTType[] = [];
Expand All @@ -75,7 +77,7 @@ export default class Gallery extends Vue {
this.isLoading = true;
try {
this.nfts = await rmrkService.getAllNFTs();
this.nfts = await rmrkService.getAllNFTs().then(arr => arr.slice().sort(nftSort));
this.collectionMeta();
} catch (e) {
console.warn(e);
Expand Down
16 changes: 16 additions & 0 deletions dashboard/src/components/rmrk/service/RmrkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RmrkEvent, RMRK, RmrkInteraction } from '../types'
import NFTUtils from './NftUtils'
import { emptyObject } from '@/utils/empty';
import Consolidator, { generateId } from './Consolidator';
import { keyInfo as keysToTheKingdom } from '@/textile'

export type RmrkType = Collection | NFT | Emotion

Expand Down Expand Up @@ -43,7 +44,20 @@ export class RmrkService extends TextileService<RmrkType> implements State {
return rmrkService
}

protected refreshContext() {
return this._client.context.withKeyInfo(keysToTheKingdom)
}

protected async checkExpiredOrElseRefresh() {
console.log('checkExpiredOrElseRefresh', this.isAuthExpired)
if (this.isAuthExpired) {
try {
await this.refreshContext()
} catch (e) {
console.error(`[RMRK] Unable to refresh context::\n ${e}`)
}
}
}

public async onUrlChange(ss58: string | undefined | number): Promise<void> {
const name = ss58 ||(typeof ss58 === 'number' && ss58 >= 0) ? String(ss58) : 'local';
Expand Down Expand Up @@ -282,6 +296,7 @@ export class RmrkService extends TextileService<RmrkType> implements State {
}

private async mint(view: object, caller: string, blocknumber?: string | number): Promise<Collection> {
await this.checkExpiredOrElseRefresh()
const collection = computeAndUpdateCollection(view as Collection);
this.useCollection();

Expand All @@ -308,6 +323,7 @@ export class RmrkService extends TextileService<RmrkType> implements State {
}

private async mintNFT(view: object, caller: string, blocknumber?: string | number): Promise<NFT> {
await this.checkExpiredOrElseRefresh()
const item = computeAndUpdateNft(view as NFT, blocknumber);
this.useCollection();
await this.shouldExist(item.collection);
Expand Down
5 changes: 3 additions & 2 deletions dashboard/src/components/rmrk/service/TextileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default abstract class TextileService<T> {
return TextileService.threadId(this._dbStore)
}

get isAuthExpired(): boolean {
return (this._client.context as any).isExpired
}

abstract get collectioName(): string;
abstract set collectioName(name: string);
Expand Down Expand Up @@ -117,8 +120,6 @@ export default abstract class TextileService<T> {
} catch(e) {
return false
}


}

}
Expand Down
Loading

0 comments on commit ccdcd4d

Please sign in to comment.