Disable minter or subscriptions if contract doesn't support these features

This commit is contained in:
silverpill 2022-06-28 23:01:44 +00:00
parent f346315296
commit fbc4808a76
8 changed files with 21 additions and 9 deletions

View file

@ -4,7 +4,8 @@ import { BACKEND_URL } from "@/constants"
import { http } from "./common"
export enum Contracts {
Adapter = "IAdapter",
Minter = "IMinter",
SubscriptionAdapter = "ISubscriptionAdapter",
Subscription = "ISubscription",
ERC20 = "IERC20Metadata",
}

View file

@ -1,6 +1,11 @@
import { BACKEND_URL } from "@/constants"
import { http } from "./common"
interface ContractFeatures {
minter: boolean;
subscription: boolean;
}
interface ChainInfo {
chain_name: string;
public_api_url: string;
@ -20,6 +25,7 @@ export interface InstanceInfo {
blockchain_id: string | null;
blockchain_explorer_url: string | null;
blockchain_contract_address: string | null;
blockchain_features: ContractFeatures | null;
blockchain_info: ChainInfo | null;
ipfs_gateway_url: string | null;
}

View file

@ -55,7 +55,7 @@ export async function mintToken(
tokenUri: string,
serverSignature: EthereumSignature,
): Promise<TransactionResponse> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.Minter, contractAddress, signer)
const transaction = await adapter.mint(
ownerAddress,
tokenUri,

View file

@ -16,7 +16,7 @@ export async function getPricePerSec(
signer: Signer,
pricePerMonth: number,
): Promise<BigNumber> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const tokenAddress = await adapter.subscriptionToken()
const token = await getContract(Contracts.ERC20, tokenAddress, signer)
const tokenDecimals = await token.decimals()
@ -49,7 +49,7 @@ export async function configureSubscription(
pricePerSec: BigNumber,
serverSignature: EthereumSignature,
): Promise<TransactionResponse> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const transaction = await adapter.configureSubscription(
recipientAddress,
pricePerSec,
@ -108,7 +108,7 @@ export async function getSubscriptionInfo(
signer: Signer,
recipientAddress: string,
): 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)
if (result === true) {
const tokenAddress = await adapter.subscriptionToken()
@ -139,7 +139,7 @@ export async function getSubscriptionState(
senderAddress: string,
recipientAddress: string,
): Promise<SubscriptionState> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const [senderBalance, recipientBalance] = await adapter.getSubscriptionState(
senderAddress,
recipientAddress,
@ -162,7 +162,7 @@ export async function makeSubscriptionPayment(
recipientAddress: string,
amount: BigNumber,
): Promise<TransactionResponse> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const subscriptionAddress = await adapter.subscription()
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
const tokenAddress = await adapter.subscriptionToken()
@ -188,7 +188,7 @@ export async function cancelSubscription(
signer: Signer,
recipientAddress: string,
): Promise<TransactionResponse> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const subscriptionAddress = await adapter.subscription()
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
const transaction = await subscription.cancel(recipientAddress)
@ -200,7 +200,7 @@ export async function withdrawReceived(
signer: Signer,
senderAddress: string,
): Promise<TransactionResponse> {
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
const adapter = await getContract(Contracts.SubscriptionAdapter, contractAddress, signer)
const subscriptionAddress = await adapter.subscription()
const subscription = await getContract(Contracts.Subscription, subscriptionAddress, signer)
const transaction = await subscription.withdrawReceived(senderAddress)

View file

@ -463,6 +463,7 @@ export default class PostComponent extends Vue {
return (
Boolean(this.store.instance?.ipfs_gateway_url) &&
Boolean(this.store.instance?.blockchain_contract_address) &&
Boolean(this.store.instance?.blockchain_features?.minter) &&
this.post.account.id === this.store.currentUser?.id &&
this.post.visibility === "public" &&
Boolean(this.store.currentUser?.wallet_address) &&

View file

@ -155,6 +155,7 @@ function canConnectWallet(): boolean {
return (
Boolean(instance?.blockchain_id) &&
Boolean(instance?.blockchain_contract_address) &&
Boolean(instance?.blockchain_features?.subscription) &&
// Only profiles with verified address can have subscription
recipientEthereumAddress !== null &&
walletAddress === null

View file

@ -89,6 +89,7 @@ function canConnectWallet(): boolean {
return (
Boolean(instance?.blockchain_id) &&
Boolean(instance?.blockchain_contract_address) &&
Boolean(instance?.blockchain_features?.subscription) &&
// Only profiles with verified address can have subscription
profileEthereumAddress !== null &&
walletAddress === null

View file

@ -396,6 +396,7 @@ export default class ProfileView extends Vue {
// Only users with verified address can configure subscription
return (
Boolean(this.store.instance?.blockchain_contract_address) &&
Boolean(this.store.instance?.blockchain_features?.subscription) &&
Boolean(this.store.currentUser?.wallet_address) &&
this.isCurrentUser()
)
@ -404,6 +405,7 @@ export default class ProfileView extends Vue {
canSubscribe(): boolean {
return (
Boolean(this.store.instance?.blockchain_contract_address) &&
Boolean(this.store.instance?.blockchain_features?.subscription) &&
this.profile !== null &&
getVerifiedEthereumAddress(this.profile) !== null &&
!this.isCurrentUser()