1313 <div ><span >Verified Token</span ></div >
1414 </template >
1515 <div class =" content" >
16+ <div v-if =" showDisable"
17+ style =" text-align : center ;margin-top : 120px ;" >
18+ <img height =" 70"
19+ width =" 70"
20+ src =" ../../static/icons/ic_wait.svg" >
21+ </div >
1622 <div class =" accounts-part" >
1723 <div class =" scroll"
18- :style =" {height: ' 264px'}" >
24+ :style =" {height: showDisable ? '94px': ' 264px' }" >
1925 <div v-for =" (certifiedToken, tokenId) in certifiedTokens"
2026 :key =" tokenId" >
2127 <b-btn class =" token-unit"
22- @click =" addVerifiedToken(tokenId, certifiedToken)" >
28+ @click =" addVerifiedToken(tokenId, certifiedToken.name )" >
2329 <div class =" token-svg" ><img width =" 56px"
2430 height =" 56px"
25- :src =" certifiedTokenSvg( certifiedToken) " ></div >
26- <div class =" cer-name" ><span >{{certifiedToken}}</span ></div >
31+ :src =" certifiedToken.iconUrl " ></div >
32+ <div class =" cer-name" ><span >{{certifiedToken.name }}</span ></div >
2733 <div class =" notice" v-if =" isExistedToken(tokenId)" >Already added!</div >
2834 </b-btn >
2935 </div >
124130import Vue from ' vue'
125131import { mapState } from ' vuex'
126132import certify from ' ../utils/certify.js'
133+ import { CERTIFIED_TOKENS , CERTIFIED_TEST_TOKENS } from ' ../store/network.js'
134+ import common from ' src/js-v-sdk/src/utils/common'
127135export default {
128136 name: " AddToken" ,
129137 data : function () {
@@ -134,7 +142,8 @@ export default {
134142 certifiedTokens: {},
135143 selectedVerifiedToken: ' ' ,
136144 selectedVerifiedSymbol: ' ' ,
137- responseErr: false
145+ responseErr: false ,
146+ showDisable: false
138147 }
139148 },
140149 created () {
@@ -168,13 +177,30 @@ export default {
168177 },
169178 methods: {
170179 getCertifiedTokens () {
171- if (String .fromCharCode (this .networkByte ) === ' T' ) {
172- this .certifiedTokens = certify .certifiedTokensList [' Testnet' ]
173- } else if (String .fromCharCode (this .networkByte ) === ' M' ) {
174- this .certifiedTokens = certify .certifiedTokensList [' Mainnet' ]
175- } else {
176- this .certifiedTokens = {}
177- }
180+ let isTestnet = String .fromCharCode (this .networkByte ) === ' T'
181+ let url = isTestnet ? CERTIFIED_TEST_TOKENS : CERTIFIED_TOKENS
182+ let localCertifiedTokens = isTestnet ? certify .certifiedTokensList [' Testnet' ] : certify .certifiedTokensList [' Mainnet' ]
183+ let iconUrl = url .slice (0 , url .length - 11 )
184+ this .showDisable = true
185+ this .$http .get (url).then (res => {
186+ try {
187+ let data = res .body .data .list
188+ let tmpTokens = {}
189+ let tmpToken = {}
190+ for (let index in data) {
191+ tmpToken = data[index]
192+ tmpTokens[tmpToken .Id ] = { ' name' : tmpToken .Name , ' iconUrl' : iconUrl + tmpToken .IconUrl }
193+ }
194+ this .certifiedTokens = tmpTokens
195+ } catch (err) {
196+ this .certifiedTokens = localCertifiedTokens
197+ }
198+ this .showDisable = false
199+ },err => {
200+ console .log (err)
201+ this .certifiedTokens = localCertifiedTokens
202+ this .showDisable = false
203+ })
178204 },
179205 tokenTabChange (tabIndex ) {
180206 if (tabIndex === 0 ) {
@@ -187,6 +213,10 @@ export default {
187213 let tmp = this .tokenRecords
188214 let tokenId = this .activeTab === ' custom' ? this .tokenId : this .selectedVerifiedToken
189215 let tokenSymbol = this .activeTab === ' custom' ? this .tokenSymbol : this .selectedVerifiedSymbol
216+ let iconUrl = ' '
217+ if (tokenId in this .certifiedTokens ) {
218+ iconUrl = this .certifiedTokens [tokenId].iconUrl
219+ }
190220 if (tokenId in tmp) {
191221 this .$emit (' changePage' , ' home' )
192222 }
@@ -197,11 +227,26 @@ export default {
197227 this .responseErr = true
198228 return
199229 }
200- Vue .set (tmp, tokenId, tokenSymbol)
201- const updateInfo = { ' networkByte' : this .networkByte , ' tokens' : tmp}
202- this .$store .commit (' account/updateToken' , updateInfo)
203- this .$store .commit (' account/updateSelectedToken' , tokenId)
204- this .$emit (' changePage' , ' home' )
230+ let contractID = common .tokenIDToContractID (tokenId)
231+ this .chain .getContractInfo (contractID).then (res => {
232+ if (res .hasOwnProperty (' error' )) {
233+ this .responseErr = true
234+ return
235+ }
236+ if (res .type !== ' NonFungibleContract' && res .type !== ' TokenContract' && res .type !== ' TokenContractWithSplit' ) {
237+ this .responseErr = true
238+ return
239+ }
240+ let contractType = res .type
241+ let tokenInfo = { ' name' : tokenSymbol, ' contractType' : contractType,' iconUrl' : iconUrl }
242+ Vue .set (tmp, tokenId, tokenInfo)
243+ const updateInfo = { ' networkByte' : this .networkByte , ' tokens' : tmp}
244+ this .$store .commit (' account/updateToken' , updateInfo)
245+ this .$store .commit (' account/updateSelectedToken' , tokenId)
246+ this .$emit (' changePage' , ' home' )
247+ }, err => {
248+ this .responseErr = true
249+ })
205250 }, respError => {
206251 this .responseErr = true
207252 })
@@ -214,9 +259,6 @@ export default {
214259 this .selectedVerifiedToken = tokenId
215260 this .selectedVerifiedSymbol = verifiedSymbol
216261 },
217- certifiedTokenSvg (name ) {
218- return " ../../static/icons/token/" + name + " .svg"
219- },
220262 isExistedToken (tokenId ) {
221263 return tokenId in this .tokenRecords
222264 },
@@ -229,7 +271,7 @@ export default {
229271 }
230272 let tmp = this .tokenRecords
231273 for (let tokenId in tmp) {
232- if (tmp[tokenId] === symbol) {
274+ if (tmp[tokenId]. name === symbol) {
233275 return false
234276 }
235277 }
0 commit comments