diff --git a/ui/js/page/publish/index.js b/ui/js/page/publish/index.js
index bfe1f06e0..d959b04bd 100644
--- a/ui/js/page/publish/index.js
+++ b/ui/js/page/publish/index.js
@@ -6,8 +6,14 @@ import {
selectMyClaims,
selectFetchingMyChannels,
selectMyChannelClaims,
+ selectClaimsByUri,
} from "selectors/claims";
-import { doFetchClaimListMine, doFetchChannelListMine } from "actions/content";
+import { selectResolvingUris } from "selectors/content";
+import {
+ doFetchClaimListMine,
+ doFetchChannelListMine,
+ doResolveUri,
+} from "actions/content";
import rewards from "rewards";
import PublishPage from "./view";
@@ -15,6 +21,8 @@ const select = state => ({
myClaims: selectMyClaims(state),
fetchingChannels: selectFetchingMyChannels(state),
channels: selectMyChannelClaims(state),
+ claimsByUri: selectClaimsByUri(state),
+ resolvingUris: selectResolvingUris(state),
});
const perform = dispatch => ({
@@ -24,6 +32,7 @@ const perform = dispatch => ({
claimFirstChannelReward: () =>
dispatch(doClaimRewardType(rewards.TYPE_FIRST_CHANNEL)),
fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
+ resolveUri: uri => dispatch(doResolveUri(uri)),
});
export default connect(select, perform)(PublishPage);
diff --git a/ui/js/page/publish/view.jsx b/ui/js/page/publish/view.jsx
index 06edf4b43..5d06b9b6f 100644
--- a/ui/js/page/publish/view.jsx
+++ b/ui/js/page/publish/view.jsx
@@ -23,9 +23,6 @@ class PublishPage extends React.PureComponent {
channel: "anonymous",
newChannelName: "@",
newChannelBid: 10,
- nameResolved: null,
- myClaimExists: null,
- topClaimValue: 0.0,
myClaimValue: 0.0,
myClaimMetadata: null,
copyrightNotice: "",
@@ -44,15 +41,6 @@ class PublishPage extends React.PureComponent {
const { fetchingChannels, fetchChannelListMine } = this.props;
if (!fetchingChannels) fetchChannelListMine();
- // Calls API to update displayed list of channels. If a channel name is provided, will select
- // that channel at the same time (used immediately after creating a channel)
- // lbry.channel_list_mine().then(channels => {
- // this.props.claimFirstChannelReward();
- // this.setState({
- // channels: channels,
- // ...(channel ? { channel } : {}),
- // });
- // });
}
handleSubmit(event) {
@@ -65,7 +53,7 @@ class PublishPage extends React.PureComponent {
});
let checkFields = this._requiredFields;
- if (!this.state.myClaimExists) {
+ if (!this.myClaimExists()) {
checkFields.unshift("file");
}
@@ -182,6 +170,49 @@ class PublishPage extends React.PureComponent {
});
}
+ claim() {
+ const { claimsByUri } = this.props;
+ const { uri } = this.state;
+
+ return claimsByUri[uri];
+ }
+
+ topClaimValue() {
+ if (!this.claim()) return null;
+
+ return parseFloat(this.claim().amount);
+ }
+
+ myClaimExists() {
+ const { myClaims } = this.props;
+ const { name } = this.state;
+
+ if (!name) return false;
+
+ return !!myClaims.find(claim => claim.name === name);
+ }
+
+ topClaimIsMine() {
+ const myClaimInfo = this.myClaimInfo();
+ const { claimsByUri } = this.props;
+ const { uri } = this.state;
+
+ if (!uri) return null;
+
+ const claim = claimsByUri[uri];
+
+ if (!claim) return true;
+ if (!myClaimInfo) return false;
+
+ return myClaimInfo.amount >= claimInfo.amount;
+ }
+
+ myClaimInfo() {
+ return Object.values(this.props.myClaims).find(
+ claim => claim.name === name
+ );
+ }
+
handleNameChange(event) {
var rawName = event.target.value;
@@ -189,7 +220,7 @@ class PublishPage extends React.PureComponent {
this.setState({
rawName: "",
name: "",
- nameResolved: false,
+ uri: "",
});
return;
@@ -203,61 +234,14 @@ class PublishPage extends React.PureComponent {
}
const name = rawName.toLowerCase();
+ const uri = lbryuri.normalize(name);
this.setState({
rawName: rawName,
name: name,
- nameResolved: null,
- myClaimExists: null,
+ uri,
});
- const myClaimInfo = Object.values(this.props.myClaims).find(
- claim => claim.name === name
- );
-
- this.setState({
- myClaimExists: !!myClaimInfo,
- });
- lbry.resolve({ uri: name }).then(
- claimInfo => {
- if (name != this.state.name) {
- return;
- }
-
- if (!claimInfo) {
- this.setState({
- nameResolved: false,
- });
- } else {
- const topClaimIsMine =
- myClaimInfo && myClaimInfo.amount >= claimInfo.amount;
- const newState = {
- nameResolved: true,
- topClaimValue: parseFloat(claimInfo.amount),
- myClaimExists: !!myClaimInfo,
- myClaimValue: myClaimInfo ? parseFloat(myClaimInfo.amount) : null,
- myClaimMetadata: myClaimInfo ? myClaimInfo.value : null,
- topClaimIsMine: topClaimIsMine,
- };
-
- if (topClaimIsMine) {
- newState.bid = myClaimInfo.amount;
- } else if (this.state.myClaimMetadata) {
- // Just changed away from a name we have a claim on, so clear pre-fill
- newState.bid = "";
- }
-
- this.setState(newState);
- }
- },
- () => {
- // Assume an error means the name is available
- this.setState({
- name: name,
- nameResolved: false,
- myClaimExists: false,
- });
- }
- );
+ this.props.resolveUri(uri);
}
handleBidChange(event) {
@@ -427,22 +411,27 @@ class PublishPage extends React.PureComponent {
}
getNameBidHelpText() {
- if (!this.state.name) {
+ if (
+ this.state.uri &&
+ this.props.resolvingUris.indexOf(this.state.uri) !== -1
+ ) {
+ return
{__("Your file has been published to LBRY at the address")}
- {" "}lbry://{this.state.name}
!
+ {" "}{this.state.uri}
!
{__( diff --git a/ui/js/selectors/claims.js b/ui/js/selectors/claims.js index 454c11c43..2ca754511 100644 --- a/ui/js/selectors/claims.js +++ b/ui/js/selectors/claims.js @@ -93,21 +93,33 @@ export const selectClaimListMineIsPending = createSelector( state => state.isClaimListMinePending ); -export const selectMyClaims = createSelector( +export const selectMyClaimsRaw = createSelector( _selectState, state => state.myClaims || new Set() ); +export const selectMyClaims = createSelector( + selectMyClaimsRaw, + selectClaimsById, + (myClaimIds, byId) => { + const claims = []; + + myClaimIds.forEach(id => { + const claim = byId[id]; + + if (claim) claims.push(claim); + }); + + return claims; + } +); + export const selectMyClaimsOutpoints = createSelector( selectMyClaims, - selectClaimsById, - (claimIds, byId) => { + myClaims => { const outpoints = []; - claimIds.forEach(claimId => { - const claim = byId[claimId]; - if (claim) outpoints.push(`${claim.txid}:${claim.nout}`); - }); + myClaims.forEach(claim => outpoints.push(`${claim.txid}:${claim.nout}`)); return outpoints; }