Skip to content

Commit

Permalink
🔀 Merge pull request #8 from nekomeowww/master
Browse files Browse the repository at this point in the history
✨ Seperated the different error messages, connected the link to avatar and reset functions, fixed the loading percentage sometimes became NaN
  • Loading branch information
nekomeowww authored Sep 4, 2020
2 parents c552748 + 9cb5a21 commit 60ee9a9
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">ArweaveAvatar</h1>
<p align="center">Avatar upload and manage for Arweave Identification</p>
<p align="center"> Link at Permaweb: <a href="https://arweave.net/d9SXf_N32hAm3cygt1btmPC-7Dg460VhQEtW8I-cfvU">Online</a></p>
<p align="center"> Link to Permaweb: <a href="https://arweave.net/SV9JcBCwCzCUt22pX2xN6BynKi8zdaTrQ57ytu-Vems">Online</a></p>
<p align="center">
<img src="https://github.com/AyakaLab/ArweaveAvatar/workflows/Node%20Build%20Test/badge.svg" />
<img src="https://github.com/AyakaLab/ArweaveAvatar/workflows/Production%20CI%20Build%20Test/badge.svg" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arweave-avatar",
"version": "1.0.1",
"version": "1.0.2",
"description": "Avatar upload and manage for Arweave Identification",
"author": "Ayaka Neko <[email protected]>",
"private": true,
Expand Down
11 changes: 9 additions & 2 deletions src/api/arweave.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let arweave = {
ar.transactions.get(txid).then(detail => {
resolve(detail)
}).catch(err => {
console.log(err)
reject(err)
})
})
Expand Down Expand Up @@ -54,14 +55,20 @@ let arweave = {
}
}).then(async ids => {
if (ids.length === 0) {
resolve(false)
resolve({ result: 'no image found' })
return
}

let detail = await this.getTransactionDetail(ids[0]).catch((err) => {
resolve(err)
console.log(err)
resolve({ result: 'pending on confirm', error: err })
})

if (!detail) {
resolve({ result: 'pending on upload' })
return
}

ar.transactions.getData(detail.id, {decode: true, string: true}).then(data => {
resolve(data)
})
Expand Down
1 change: 0 additions & 1 deletion src/components/imgUpload/imgUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export default {
try {
let res = { data: { code: 0 } }
res.data.code = 0
console.log(file)
this.setAvatarFile(file)
if (res.data.code === 0 || res.data.code === 1) {
this.$emit('doneImageUpload', {
Expand Down
57 changes: 44 additions & 13 deletions src/pages/SetAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default {
imgUploadDone: 0,
loading: true,
loadingPct: 0,
loadingStatus: ''
loadingStatus: undefined
}
},
computed: {
Expand Down Expand Up @@ -149,24 +149,55 @@ export default {
}, 500)
API.arweave.getAvatar(this.walletAddress).then(res => {
if (!res) {
if (res.result === 'no image found') {
this.loadingStatus = 'exception'
this.$message({
message: 'Avatar not Found or is Pending on confirmation',
message: 'No Avatar not Found',
type: 'error',
duration: 4000
duration: 6000
})
clearInterval(intervalId)
}
this.avatar = res
clearInterval(intervalId)
this.loadingPct = 100
setTimeout(() => {
this.loading = false
}, 2000)
this.avatar = false
setTimeout(() => {
this.loading = false
}, 2000)
} else if (res.result === 'pending on confirm') {
this.loadingStatus = 'exception'
this.$message({
message: 'Avatar is pending on confirmation',
type: 'warning',
duration: 6000
})
console.log(res.result.error)
clearInterval(intervalId)
this.avatar = false
this.loadingPct = 100
setTimeout(() => {
this.loading = false
}, 2000)
} else if (res.result === 'pending on upload') {
this.loadingStatus = 'exception'
this.$message({
message: 'Avatar is pending on upload',
type: 'warning',
duration: 6000
})
clearInterval(intervalId)
this.avatar = false
this.loadingPct = 100
setTimeout(() => {
this.loading = false
}, 2000)
} else {
this.loadingStatus = 'success'
this.avatar = res
clearInterval(intervalId)
this.loadingPct = 100
return res
setTimeout(() => {
this.loading = false
}, 2000)
}
})
}, 2000)
}
Expand Down
31 changes: 25 additions & 6 deletions src/pages/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<i class="el-icon-success" style="font-size: 10rem; color: #67C23A;"></i>
<span>Upload Successful!</span>
<span v-if="!upload && avatarLink !== ''" style="margin-top: 1rem;">Link to your avatar: <a :href="avatarLink">{{ avatarLink }}</a></span>
<img :src="getAvatar()" />
<img :src="getAvatar()" class="avatar"/>
</div>
</div>
<Footer />
Expand All @@ -18,7 +18,7 @@

<script>
import { mapState } from 'vuex'
import { mapState, mapActions } from 'vuex'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'
Expand All @@ -36,19 +36,29 @@ export default {
}
},
computed: {
...mapState(['uploadPct', 'avatarLink', 'avatarAfterUpload'])
...mapState(['uploadPct', 'avatarLink', 'avatarId', 'avatarAfterUpload'])
},
watch: {
uploadPct (val) {
this.pct = parseInt(val)
if (val === 100) {
this.$message({
message: 'Your avatar will be available on next mine',
type: 'success',
duration: 6000
})
this.upload = false
} else {
this.upload = true
this.pct = 0
}
}
},
methods: {
...mapActions(['getAvatarFromId', 'uploadReset']),
getAvatar () {
this.getAvatarFromId(this.avatarId)
return this.avatarAfterUpload
}
},
Expand All @@ -60,10 +70,13 @@ export default {
}
if (this.uploadPct === 100) {
this.$message({
message: 'Your avatar will be available on next mine',
type: 'success',
duration: 6000
})
this.upload = false
setTimeout(() => {
this.$router.push({ path: '/' })
}, 5000)
this.uploadReset()
}
}
}
Expand All @@ -86,4 +99,10 @@ export default {
.upload-progress {
width: 70vw;
}
.avatar {
height: 250px;
width: 250px;
margin: 1rem auto;
}
</style>
17 changes: 14 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export default new Vuex.Store({
walletAddress: '',
avatar: '',
avatarFile: '',
uploadPct: '',
uploadPct: 0,
avatarId: '',
avatarLink: '',
avatarAfterUpload: ''
},
mutations: {
Expand All @@ -46,6 +47,9 @@ export default new Vuex.Store({
setAvatarId (state, id) {
state.avatarId = id
},
setAvatarLink (state, link) {
state.avatarLink = link
},
setAvatarAfterUpload (state, avatar) {
state.avatarAfterUpload = avatar
}
Expand Down Expand Up @@ -82,12 +86,13 @@ export default new Vuex.Store({
while (!uploader.isComplete) {
await uploader.uploadChunk()
commit('setUploadPct', uploader.pctComplete)
console.log(`${uploader.pctComplete}% complete, ${uploader.uploadedChunks}/${uploader.totalChunks}`)
}

commit('setAvatarId', transaction.id)
commit('setAvatarLink', 'https://arweave.net/' + transaction.id)

const response = await ar.transactions.post(transaction)
console.log(response)
await ar.transactions.post(transaction)
})
},
setAvatarId ({ commit }, id) {
Expand All @@ -97,6 +102,12 @@ export default new Vuex.Store({
ar.transactions.getData(id, {decode: true, string: true}).then(data => {
commit('setAvatarAfterUpload', data)
})
},
uploadReset ({ commit }) {
commit('setAvatarAfterUpload', '')
commit('setAvatarLink', '')
commit('setAvatarId', '')
commit('setUploadPct', 0)
}
}
})

0 comments on commit 60ee9a9

Please sign in to comment.