Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion lib/js/packages/reef-mobile-js/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172993,6 +172993,30 @@ ${bz(e, r10)}`);
} catch (error) {
}

// src/jsApi/abi/ReefNameService.ts
var RnsAddress = "0x2B679Ea6B05da053D698b0d2c6daF1014Db7281e";
var ReefNameService = [
{ "type": "constructor", "inputs": [], "stateMutability": "nonpayable" },
{ "name": "RnsCreated", "type": "event", "inputs": [{ "name": "user", "type": "address", "indexed": true, "internalType": "address" }, { "name": "rns", "type": "string", "indexed": false, "internalType": "string" }], "anonymous": false },
{ "name": "allUsers", "type": "function", "inputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" },
{ "name": "blacklist", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "view" },
{ "name": "blacklistAddress", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }, { "name": "_action", "type": "bool", "internalType": "bool" }], "outputs": [], "stateMutability": "nonpayable" },
{ "name": "buy", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" },
{ "name": "create", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" },
{ "name": "getPrice", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" },
{ "name": "migrate", "type": "function", "inputs": [{ "name": "_user", "type": "address", "internalType": "address" }, { "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "nonpayable" },
{ "name": "owner", "type": "function", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" },
{ "name": "rnsPrices", "type": "function", "inputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" },
{ "name": "rnsToSell", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" },
{ "name": "rnsToUser", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" },
{ "name": "sell", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }, { "name": "_price", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" },
{ "name": "sendReef", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" },
{ "name": "setRnsPrices", "type": "function", "inputs": [{ "name": "_rnsPrices", "type": "uint256[]", "internalType": "uint256[]" }], "outputs": [], "stateMutability": "nonpayable" },
{ "name": "userToRns", "type": "function", "inputs": [{ "name": "", "type": "address", "internalType": "address" }], "outputs": [{ "name": "", "type": "string", "internalType": "string" }], "stateMutability": "view" },
{ "name": "usersCount", "type": "function", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" },
{ "name": "withdraw", "type": "function", "inputs": [], "outputs": [], "stateMutability": "payable" }
];

// src/jsApi/accountApi.ts
var { REEF_EXTENSION_IDENT } = V7e;
var buildAccountWithMeta = async (name6, address) => {
Expand Down Expand Up @@ -173053,6 +173077,34 @@ ${bz(e, r10)}`);
take(1)
));
},
fetchRns: async (evmAddress) => {
const provider = await firstValueFrom(z7e.selectedProvider$);
const rnsContract = new Contract(RnsAddress, ReefNameService, provider);
try {
const rns = await rnsContract.userToRns(evmAddress);
return rns;
} catch (error) {
console.log({
name: "fetchRns",
error: error.message
});
return "";
}
},
fetchEvmAddressFromRns: async (reefName) => {
const provider = await firstValueFrom(z7e.selectedProvider$);
const rnsContract = new Contract(RnsAddress, ReefNameService, provider);
try {
const addr = await rnsContract.rnsToUser(reefName);
return addr;
} catch (error) {
console.log({
name: "fetchEvmAddressFromRns",
error: error.message
});
return "";
}
},
toReefEVMAddressWithNotification: (evmAddress) => {
return q7e.addReefSpecificStringFromAddress(evmAddress);
},
Expand Down Expand Up @@ -177717,7 +177769,7 @@ query FETCH_TX_INFO {
return {
query: `
query TokenQuery {
tokens(where: {id_eq: "${tokenAddr}"}) {
tokens(where: {id_containsInsensitive: "${tokenAddr}"}, limit: 1) {
decimals
iconUrl
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ContractInterface } from 'ethers';

export const RnsAddress = "0x2B679Ea6B05da053D698b0d2c6daF1014Db7281e"

export const ReefNameService: ContractInterface = [
{ "type": "constructor", "inputs": [], "stateMutability": "nonpayable" }, { "name": "RnsCreated", "type": "event", "inputs": [{ "name": "user", "type": "address", "indexed": true, "internalType": "address" }, { "name": "rns", "type": "string", "indexed": false, "internalType": "string" }], "anonymous": false }, { "name": "allUsers", "type": "function", "inputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "name": "blacklist", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "bool", "internalType": "bool" }], "stateMutability": "view" }, { "name": "blacklistAddress", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }, { "name": "_action", "type": "bool", "internalType": "bool" }], "outputs": [], "stateMutability": "nonpayable" }, { "name": "buy", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" }, { "name": "create", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" }, { "name": "getPrice", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "name": "migrate", "type": "function", "inputs": [{ "name": "_user", "type": "address", "internalType": "address" }, { "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "nonpayable" }, { "name": "owner", "type": "function", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "name": "rnsPrices", "type": "function", "inputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "name": "rnsToSell", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "name": "rnsToUser", "type": "function", "inputs": [{ "name": "", "type": "string", "internalType": "string" }], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "name": "sell", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }, { "name": "_price", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "name": "sendReef", "type": "function", "inputs": [{ "name": "_rns", "type": "string", "internalType": "string" }], "outputs": [], "stateMutability": "payable" }, { "name": "setRnsPrices", "type": "function", "inputs": [{ "name": "_rnsPrices", "type": "uint256[]", "internalType": "uint256[]" }], "outputs": [], "stateMutability": "nonpayable" }, { "name": "userToRns", "type": "function", "inputs": [{ "name": "", "type": "address", "internalType": "address" }], "outputs": [{ "name": "", "type": "string", "internalType": "string" }], "stateMutability": "view" }, { "name": "usersCount", "type": "function", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "name": "withdraw", "type": "function", "inputs": [], "outputs": [], "stateMutability": "payable" }
]
67 changes: 48 additions & 19 deletions lib/js/packages/reef-mobile-js/src/jsApi/accountApi.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {AddressName, getAccountSigner, ReefAccount, reefState, addressUtils, network} from '@reef-chain/util-lib';
import {combineLatest, map, switchMap, take} from "rxjs/operators";
import {firstValueFrom} from 'rxjs';
import { AddressName, getAccountSigner, ReefAccount, reefState, addressUtils, network } from '@reef-chain/util-lib';
import { combineLatest, map, switchMap, take } from "rxjs/operators";
import { firstValueFrom } from 'rxjs';
import { extension } from '@reef-chain/util-lib';
import { resolveEvmAddress as utilsResolveEvmAddr, resolveAddress as utilsResolveToNativeAddress, isSubstrateAddress } from "@reef-chain/evm-provider/utils";
import {Provider} from "@reef-chain/evm-provider";
import { Provider } from "@reef-chain/evm-provider";
import Signer from "./background/Signer";
import {ethers} from 'ethers';
import { Contract, ethers } from 'ethers';
import type { InjectedAccountWithMeta } from '@reef-chain/util-lib/dist/dts/extension';
import { ReefNameService, RnsAddress } from './abi/ReefNameService';

const {REEF_EXTENSION_IDENT} = extension;
const { REEF_EXTENSION_IDENT } = extension;

export const buildAccountWithMeta = async (name: string, address: string): Promise<InjectedAccountWithMeta> => {
const acountWithMeta: InjectedAccountWithMeta = {
Expand Down Expand Up @@ -49,15 +50,15 @@ export const innitApi = (signingKey: Signer) => {
accounts.map(async (account: AddressName) => {
return await buildAccountWithMeta(account.name, account.address);
}
));
console.log("updateAccounts=",accountsWithMeta);
));
console.log("updateAccounts=", accountsWithMeta);
reefState.setAccounts(accountsWithMeta);
},
claimEvmAccount: async (nativeAddress: string) => {
return firstValueFrom(reefState.accounts$.pipe(
take(1),
map((accounts: ReefAccount[]) => {
return accounts.find((s)=> s.address === nativeAddress);
return accounts.find((s) => s.address === nativeAddress);
}),
combineLatest([reefState.selectedProvider$]),
switchMap(async ([signer, provider]: [ReefAccount | undefined, Provider]) => {
Expand All @@ -79,7 +80,7 @@ export const innitApi = (signingKey: Signer) => {
address,
type: reefState.UpdateDataType.ACCOUNT_NATIVE_BALANCE,
} as reefState.UpdateAction);
reefState.onTxUpdateResetSigners({isInBlock: true, txTypeEvm: false}, updateActions);
reefState.onTxUpdateResetSigners({ isInBlock: true, txTypeEvm: false }, updateActions);
return true;
} catch (e) {
console.log('account.claimEvmAccount() - ', e.message);
Expand All @@ -89,32 +90,60 @@ export const innitApi = (signingKey: Signer) => {
take(1)
));
},
toReefEVMAddressWithNotification: (evmAddress: string)=>{
fetchRns: async (evmAddress: string) => {
const provider = await firstValueFrom(reefState.selectedProvider$);
const rnsContract = new Contract(RnsAddress, ReefNameService, provider);
try {
const rns = await rnsContract.userToRns(evmAddress);
return rns;
} catch (error) {
console.log({
name: "fetchRns",
error: error.message
});
return ""
}
},
fetchEvmAddressFromRns: async (reefName: string) => {
const provider = await firstValueFrom(reefState.selectedProvider$);
const rnsContract = new Contract(RnsAddress, ReefNameService, provider);
try {
const addr = await rnsContract.rnsToUser(reefName);
return addr;
} catch (error) {
console.log({
name: "fetchEvmAddressFromRns",
error: error.message
});
return ""
}
},
toReefEVMAddressWithNotification: (evmAddress: string) => {
return addressUtils.addReefSpecificStringFromAddress(evmAddress);
},

toReefEVMAddressNoNotification: (evmAddressMsg: string)=>{
toReefEVMAddressNoNotification: (evmAddressMsg: string) => {
return addressUtils.removeReefSpecificStringFromAddress(evmAddressMsg);
},

resolveEvmAddress:async(nativeAddress:string)=>{
resolveEvmAddress: async (nativeAddress: string) => {
const provider = await firstValueFrom(reefState.selectedProvider$);
return utilsResolveEvmAddr(provider,nativeAddress);
return utilsResolveEvmAddr(provider, nativeAddress);
},

resolveFromEvmAddress:async(evmAddress:string)=>{
resolveFromEvmAddress: async (evmAddress: string) => {
const provider = await firstValueFrom(reefState.selectedProvider$);
const nativeAddress=await utilsResolveToNativeAddress(provider,evmAddress);
return nativeAddress||null;
const nativeAddress = await utilsResolveToNativeAddress(provider, evmAddress);
return nativeAddress || null;
},

isValidEvmAddress: (address: string) => ethers.utils.isAddress(address),
isValidEvmAddress: (address: string) => ethers.utils.isAddress(address),

isValidSubstrateAddress: (address: string) => isSubstrateAddress(address),

listenBindActivity: (address: string) => {
return network.getLatestBlockAccountUpdates$([address])
}
}
};
}

10 changes: 10 additions & 0 deletions lib/model/account/AccountCtrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ Future<dynamic> listenBindActivity(String address) async {
.jsPromise('window.account.resolveFromEvmAddress("$evmAddress")');
}

Future<String?> resolveToRns(String evmAddress) async {
return await _jsApi
.jsPromise('window.account.fetchRns("$evmAddress")');
}

Future<String?> resolveEvmFromRns(String rns) async {
return await _jsApi
.jsPromise('window.account.fetchEvmAddressFromRns("$rns")');
}

Future<String> sanitizeEvmAddress(String evmAddress) async{
return await _jsApi.jsPromise('window.utils.sanitizeInput("$evmAddress")');
}
Expand Down