Define contract names at client side
This commit is contained in:
parent
03f20ed0c1
commit
16b32ac00c
6 changed files with 9 additions and 16 deletions
|
@ -3,8 +3,11 @@ import { Contract, Signer } from "ethers"
|
||||||
import { BACKEND_URL } from "@/constants"
|
import { BACKEND_URL } from "@/constants"
|
||||||
import { http } from "./common"
|
import { http } from "./common"
|
||||||
|
|
||||||
|
export enum Contracts {
|
||||||
|
Adapter = "IAdapter",
|
||||||
|
}
|
||||||
|
|
||||||
async function getContractAbi(contractName: string): Promise<any> {
|
async function getContractAbi(contractName: string): Promise<any> {
|
||||||
// TODO: take artifact URL from instance config
|
|
||||||
const url = `${BACKEND_URL}/contracts/${contractName}.json`
|
const url = `${BACKEND_URL}/contracts/${contractName}.json`
|
||||||
const response = await http(url, {
|
const response = await http(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
|
@ -9,7 +9,6 @@ export interface InstanceInfo {
|
||||||
registrations: boolean;
|
registrations: boolean;
|
||||||
login_message: string;
|
login_message: string;
|
||||||
blockchain_explorer_url: string | null;
|
blockchain_explorer_url: string | null;
|
||||||
blockchain_contract_name: string | null;
|
|
||||||
blockchain_contract_address: string | null;
|
blockchain_contract_address: string | null;
|
||||||
ipfs_gateway_url: string | null;
|
ipfs_gateway_url: string | null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { TransactionResponse } from "@ethersproject/abstract-provider"
|
||||||
import { BACKEND_URL } from "@/constants"
|
import { BACKEND_URL } from "@/constants"
|
||||||
import { Signature } from "@/utils/ethereum"
|
import { Signature } from "@/utils/ethereum"
|
||||||
import { http } from "./common"
|
import { http } from "./common"
|
||||||
import { getContract } from "./contracts"
|
import { Contracts, getContract } from "./contracts"
|
||||||
import { Post } from "./posts"
|
import { Post } from "./posts"
|
||||||
|
|
||||||
export async function makePermanent(
|
export async function makePermanent(
|
||||||
|
@ -49,14 +49,13 @@ export interface TokenMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function mintToken(
|
export async function mintToken(
|
||||||
contractName: string,
|
|
||||||
contractAddress: string,
|
contractAddress: string,
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
ownerAddress: string,
|
ownerAddress: string,
|
||||||
tokenUri: string,
|
tokenUri: string,
|
||||||
serverSignature: Signature,
|
serverSignature: Signature,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(contractName, contractAddress, signer)
|
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||||
const transaction = await adapter.mint(
|
const transaction = await adapter.mint(
|
||||||
ownerAddress,
|
ownerAddress,
|
||||||
tokenUri,
|
tokenUri,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { TransactionResponse } from "@ethersproject/abstract-provider"
|
||||||
import { BACKEND_URL } from "@/constants"
|
import { BACKEND_URL } from "@/constants"
|
||||||
import { Signature } from "@/utils/ethereum"
|
import { Signature } from "@/utils/ethereum"
|
||||||
import { http } from "./common"
|
import { http } from "./common"
|
||||||
import { getContract } from "./contracts"
|
import { Contracts, getContract } from "./contracts"
|
||||||
|
|
||||||
export async function getSubscriptionAuthorization(
|
export async function getSubscriptionAuthorization(
|
||||||
authToken: string,
|
authToken: string,
|
||||||
|
@ -23,13 +23,12 @@ export async function getSubscriptionAuthorization(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function configureSubscription(
|
export async function configureSubscription(
|
||||||
contractName: string,
|
|
||||||
contractAddress: string,
|
contractAddress: string,
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
serverSignature: Signature,
|
serverSignature: Signature,
|
||||||
): Promise<TransactionResponse> {
|
): Promise<TransactionResponse> {
|
||||||
const adapter = await getContract(contractName, contractAddress, signer)
|
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||||
const transaction = await adapter.configureSubscription(
|
const transaction = await adapter.configureSubscription(
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
serverSignature.v,
|
serverSignature.v,
|
||||||
|
@ -40,12 +39,11 @@ export async function configureSubscription(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isSubscriptionConfigured(
|
export async function isSubscriptionConfigured(
|
||||||
contractName: string,
|
|
||||||
contractAddress: string,
|
contractAddress: string,
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const adapter = await getContract(contractName, contractAddress, signer)
|
const adapter = await getContract(Contracts.Adapter, contractAddress, signer)
|
||||||
const result = await adapter.isSubscriptionConfigured(recipientAddress)
|
const result = await adapter.isSubscriptionConfigured(recipientAddress)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,7 +457,6 @@ export default class PostComponent extends Vue {
|
||||||
if (
|
if (
|
||||||
!currentUser ||
|
!currentUser ||
|
||||||
!instance ||
|
!instance ||
|
||||||
!instance.blockchain_contract_name ||
|
|
||||||
!instance.blockchain_contract_address
|
!instance.blockchain_contract_address
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
|
@ -488,7 +487,6 @@ export default class PostComponent extends Vue {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const transaction = await mintToken(
|
const transaction = await mintToken(
|
||||||
instance.blockchain_contract_name,
|
|
||||||
instance.blockchain_contract_address,
|
instance.blockchain_contract_address,
|
||||||
signer,
|
signer,
|
||||||
currentUser.wallet_address,
|
currentUser.wallet_address,
|
||||||
|
|
|
@ -316,7 +316,6 @@ export default class ProfileView extends Vue {
|
||||||
!this.profile ||
|
!this.profile ||
|
||||||
!this.profile.wallet_address ||
|
!this.profile.wallet_address ||
|
||||||
!instance ||
|
!instance ||
|
||||||
!instance.blockchain_contract_name ||
|
|
||||||
!instance.blockchain_contract_address
|
!instance.blockchain_contract_address
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
|
@ -326,7 +325,6 @@ export default class ProfileView extends Vue {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.subscriptionConfigured = await isSubscriptionConfigured(
|
this.subscriptionConfigured = await isSubscriptionConfigured(
|
||||||
instance.blockchain_contract_name,
|
|
||||||
instance.blockchain_contract_address,
|
instance.blockchain_contract_address,
|
||||||
signer,
|
signer,
|
||||||
this.profile.wallet_address,
|
this.profile.wallet_address,
|
||||||
|
@ -338,7 +336,6 @@ export default class ProfileView extends Vue {
|
||||||
if (
|
if (
|
||||||
!currentUser ||
|
!currentUser ||
|
||||||
!instance ||
|
!instance ||
|
||||||
!instance.blockchain_contract_name ||
|
|
||||||
!instance.blockchain_contract_address
|
!instance.blockchain_contract_address
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
|
@ -351,7 +348,6 @@ export default class ProfileView extends Vue {
|
||||||
const authToken = this.store.ensureAuthToken()
|
const authToken = this.store.ensureAuthToken()
|
||||||
const signature = await getSubscriptionAuthorization(authToken)
|
const signature = await getSubscriptionAuthorization(authToken)
|
||||||
await configureSubscription(
|
await configureSubscription(
|
||||||
instance.blockchain_contract_name,
|
|
||||||
instance.blockchain_contract_address,
|
instance.blockchain_contract_address,
|
||||||
signer,
|
signer,
|
||||||
currentUser.wallet_address,
|
currentUser.wallet_address,
|
||||||
|
|
Loading…
Reference in a new issue