Skip to content

Commit 60ee9a9

Browse files
authored
🔀 Merge pull request #8 from nekomeowww/master
✨ Seperated the different error messages, connected the link to avatar and reset functions, fixed the loading percentage sometimes became NaN
2 parents c552748 + 9cb5a21 commit 60ee9a9

File tree

7 files changed

+94
-27
lines changed

7 files changed

+94
-27
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">ArweaveAvatar</h1>
22
<p align="center">Avatar upload and manage for Arweave Identification</p>
3-
<p align="center"> Link at Permaweb: <a href="https://arweave.net/d9SXf_N32hAm3cygt1btmPC-7Dg460VhQEtW8I-cfvU">Online</a></p>
3+
<p align="center"> Link to Permaweb: <a href="https://arweave.net/SV9JcBCwCzCUt22pX2xN6BynKi8zdaTrQ57ytu-Vems">Online</a></p>
44
<p align="center">
55
<img src="https://github.com/AyakaLab/ArweaveAvatar/workflows/Node%20Build%20Test/badge.svg" />
66
<img src="https://github.com/AyakaLab/ArweaveAvatar/workflows/Production%20CI%20Build%20Test/badge.svg" />

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arweave-avatar",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Avatar upload and manage for Arweave Identification",
55
"author": "Ayaka Neko <neko@ayaka.moe>",
66
"private": true,

‎src/api/arweave.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let arweave = {
2424
ar.transactions.get(txid).then(detail => {
2525
resolve(detail)
2626
}).catch(err => {
27+
console.log(err)
2728
reject(err)
2829
})
2930
})
@@ -54,14 +55,20 @@ let arweave = {
5455
}
5556
}).then(async ids => {
5657
if (ids.length === 0) {
57-
resolve(false)
58+
resolve({ result: 'no image found' })
5859
return
5960
}
6061

6162
let detail = await this.getTransactionDetail(ids[0]).catch((err) => {
62-
resolve(err)
63+
console.log(err)
64+
resolve({ result: 'pending on confirm', error: err })
6365
})
6466

67+
if (!detail) {
68+
resolve({ result: 'pending on upload' })
69+
return
70+
}
71+
6572
ar.transactions.getData(detail.id, {decode: true, string: true}).then(data => {
6673
resolve(data)
6774
})

‎src/components/imgUpload/imgUpload.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ export default {
266266
try {
267267
let res = { data: { code: 0 } }
268268
res.data.code = 0
269-
console.log(file)
270269
this.setAvatarFile(file)
271270
if (res.data.code === 0 || res.data.code === 1) {
272271
this.$emit('doneImageUpload', {

‎src/pages/SetAvatar.vue‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default {
6868
imgUploadDone: 0,
6969
loading: true,
7070
loadingPct: 0,
71-
loadingStatus: ''
71+
loadingStatus: undefined
7272
}
7373
},
7474
computed: {
@@ -149,24 +149,55 @@ export default {
149149
}, 500)
150150
151151
API.arweave.getAvatar(this.walletAddress).then(res => {
152-
if (!res) {
152+
if (res.result === 'no image found') {
153153
this.loadingStatus = 'exception'
154154
this.$message({
155-
message: 'Avatar not Found or is Pending on confirmation',
155+
message: 'No Avatar not Found',
156156
type: 'error',
157-
duration: 4000
157+
duration: 6000
158158
})
159159
clearInterval(intervalId)
160-
}
161-
this.avatar = res
162-
clearInterval(intervalId)
163-
this.loadingPct = 100
164-
165-
setTimeout(() => {
166-
this.loading = false
167-
}, 2000)
160+
this.avatar = false
161+
setTimeout(() => {
162+
this.loading = false
163+
}, 2000)
164+
} else if (res.result === 'pending on confirm') {
165+
this.loadingStatus = 'exception'
166+
this.$message({
167+
message: 'Avatar is pending on confirmation',
168+
type: 'warning',
169+
duration: 6000
170+
})
171+
console.log(res.result.error)
172+
clearInterval(intervalId)
173+
this.avatar = false
174+
this.loadingPct = 100
175+
setTimeout(() => {
176+
this.loading = false
177+
}, 2000)
178+
} else if (res.result === 'pending on upload') {
179+
this.loadingStatus = 'exception'
180+
this.$message({
181+
message: 'Avatar is pending on upload',
182+
type: 'warning',
183+
duration: 6000
184+
})
185+
clearInterval(intervalId)
186+
this.avatar = false
187+
this.loadingPct = 100
188+
setTimeout(() => {
189+
this.loading = false
190+
}, 2000)
191+
} else {
192+
this.loadingStatus = 'success'
193+
this.avatar = res
194+
clearInterval(intervalId)
195+
this.loadingPct = 100
168196
169-
return res
197+
setTimeout(() => {
198+
this.loading = false
199+
}, 2000)
200+
}
170201
})
171202
}, 2000)
172203
}

‎src/pages/Upload.vue‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<i class="el-icon-success" style="font-size: 10rem; color: #67C23A;"></i>
1010
<span>Upload Successful!</span>
1111
<span v-if="!upload && avatarLink !== ''" style="margin-top: 1rem;">Link to your avatar: <a :href="avatarLink">{{ avatarLink }}</a></span>
12-
<img :src="getAvatar()" />
12+
<img :src="getAvatar()" class="avatar"/>
1313
</div>
1414
</div>
1515
<Footer />
@@ -18,7 +18,7 @@
1818

1919
<script>
2020
21-
import { mapState } from 'vuex'
21+
import { mapState, mapActions } from 'vuex'
2222
2323
import Header from '@/components/Header.vue'
2424
import Footer from '@/components/Footer.vue'
@@ -36,19 +36,29 @@ export default {
3636
}
3737
},
3838
computed: {
39-
...mapState(['uploadPct', 'avatarLink', 'avatarAfterUpload'])
39+
...mapState(['uploadPct', 'avatarLink', 'avatarId', 'avatarAfterUpload'])
4040
},
4141
watch: {
4242
uploadPct (val) {
4343
this.pct = parseInt(val)
4444
4545
if (val === 100) {
46+
this.$message({
47+
message: 'Your avatar will be available on next mine',
48+
type: 'success',
49+
duration: 6000
50+
})
4651
this.upload = false
52+
} else {
53+
this.upload = true
54+
this.pct = 0
4755
}
4856
}
4957
},
5058
methods: {
59+
...mapActions(['getAvatarFromId', 'uploadReset']),
5160
getAvatar () {
61+
this.getAvatarFromId(this.avatarId)
5262
return this.avatarAfterUpload
5363
}
5464
},
@@ -60,10 +70,13 @@ export default {
6070
}
6171
6272
if (this.uploadPct === 100) {
73+
this.$message({
74+
message: 'Your avatar will be available on next mine',
75+
type: 'success',
76+
duration: 6000
77+
})
6378
this.upload = false
64-
setTimeout(() => {
65-
this.$router.push({ path: '/' })
66-
}, 5000)
79+
this.uploadReset()
6780
}
6881
}
6982
}
@@ -86,4 +99,10 @@ export default {
8699
.upload-progress {
87100
width: 70vw;
88101
}
102+
103+
.avatar {
104+
height: 250px;
105+
width: 250px;
106+
margin: 1rem auto;
107+
}
89108
</style>

‎src/store/index.js‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export default new Vuex.Store({
2323
walletAddress: '',
2424
avatar: '',
2525
avatarFile: '',
26-
uploadPct: '',
26+
uploadPct: 0,
2727
avatarId: '',
28+
avatarLink: '',
2829
avatarAfterUpload: ''
2930
},
3031
mutations: {
@@ -46,6 +47,9 @@ export default new Vuex.Store({
4647
setAvatarId (state, id) {
4748
state.avatarId = id
4849
},
50+
setAvatarLink (state, link) {
51+
state.avatarLink = link
52+
},
4953
setAvatarAfterUpload (state, avatar) {
5054
state.avatarAfterUpload = avatar
5155
}
@@ -82,12 +86,13 @@ export default new Vuex.Store({
8286
while (!uploader.isComplete) {
8387
await uploader.uploadChunk()
8488
commit('setUploadPct', uploader.pctComplete)
89+
console.log(`${uploader.pctComplete}% complete, ${uploader.uploadedChunks}/${uploader.totalChunks}`)
8590
}
8691

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

89-
const response = await ar.transactions.post(transaction)
90-
console.log(response)
95+
await ar.transactions.post(transaction)
9196
})
9297
},
9398
setAvatarId ({ commit }, id) {
@@ -97,6 +102,12 @@ export default new Vuex.Store({
97102
ar.transactions.getData(id, {decode: true, string: true}).then(data => {
98103
commit('setAvatarAfterUpload', data)
99104
})
105+
},
106+
uploadReset ({ commit }) {
107+
commit('setAvatarAfterUpload', '')
108+
commit('setAvatarLink', '')
109+
commit('setAvatarId', '')
110+
commit('setUploadPct', 0)
100111
}
101112
}
102113
})

0 commit comments

Comments
 (0)