diff --git a/core/language/us.json b/core/language/us.json index ddc95e4b..80b7bf2d 100644 --- a/core/language/us.json +++ b/core/language/us.json @@ -1219,6 +1219,13 @@ "profile3": "Update profile", "profile4": "Tagline", "profile5": "Bio", - "profile6": "Wallet Addresses" + "profile6": "Wallet Addresses", + "profile7": "Fill from UI", + "profile8": "Add custom data", + "profile9": "key name", + "profile10": "Fields", + "profile11": "Add new field", + "profile12": "Field name", + "profile13": "Fill out" } } \ No newline at end of file diff --git a/core/src/components/friends-view/profile-modal-update.js b/core/src/components/friends-view/profile-modal-update.js index 49c86119..8371c3a3 100644 --- a/core/src/components/friends-view/profile-modal-update.js +++ b/core/src/components/friends-view/profile-modal-update.js @@ -8,11 +8,13 @@ import { registerTranslateConfig, } from 'lit-translate'; import '@material/mwc-button'; +import '@material/mwc-icon'; import '@material/mwc-dialog'; import '@material/mwc-checkbox'; import { connect } from 'pwa-helpers'; import { store } from '../../store'; import '@polymer/paper-spinner/paper-spinner-lite.js'; +import { parentEpml } from '../show-plugin'; class ProfileModalUpdate extends connect(store)(LitElement) { static get properties() { @@ -26,6 +28,11 @@ class ProfileModalUpdate extends connect(store)(LitElement) { tagline: { type: String }, bio: { type: String }, wallets: { type: Array }, + hasFetchedArrr: { type: Boolean }, + isOpenCustomDataModal: { type: Boolean }, + customData: { type: Object }, + newCustomDataField: {type: Object}, + newFieldName: {type: String} }; } @@ -36,20 +43,40 @@ class ProfileModalUpdate extends connect(store)(LitElement) { this.nodeUrl = this.getNodeUrl(); this.myNode = this.getMyNode(); this.tagline = ''; - (this.bio = ''), - (this.walletList = [ - 'btc_Address', - 'ltc_Address', - 'doge_Address', - 'dgb_Address', - 'rvn_Address', - 'arrr_Address', - ]); + this.bio = ''; + this.walletList = ['btc', 'ltc', 'doge', 'dgb', 'rvn', 'arrr']; let wallets = {}; this.walletList.forEach((item) => { wallets[item] = ''; }); this.wallets = wallets; + this.walletsUi = new Map(); + let coinProp = { + wallet: null, + }; + + this.walletList.forEach((c, i) => { + this.walletsUi.set(c, { ...coinProp }); + }); + this.walletsUi.get('btc').wallet = + window.parent.reduxStore.getState().app.selectedAddress.btcWallet; + this.walletsUi.get('ltc').wallet = + window.parent.reduxStore.getState().app.selectedAddress.ltcWallet; + this.walletsUi.get('doge').wallet = + window.parent.reduxStore.getState().app.selectedAddress.dogeWallet; + this.walletsUi.get('dgb').wallet = + window.parent.reduxStore.getState().app.selectedAddress.dgbWallet; + this.walletsUi.get('rvn').wallet = + window.parent.reduxStore.getState().app.selectedAddress.rvnWallet; + this.walletsUi.get('arrr').wallet = + window.parent.reduxStore.getState().app.selectedAddress.arrrWallet; + this.hasFetchedArrr = false; + this.isOpenCustomDataModal = false; + this.customData = {}; + this.newCustomDataKey = "" + this.newCustomDataField = {}; + this.newFieldName = '' + } static get styles() { @@ -75,7 +102,6 @@ class ProfileModalUpdate extends connect(store)(LitElement) { color: var(--chat-bubble-msg-color); box-sizing: border-box; } - .input::selection { background-color: var(--mdc-theme-primary); color: white; @@ -205,7 +231,85 @@ class ProfileModalUpdate extends connect(store)(LitElement) { `; } - firstUpdated() {} + async updated(changedProperties) { + if ( + changedProperties && + changedProperties.has('editContent') && + this.editContent + ) { + this.bio = this.editContent.bio ?? ''; + this.tagline = this.editContent.tagline ?? ''; + this.wallets = this.editContent.wallets ?? {}; + this.requestUpdate(); + } + } + + async firstUpdated() { + try { + await this.fetchWalletAddress('arrr'); + } catch (error) { + console.log({ error }); + } finally { + } + } + + async fetchWalletAddress(coin) { + console.log({ coin }); + switch (coin) { + case 'arrr': + console.log('arrr'); + const arrrWalletName = `${coin}Wallet`; + + const res2 = await parentEpml.request('apiCall', { + url: `/crosschain/${coin}/syncstatus?apiKey=${this.myNode.apiKey}`, + method: 'POST', + body: `${ + window.parent.reduxStore.getState().app.selectedAddress[ + arrrWalletName + ].seed58 + }`, + }); + if (res2 !== null && res2 !== 'Synchronized') { + // Check again shortly after + await new Promise((resolve) => setTimeout(resolve, 2000)); + this.fetchWalletAddress('arrr'); + + // No need to make balance or transaction list calls yet + return; + } + + let res = await parentEpml.request('apiCall', { + url: `/crosschain/${coin}/walletaddress?apiKey=${this.myNode.apiKey}`, + method: 'POST', + body: `${ + window.parent.reduxStore.getState().app.selectedAddress[ + arrrWalletName + ].seed58 + }`, + }); + if (res != null && res.error != 1201 && res.length === 78) { + this.arrrWalletAddress = res; + this.hasFetchedArrr = true; + } + break; + + default: + // Not used for other coins yet + break; + } + } + + getSelectedWalletAddress(wallet) { + switch (wallet) { + case 'arrr': + // Use address returned by core API + return this.arrrWalletAddress; + + default: + // Use locally derived address + return this.walletsUi.get(wallet).wallet.address; + } + } getNodeUrl() { const myNode = @@ -226,9 +330,58 @@ class ProfileModalUpdate extends connect(store)(LitElement) { return myNode; } - clearFields() {} + clearFields() { + this.bio = ''; + this.tagline = ''; + this.wallets = {}; + } + + fillAddress(coin) { + const address = this.getSelectedWalletAddress(coin); + if (address) { + this.wallets = { + ...this.wallets, + [coin]: address, + }; + } + } + + async saveProfile() { + try { + const data = { + version: 1, + tagline: this.tagline, + bio: this.bio, + wallets: this.wallets, + }; + await this.onSubmit(data); + this.setIsOpen(false); + this.clearFields(); + this.onClose(); + } catch (error) {} + } + + removeField(key){ + const copyObj = {...this.newCustomDataField} + delete copyObj[key] + this.newCustomDataField = copyObj + } + + addField(){ + const copyObj = {...this.newCustomDataField} + copyObj[this.newFieldName] = '' + this.newCustomDataField = copyObj + this.newFieldName = "" + } + + addCustomData(){ + const copyObj = {...this.customData} + copyObj[this.newCustomDataKey] = this.newCustomDataField + this.customData = copyObj + } render() { + console.log('modal'); return html` + + + + ` - : html` -
{ - this.isOpenProfileModalUpdate = !this.isOpenProfileModalUpdate - }}> + : this.error ? html` +
+ +
+ ` : html` +
{ + if(this.resourceExists && this.profileData){ + this.editContent = this.profileData + } else if(this.resourceExists && !this.profileData){ + return + } + this.isOpenProfileModalUpdate = + !this.isOpenProfileModalUpdate; + }} + > { - this.isOpenProfileModalUpdate = val + ?isOpen=${this.isOpenProfileModalUpdate} + .setIsOpen=${(val) => { + this.isOpenProfileModalUpdate = val; }} - .onSubmit=${(val, isEdit)=> this.publishProfile(val, isEdit)} - .editContent=${this.editContent} - .onClose=${()=> this.onClose()} + .onSubmit=${this.saveToQdn} + .editContent=${this.editContent} + .onClose=${() => this.onClose()} > `; }