Disable minter or subscriptions if contract doesn't support these features
This commit is contained in:
parent
f346315296
commit
fbc4808a76
8 changed files with 21 additions and 9 deletions
|
@ -4,7 +4,8 @@ import { BACKEND_URL } from "@/constants"
|
||||||
import { http } from "./common"
|
import { http } from "./common"
|
||||||
|
|
||||||
export enum Contracts {
|
export enum Contracts {
|
||||||
Adapter = "IAdapter",
|
Minter = "IMinter",
|
||||||
|
SubscriptionAdapter = "ISubscriptionAdapter",
|
||||||
Subscription = "ISubscription",
|
Subscription = "ISubscription",
|
||||||
ERC20 = "IERC20Metadata",
|
ERC20 = "IERC20Metadata",
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import { BACKEND_URL } from "@/constants"
|
import { BACKEND_URL } from "@/constants"
|
||||||
import { http } from "./common"
|
import { http } from "./common"
|
||||||
|
|
||||||
|
interface ContractFeatures {
|
||||||
|
minter: boolean;
|
||||||
|
subscription: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface ChainInfo {
|
interface ChainInfo {
|
||||||
chain_name: string;
|
chain_name: string;
|
||||||
public_api_url: string;
|
public_api_url: string;
|
||||||
|
@ -20,6 +25,7 @@ export interface InstanceInfo {
|
||||||
blockchain_id: string | null;
|
blockchain_id: string | null;
|
||||||
blockchain_explorer_url: string | null;
|
blockchain_explorer_url: string | null;
|
||||||
blockchain_contract_address: string | null;
|
blockchain_contract_address: string | null;
|
||||||
|
blockchain_features: ContractFeatures | null;
|
||||||
blockchain_info: ChainInfo | null;
|
blockchain_info: ChainInfo | null;
|
||||||
ipfs_gateway_url: string | null;
|
ipfs_gateway_url: string | null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ export async function mintToken(
|
||||||
tokenUri: string,
|
tokenUri: string,
|
||||||
serverSignature: EthereumSignature,
|
serverSignature: EthereumSignature,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.Minter, contractAddress, signer)
|
||||||
const transaction = await adapter.mint(
|
const transaction = await adapter.mint(
|
||||||
ownerAddress,
|
ownerAddress,
|
||||||
tokenUri,
|
tokenUri,
|
||||||
|
|
|
@ -16,7 +16,7 @@ export async function getPricePerSec(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
pricePerMonth: number,
|
pricePerMonth: number,
|
||||||
): Promise<BigNumber> {
|
): Promise<BigNumber> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const tokenAddress = await adapter.subscriptionToken()
|
const tokenAddress = await adapter.subscriptionToken()
|
||||||
const token = await getContract(Contracts.ERC20, tokenAddress, signer)
|
const token = await getContract(Contracts.ERC20, tokenAddress, signer)
|
||||||
const tokenDecimals = await token.decimals()
|
const tokenDecimals = await token.decimals()
|
||||||
|
@ -49,7 +49,7 @@ export async function configureSubscription(
|
||||||
pricePerSec: BigNumber,
|
pricePerSec: BigNumber,
|
||||||
serverSignature: EthereumSignature,
|
serverSignature: EthereumSignature,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const transaction = await adapter.configureSubscription(
|
const transaction = await adapter.configureSubscription(
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
pricePerSec,
|
pricePerSec,
|
||||||
|
@ -108,7 +108,7 @@ export async function getSubscriptionInfo(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
): Promise<Subscription | null> {
|
): Promise<Subscription | null> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const result = await adapter.isSubscriptionConfigured(recipientAddress)
|
const result = await adapter.isSubscriptionConfigured(recipientAddress)
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
const tokenAddress = await adapter.subscriptionToken()
|
const tokenAddress = await adapter.subscriptionToken()
|
||||||
|
@ -139,7 +139,7 @@ export async function getSubscriptionState(
|
||||||
senderAddress: string,
|
senderAddress: string,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
): Promise<SubscriptionState> {
|
): Promise<SubscriptionState> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const [senderBalance, recipientBalance] = await adapter.getSubscriptionState(
|
const [senderBalance, recipientBalance] = await adapter.getSubscriptionState(
|
||||||
senderAddress,
|
senderAddress,
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
|
@ -162,7 +162,7 @@ export async function makeSubscriptionPayment(
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
amount: BigNumber,
|
amount: BigNumber,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const subscriptionAddress = await adapter.subscription()
|
const subscriptionAddress = await adapter.subscription()
|
||||||
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
||||||
const tokenAddress = await adapter.subscriptionToken()
|
const tokenAddress = await adapter.subscriptionToken()
|
||||||
|
@ -188,7 +188,7 @@ export async function cancelSubscription(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const subscriptionAddress = await adapter.subscription()
|
const subscriptionAddress = await adapter.subscription()
|
||||||
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
||||||
const transaction = await subscription.cancel(recipientAddress)
|
const transaction = await subscription.cancel(recipientAddress)
|
||||||
|
@ -200,7 +200,7 @@ export async function withdrawReceived(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
senderAddress: string,
|
senderAddress: string,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
|
||||||
const subscriptionAddress = await adapter.subscription()
|
const subscriptionAddress = await adapter.subscription()
|
||||||
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
|
||||||
const transaction = await subscription.withdrawReceived(senderAddress)
|
const transaction = await subscription.withdrawReceived(senderAddress)
|
||||||
|
|
|
@ -463,6 +463,7 @@ export default class PostComponent extends Vue {
|
||||||
return (
|
return (
|
||||||
Boolean(this.store.instance?.ipfs_gateway_url) &&
|
Boolean(this.store.instance?.ipfs_gateway_url) &&
|
||||||
Boolean(this.store.instance?.blockchain_contract_address) &&
|
Boolean(this.store.instance?.blockchain_contract_address) &&
|
||||||
|
Boolean(this.store.instance?.blockchain_features?.minter) &&
|
||||||
this.post.account.id === this.store.currentUser?.id &&
|
this.post.account.id === this.store.currentUser?.id &&
|
||||||
this.post.visibility === "public" &&
|
this.post.visibility === "public" &&
|
||||||
Boolean(this.store.currentUser?.wallet_address) &&
|
Boolean(this.store.currentUser?.wallet_address) &&
|
||||||
|
|
|
@ -155,6 +155,7 @@ function canConnectWallet(): boolean {
|
||||||
return (
|
return (
|
||||||
Boolean(instance?.blockchain_id) &&
|
Boolean(instance?.blockchain_id) &&
|
||||||
Boolean(instance?.blockchain_contract_address) &&
|
Boolean(instance?.blockchain_contract_address) &&
|
||||||
|
Boolean(instance?.blockchain_features?.subscription) &&
|
||||||
// Only profiles with verified address can have subscription
|
// Only profiles with verified address can have subscription
|
||||||
recipientEthereumAddress !== null &&
|
recipientEthereumAddress !== null &&
|
||||||
walletAddress === null
|
walletAddress === null
|
||||||
|
|
|
@ -89,6 +89,7 @@ function canConnectWallet(): boolean {
|
||||||
return (
|
return (
|
||||||
Boolean(instance?.blockchain_id) &&
|
Boolean(instance?.blockchain_id) &&
|
||||||
Boolean(instance?.blockchain_contract_address) &&
|
Boolean(instance?.blockchain_contract_address) &&
|
||||||
|
Boolean(instance?.blockchain_features?.subscription) &&
|
||||||
// Only profiles with verified address can have subscription
|
// Only profiles with verified address can have subscription
|
||||||
profileEthereumAddress !== null &&
|
profileEthereumAddress !== null &&
|
||||||
walletAddress === null
|
walletAddress === null
|
||||||
|
|
|
@ -396,6 +396,7 @@ export default class ProfileView extends Vue {
|
||||||
// Only users with verified address can configure subscription
|
// Only users with verified address can configure subscription
|
||||||
return (
|
return (
|
||||||
Boolean(this.store.instance?.blockchain_contract_address) &&
|
Boolean(this.store.instance?.blockchain_contract_address) &&
|
||||||
|
Boolean(this.store.instance?.blockchain_features?.subscription) &&
|
||||||
Boolean(this.store.currentUser?.wallet_address) &&
|
Boolean(this.store.currentUser?.wallet_address) &&
|
||||||
this.isCurrentUser()
|
this.isCurrentUser()
|
||||||
)
|
)
|
||||||
|
@ -404,6 +405,7 @@ export default class ProfileView extends Vue {
|
||||||
canSubscribe(): boolean {
|
canSubscribe(): boolean {
|
||||||
return (
|
return (
|
||||||
Boolean(this.store.instance?.blockchain_contract_address) &&
|
Boolean(this.store.instance?.blockchain_contract_address) &&
|
||||||
|
Boolean(this.store.instance?.blockchain_features?.subscription) &&
|
||||||
this.profile !== null &&
|
this.profile !== null &&
|
||||||
getVerifiedEthereumAddress(this.profile) !== null &&
|
getVerifiedEthereumAddress(this.profile) !== null &&
|
||||||
!this.isCurrentUser()
|
!this.isCurrentUser()
|
||||||
|
|
Loading…
Reference in a new issue