Skip to content

Commit

Permalink
allow delegated payer on hub init (#1135)
Browse files Browse the repository at this point in the history
* allow delegated payer on hub init

* artist name cleanup
  • Loading branch information
facing-n authored Nov 4, 2023
1 parent fa72ccc commit 770f6e2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/hubs/components/HubsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const HubsModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist.substring(
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(0, 100)}"`}</Typography>
Expand Down
2 changes: 1 addition & 1 deletion js/sdk/src/contexts/Audio/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const audioPlayerContextHelper = ({
if (playlistEntry) {
setPlaylist([...playlist, playlistEntry])
return {
msg: `${playlistEntry.artist.substring(
msg: `${playlistEntry.artist?.substring(
0,
100
)} - ${playlistEntry.title.substring(0, 100)} added to queue`,
Expand Down
2 changes: 1 addition & 1 deletion js/web/components/CollectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CollectorModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`${metadata.properties.artist.substring(
<Typography fontWeight="700">{`${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(
Expand Down
2 changes: 1 addition & 1 deletion js/web/components/HubsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const HubsModal = (props) => {
>
<StyledPaper>
<Header>
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist.substring(
<Typography fontWeight="700">{`Hubs featuring: ${metadata.properties.artist?.substring(
0,
100
)} - "${metadata.properties.title.substring(
Expand Down
6 changes: 3 additions & 3 deletions js/web/components/ReleaseCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ const ReleaseCard = (props) => {
</Link>
</Typography>
<Typography variant="h4" color="white" align="left">
{metadata?.properties?.artist.substring(0, 100) ||
metadata?.artist.substring(0, 100)}{' '}
{metadata?.properties?.artist?.substring(0, 100) ||
metadata?.artist?.substring(0, 100)}{' '}
- <i>{title}</i>
</Typography>
</>
Expand All @@ -186,7 +186,7 @@ const ReleaseCard = (props) => {
src={
artwork?.meta.status === undefined ? '' : artwork.meta.previewUrl
}
alt={metadata.artist}
alt={metadata.artist | 'alt'}
layout="responsive"
height={350}
width={350}
Expand Down
4 changes: 3 additions & 1 deletion programs/nina/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,7 @@ pub enum ErrorCode {
#[msg("Post Update Via Hub Delegated Payer Mismatch")]
PostUpdateViaHubPostDelegatePayerMismatch,
#[msg("Post Init Via Hub Delegated Payer Mismatch")]
PostInitViaHubDelegatePayerMismatch
PostInitViaHubDelegatePayerMismatch,
#[msg("Hub Init Delegated Payer Mismatch")]
HubInitDelegatePayerMismatch,
}
18 changes: 14 additions & 4 deletions programs/nina/src/instructions/hub_init.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use anchor_lang::prelude::*;
use anchor_spl::token::{self, Token};
use crate::state::*;
use crate::utils::{wrapped_sol};
use crate::utils::{wrapped_sol,file_service_account};
use crate::errors::ErrorCode;

#[derive(Accounts)]
#[instruction(params: HubInitParams)]
pub struct HubInit<'info> {
#[account(mut)]
pub authority: Signer<'info>,
pub payer: Signer<'info>,
/// CHECK: This is safe because we check in the handler that authority === payer
/// or that payer is nina operated file-service wallet
pub authority: UncheckedAccount<'info>,
#[account(
init,
seeds = [b"nina-hub".as_ref(), params.handle.as_bytes()],
bump,
payer = authority,
payer = payer,
space = 337
)]
pub hub: AccountLoader<'info, Hub>,
Expand All @@ -26,7 +30,7 @@ pub struct HubInit<'info> {
init,
seeds = [b"nina-hub-collaborator".as_ref(), hub.key().as_ref(), authority.key().as_ref()],
bump,
payer = authority,
payer = payer,
space = 147,
)]
pub hub_collaborator: Account<'info, HubCollaborator>,
Expand All @@ -40,6 +44,12 @@ pub fn handler (
ctx: Context<HubInit>,
params: HubInitParams,
) -> Result<()> {
if ctx.accounts.payer.key() != ctx.accounts.authority.key() {
if ctx.accounts.payer.key() != file_service_account::ID {
return Err(ErrorCode::HubInitDelegatePayerMismatch.into());
}
}

Hub::check_hub_fees(
params.publish_fee,
params.referral_fee
Expand Down
2 changes: 2 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3757,6 +3757,7 @@ describe('Hub', async () => {
await nina.rpc.hubInit(
hubParams, {
accounts: {
payer: provider.wallet.publicKey,
authority: provider.wallet.publicKey,
hub,
hubSigner,
Expand Down Expand Up @@ -3819,6 +3820,7 @@ describe('Hub', async () => {
await nina.rpc.hubInit(
hubParams, {
accounts: {
payer: provider.wallet.publicKey,
authority: provider.wallet.publicKey,
hub,
hubSigner,
Expand Down

3 comments on commit 770f6e2

@vercel
Copy link

@vercel vercel bot commented on 770f6e2 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 770f6e2 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 770f6e2 Nov 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.