Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

feat: support rss3 name service #109

Merged
merged 1 commit into from
Nov 10, 2021
Merged
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
51 changes: 34 additions & 17 deletions src/common/rns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,45 @@ export default {
if (addrCache[addr]) {
return addrCache[addr];
} else {
const reverseNode = '0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2';
const addrHex = sha3HexAddress(addr.toLowerCase());
const node = utils.keccak256(utils.defaultAbiCoder.encode(['bytes32', 'bytes32'], [reverseNode, addrHex]));
const name = (await callRNSContract<string>('resolver', 'infura', speed, 'name', node))
.toLowerCase()
.replace(config.rns.suffix, '');
if (name) {
addrCache[addr] = name;
try {
const domainInfo = (await axios.get(`https://rss3.domains/address/${addr}`)).data;
if (domainInfo.rnsName) {
return domainInfo.rnsName.replace('.rss3', '');
} else {
return domainInfo.ensName;
}
} catch (e) {
const reverseNode = '0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2';
const addrHex = sha3HexAddress(addr.toLowerCase());
const node = utils.keccak256(
utils.defaultAbiCoder.encode(['bytes32', 'bytes32'], [reverseNode, addrHex]),
);
const name = (await callRNSContract<string>('resolver', 'infura', speed, 'name', node))
.toLowerCase()
.replace(config.rns.suffix, '');
if (name) {
addrCache[addr] = name;
}
return name;
}
return name;
}
},
async name2Addr(name: string, speed: SPEED = 'average') {
name = (name + config.rns.suffix).toLowerCase();
if (nameCache[name]) {
return nameCache[name];
} else {
const addr = await callRNSContract<string>('resolver', 'infura', speed, 'addr', utils.namehash(name));
if (parseInt(addr) !== 0) {
nameCache[name] = addr;
}
let addr;
try {
addr = (await axios.get(`https://rss3.domains/name/${name}`)).data.address;
return addr;
} catch (e) {
name = (name + config.rns.suffix).toLowerCase();
if (nameCache[name]) {
return nameCache[name];
} else {
const addr = await callRNSContract<string>('resolver', 'infura', speed, 'addr', utils.namehash(name));
if (parseInt(addr) !== 0) {
nameCache[name] = addr;
}
return addr;
}
}
},
async balanceOfPass3(addr: string, speed: SPEED = 'average') {
Expand Down
4 changes: 4 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ export function rgb2hex(r: number, g: number, b: number) {
.slice(1)
);
}

export function getName() {
return window.location.host.split('.').slice(0, -2).join('.');
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
defaultAvatar: 'https://rss3.mypinata.cloud/ipfs/QmVFq9qimnudPcs6QkQv8ZVEsvwD3aqETHWtS5yXgdbYY5',
hideUnlistedAsstes: false,
subDomain: {
isSubDomainMode: window.location.host.split('.').length === 3,
isSubDomainMode: window.location.host.split('.').length >= 3,
rootDomain: PAGE_ENV === 'production' ? 'rss3.bio' : currentRootDomain,
cookieExpires: 14,
},
Expand Down
3 changes: 2 additions & 1 deletion src/views/Accounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { RSS3Account, RSS3Index } from 'rss3-next/types/rss3';
import RNSUtils from '@/common/rns';
import config from '@/config';
import ContentProviders from '@/common/content-providers';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -142,7 +143,7 @@ export default class Accounts extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Followers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import RSS3, { IRSS3 } from '@/common/rss3';
import RNSUtils from '@/common/rns';
import config from '@/config';
import { reverse } from 'lodash';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -77,7 +78,7 @@ export default class Followers extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Followings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import RSS3, { IRSS3 } from '@/common/rss3';
import RNSUtils from '@/common/rns';
import config from '@/config';
import { reverse } from 'lodash';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -77,7 +78,7 @@ export default class Followings extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Footprints.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import RSS3 from '@/common/rss3';
import { GeneralAsset, GeneralAssetWithTags } from '@/common/types';
import { RSS3Asset } from 'rss3-next/types/rss3';
import { debounce } from 'lodash';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -134,7 +135,7 @@ export default class Footprints extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Gitcoins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import RSS3 from '@/common/rss3';
import { GeneralAsset, GeneralAssetWithTags } from '@/common/types';
import { RSS3Asset } from 'rss3-next/types/rss3';
import { debounce } from 'lodash';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -137,7 +138,7 @@ export default class Gitcoins extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ import RSS3, { IRSS3 } from '@/common/rss3';
import { RSS3Account, RSS3Asset, RSS3ID, RSS3Index } from 'rss3-next/types/rss3';
import Modal from '@/components/Modal.vue';
import RNSUtils from '@/common/rns';
import { getName } from '@/common/utils';
import config from '@/config';
import GitcoinItem from '@/components/GitcoinItem.vue';
import { GeneralAsset, GeneralAssetWithTags } from '@/common/types';
Expand Down Expand Up @@ -697,7 +698,7 @@ export default class Home extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/NFTs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import config from '@/config';
import { RSS3Asset } from 'rss3-next/types/rss3';
import { GeneralAsset, GeneralAssetWithTags } from '@/common/types';
import { debounce } from 'lodash';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -136,7 +137,7 @@ export default class NFTs extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/SingleFootprint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { POAP } from '@/common/types';
import RSS3 from '@/common/rss3';
import config from '@/config';
import RNSUtils from '@/common/rns';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -154,7 +155,7 @@ export default class SingleFootprint extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/SingleGitcoin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import config from '@/config';
import RNSUtils from '@/common/rns';
import RSS3 from '@/common/rss3';
import Vue3Autocounter from 'vue3-autocounter';
import { getName } from '@/common/utils';

interface Profile {
avatar: string;
Expand Down Expand Up @@ -209,7 +210,7 @@ export default class SingleGitcoin extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/SingleNFT.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import RSS3, { IRSS3 } from '@/common/rss3';
import RNSUtils from '@/common/rns';
import { NFT } from '@/common/types';
import config from '@/config';
import { getName } from '@/common/utils';

@Options({
name: 'SingleNFT',
Expand Down Expand Up @@ -117,7 +118,7 @@ export default class SingleNFT extends Vue {
let address: string = '';
if (config.subDomain.isSubDomainMode) {
// Is subdomain mode
address = window.location.host.split('.')[0];
address = getName();
} else if (this.$route.params.address) {
address = <string>this.$route.params.address;
} else {
Expand Down