Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
facing-n committed Oct 10, 2023
2 parents cce0264 + 085874d commit 18fb51d
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 4 deletions.
15 changes: 15 additions & 0 deletions js/hubs/components/ReleasePurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const WalletConnectModal = dynamic(() =>
import('@nina-protocol/nina-internal-sdk/esm/WalletConnectModal')
)

const UnverifiedModal = dynamic(() =>
import('@nina-protocol/nina-internal-sdk/esm/UnverifiedModal')
)

import dynamic from 'next/dynamic'

const BUTTON_WIDTH = '155px'
Expand Down Expand Up @@ -67,6 +71,8 @@ const ReleasePurchase = (props) => {
const [showNoSolModal, setShowNoSolModal] = useState(false)
const [showWalletModal, setShowWalletModal] = useState(false)
const [coinflowPurchasePending, setCoinflowPurchasePending] = useState(false)
const [showUnverifiedModal, setShowUnverifiedModal] = useState(false)
const [verificationError, setVerificationError] = useState('')

const txPending = useMemo(
() => releasePurchaseTransactionPending[releasePubkey],
Expand Down Expand Up @@ -171,6 +177,10 @@ const ReleasePurchase = (props) => {
}

const showCompletedTransaction = (result) => {
if (result.msg.indexOf('Unauthorized') > -1) {
setShowUnverifiedModal(true)
setVerificationError(result.msg)
}
enqueueSnackbar(result.msg, {
variant: result.success ? 'success' : 'warn',
})
Expand Down Expand Up @@ -331,6 +341,11 @@ const ReleasePurchase = (props) => {
</Box>
</Box>
</Box>
<UnverifiedModal
open={showUnverifiedModal}
setOpen={setShowUnverifiedModal}
error={verificationError}
/>
</ReleasePurchaseWrapper>
)
}
Expand Down
1 change: 1 addition & 0 deletions js/sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default [
CoinflowModal: 'src/components/CoinflowModal.js',
PurchaseModal: 'src/components/PurchaseModal.js',
CoinflowWithdrawModal: 'src/components/CoinflowWithdrawModal.js',
UnverifiedModal: 'src/components/UnverifiedModal.js',
},
output: [
{
Expand Down
84 changes: 84 additions & 0 deletions js/sdk/src/components/UnverifiedModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react'
import { styled } from '@mui/material/styles'
import Paper from '@mui/material/Paper'
import Modal from '@mui/material/Modal'
import Backdrop from '@mui/material/Backdrop'
import Fade from '@mui/material/Fade'
import Button from '@mui/material/Button'
import Typography from '@mui/material/Typography'
import Link from 'next/link'

const UnverifiedModal = ({ open, setOpen, error }) => {
const handleClose = () => {
setOpen(false)
}
return (
<Root>
<StyledModal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={open}
onClose={() => handleClose()}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={open}>
<StyledPaper>
<Typography
align="center"
variant="h4"
id="transition-modal-title"
gutterBottom
>
{error}
</Typography>
<Button
style={{ marginTop: '15px' }}
color="primary"
variant="outlined"
>
<Link href="dashboard">
<Typography>Go to Dashboard</Typography>
</Link>
</Button>{' '}
</StyledPaper>
</Fade>
</StyledModal>
</Root>
)
}

const Root = styled('div')(() => ({
display: 'flex',
alignItems: 'center',
width: '100%',
}))

const StyledModal = styled(Modal)(() => ({
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}))

const StyledPaper = styled(Paper)(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
border: '2px solid #000',
boxShadow: theme.shadows[5],
padding: theme.spacing(2, 4, 3),
width: '40vw',
maxHeight: '90vh',
overflowY: 'auto',
zIndex: '10',
display: 'flex',
flexDirection: 'column',
[theme.breakpoints.down('md')]: {
width: 'unset',
margin: '15px',
padding: theme.spacing(2),
},
}))

export default UnverifiedModal
4 changes: 3 additions & 1 deletion js/sdk/src/contexts/Release/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ const releaseContextHelper = ({
provider,
ninaClient,
usdcBalance,
solBalance,
hubPubkey
)

Expand Down Expand Up @@ -887,7 +888,8 @@ const releaseContextHelper = ({
releasePubkey,
provider,
ninaClient,
usdcBalance
usdcBalance,
solBalance
)
await getConfirmTransaction(txid, provider.connection)

Expand Down
1 change: 1 addition & 0 deletions js/sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export { default as HubPostCreate } from './components/HubPostCreate'
export { default as CoinflowModal } from './components/CoinflowModal'
export { default as PurchaseModal } from './components/PurchaseModal'
export { default as CoinflowWithdrawModal } from './components/CoinflowWithdrawModal'
export { default as UnverifiedModal } from './components/UnverifiedModal'
3 changes: 2 additions & 1 deletion js/sdk/src/utils/releasePurchaseHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ const releasePurchaseHelper = async (
provider,
ninaClient,
usdcBalance,
solBalance,
hubPubkey = null
) => {
let hub
releasePubkey = new anchor.web3.PublicKey(releasePubkey)
const program = await ninaClient.useProgram()
const release = await program.account.release.fetch(releasePubkey)

if (release.price.toNumber() === 0) {
if (release.price.toNumber() === 0 && solBalance === 0) {
const message = new TextEncoder().encode(releasePubkey.toBase58())
const messageBase64 = encodeBase64(message)
const signature = await provider.wallet.signMessage(message)
Expand Down
15 changes: 15 additions & 0 deletions js/web/components/ReleasePurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const WalletConnectModal = dynamic(() =>
import('@nina-protocol/nina-internal-sdk/esm/WalletConnectModal')
)

const UnverifiedModal = dynamic(() =>
import('@nina-protocol/nina-internal-sdk/esm/UnverifiedModal')
)

const ReleasePurchase = (props) => {
const {
releasePubkey,
Expand Down Expand Up @@ -85,6 +89,8 @@ const ReleasePurchase = (props) => {
const [description, setDescription] = useState()
const [showWalletModal, setShowWalletModal] = useState(false)
const [coinflowPurchasePending, setCoinflowPurchasePending] = useState(false)
const [showUnverifiedModal, setShowUnverifiedModal] = useState(false)
const [verificationError, setVerificationError] = useState('')

const txPending = useMemo(
() => releasePurchaseTransactionPending[releasePubkey],
Expand Down Expand Up @@ -207,6 +213,10 @@ const ReleasePurchase = (props) => {
}

const showCompletedTransaction = (result) => {
if (result.msg.indexOf('Unauthorized') > -1) {
setShowUnverifiedModal(true)
setVerificationError(result.msg)
}
enqueueSnackbar(result.msg, {
variant: result.success ? 'success' : 'warn',
})
Expand Down Expand Up @@ -415,6 +425,11 @@ const ReleasePurchase = (props) => {
</GatesNotification>
)}
</Box>
<UnverifiedModal
open={showUnverifiedModal}
setOpen={setShowUnverifiedModal}
error={verificationError}
/>
</Box>
)
}
Expand Down
2 changes: 1 addition & 1 deletion programs/nina/src/instructions/release_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn handler(
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.metadata.to_account_info().clone(),
ctx.accounts.release_mint.clone(),
ctx.accounts.payer.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.metadata_program.to_account_info().clone(),
ctx.accounts.token_program.clone(),
ctx.accounts.system_program.clone(),
Expand Down
2 changes: 1 addition & 1 deletion programs/nina/src/instructions/release_init_with_credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn handler(
ctx.accounts.release_signer.to_account_info().clone(),
ctx.accounts.metadata.to_account_info().clone(),
ctx.accounts.release_mint.clone(),
ctx.accounts.payer.clone(),
ctx.accounts.authority.clone(),
ctx.accounts.metadata_program.to_account_info().clone(),
ctx.accounts.token_program.clone(),
ctx.accounts.system_program.clone(),
Expand Down

0 comments on commit 18fb51d

Please sign in to comment.