Skip to content

Commit

Permalink
Merge pull request #831 from TokenScript/feat/load-button
Browse files Browse the repository at this point in the history
fix to wallet filter
  • Loading branch information
nicktaras authored Sep 18, 2023
2 parents f9619ee + f01be08 commit ca48cf9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 78 deletions.
144 changes: 74 additions & 70 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,36 @@
window.negotiator = new negotiator.Client({
type: "active",
issuers: [
// {
// onChain: true,
// fungible: true,
// chain: "eth",
// blockchain: "evm",
// collectionID: "socios",
// contract: "0x3506424F91fD33084466F402d5D97f05F8e3b4AF",
// oAuth2options: {
// consumerKey: "PBK9Mx_ffFRUPHW9BLTxnGHRdywa",
// partnerTag: "smarttokenlabs",
// endpoints: {
// redirectURI: {
// path: "http://localhost:5000/user-login-callback",
// params: {}
// },
// userBalance: {
// path: 'http://localhost:5000/user-balance',
// params: {}
// },
// userNfts: {
// path: 'http://localhost:5000/user-nfts',
// params: {}
// },
// },
// },
// },
{
onChain: true,
fungible: true,
chain: "eth",
blockchain: "evm",
collectionID: "socios",
contract: "0x3506424F91fD33084466F402d5D97f05F8e3b4AF",
oAuth2options: {
consumerKey: "PBK9Mx_ffFRUPHW9BLTxnGHRdywa",
partnerTag: "smarttokenlabs",
endpoints: {
redirectURI: {
path: "http://localhost:5000/user-login-callback",
params: {}
},
userBalance: {
path: 'http://localhost:5000/user-balance',
params: {}
},
userNfts: {
path: 'http://localhost:5000/user-nfts',
params: {}
},
userLogout: {
path: 'http://localhost:5000/user-logout',
params: {}
},
},
},
},
// {
// hideToggle: true,
// noTokenMsg:
Expand Down Expand Up @@ -178,62 +182,62 @@
// },
// base64attestorPubKey: "MIIBMzCB7AYHKoZIzj0CATCB4AIBATAsBgcqhkjOPQEBAiEA/////////////////////////////////////v///C8wRAQgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHBEEEeb5mfvncu6xVoGKVzocLBwKb/NstzijZWfKBWxb4F5hIOtp3JqPEZV2k+/wOEQio/Re0SKaFVBmcR9CP+xDUuAIhAP////////////////////66rtzmr0igO7/SXozQNkFBAgEBA0IABL+y43T1OJFScEep69/yTqpqnV/jzONz9Sp4TEHyAJ7IPN9+GHweCX1hT4OFxt152sBN3jJc1s0Ymzd8pNGZNoQ="
// },
// {
// collectionID: "crypto-cowboy-country",
// tokenProgram: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
// collectionAddress:
// "bf0aae3dd0078a9feb975f1e3242ddcb7774d551c7fd2a3f07a89c827ed606b2",
// updateAuthority: "CCCUzWanUNegjGby11DjujDvPaNN68jd9Rimwk2MZzqZ",
// onChain: true,
// symbol: "CCC",
// chain: "mainnet",
// blockchain: "solana",
// },
// {
// collectionID: "penthouse-panther-club",
// collectionAddress: "ff846ef2eed57e5367cf8826e63f4d53fe28d28aa67417accb6e4b48cbd19136",
// updateAuthority: "92oYPmrr1BHznizuZmpKZ3MFRadMFYRTCxo9Pf34mZKX",
// tokenProgram: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
// onChain: true,
// symbol: "PPC",
// chain: "mainnet",
// blockchain: "solana",
// },
// {
// hideToggle : false,
// collectionID: "pixel",
// collectionAddress: "166424b16c4c7f40eb852f9eb2d0d6869a9ed7ac54a8e6afbd516676bfbbeb19",
// onChain: true,
// symbol: "PIXEL",
// chain: "mainnet",
// blockchain: "solana",
// },
{
collectionID: "crypto-cowboy-country",
tokenProgram: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
collectionAddress:
"bf0aae3dd0078a9feb975f1e3242ddcb7774d551c7fd2a3f07a89c827ed606b2",
updateAuthority: "CCCUzWanUNegjGby11DjujDvPaNN68jd9Rimwk2MZzqZ",
onChain: true,
collectionID: "expansion-punks",
contract: "0x0d0167a823c6619d430b1a96ad85b888bcf97c37",
chain: "eth",
blockchain: "evm",
symbol: "CCC",
chain: "mainnet",
blockchain: "solana",
},
{
collectionID: "penthouse-panther-club",
collectionAddress: "ff846ef2eed57e5367cf8826e63f4d53fe28d28aa67417accb6e4b48cbd19136",
updateAuthority: "92oYPmrr1BHznizuZmpKZ3MFRadMFYRTCxo9Pf34mZKX",
tokenProgram: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
onChain: true,
collectionID: "fantom-collection-test",
contract: "0x94e22c14118353651636f9af43cd0a5a08b93da3",
chain: "fantom",
blockchain: "evm",
symbol: "PPC",
chain: "mainnet",
blockchain: "solana",
},
{
hideToggle: true,
noTokenMsg:
"<p>If you have a token please:</p><p>1. Open your magic link inside this browser.<br/>2. Refresh this page.</p>",
hideToggle: false,
collectionID: "pixel",
collectionAddress: "166424b16c4c7f40eb852f9eb2d0d6869a9ed7ac54a8e6afbd516676bfbbeb19",
onChain: true,
collectionID: "bsc-collection-test",
contract: "0xF5db804101d8600c26598A1Ba465166c33CdAA4b",
chain: "bsc",
symbol: "PIXEL",
chain: "mainnet",
blockchain: "solana",
},
{
onChain: true,
collectionID: "expansion-punks",
contract: "0x0d0167a823c6619d430b1a96ad85b888bcf97c37",
chain: "eth",
blockchain: "evm",
},
// {
// onChain: true,
// collectionID: "fantom-collection-test",
// contract: "0x94e22c14118353651636f9af43cd0a5a08b93da3",
// chain: "fantom",
// blockchain: "evm",
// },
// {
// hideToggle: true,
// noTokenMsg:
// "<p>If you have a token please:</p><p>1. Open your magic link inside this browser.<br/>2. Refresh this page.</p>",
// onChain: true,
// collectionID: "bsc-collection-test",
// contract: "0xF5db804101d8600c26598A1Ba465166c33CdAA4b",
// chain: "bsc",
// blockchain: "evm",
// },
// {
// onChain: true,
// collectionID: "tt",
// contract: '0x76be3b62873462d2142405439777e971754e8e77',
// chain: 'eth',
Expand Down
16 changes: 11 additions & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,18 @@ export class Client {
public hasIssuerForBlockchain(blockchain: 'evm' | 'solana' | 'flow' | 'ultra', useOauth = false) {
return (
this.config.issuers.filter((issuer: OnChainTokenConfig) => {
const oAuthIssuerOrNotRequired = !useOauth || (useOauth && issuer.oAuth2options)
if (oAuthIssuerOrNotRequired && blockchain === 'evm' && !issuer.onChain) return true
if (oAuthIssuerOrNotRequired && blockchain === 'solana' && typeof window.solana === 'undefined') return false
if (oAuthIssuerOrNotRequired && blockchain === 'ultra' && typeof window.ultra === 'undefined') return false
const oAuthIssuer = useOauth && issuer.oAuth2options
if (blockchain === 'evm' && !issuer.onChain) {
return true
}
if (blockchain === 'solana' && typeof window.solana === 'undefined') {
return false
}
if (blockchain === 'ultra' && typeof window.ultra === 'undefined') {
return false
}
const blockChainNameMatch = issuer.blockchain ? issuer.blockchain.toLowerCase() : 'evm' === blockchain
return oAuthIssuerOrNotRequired && blockChainNameMatch
return blockChainNameMatch && (oAuthIssuer || !issuer.oAuth2options)
}).length > 0
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export interface Oauth2IssuerConfig {
path: string
params: object
}
userLogout?: {
path: string
params: object
}
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/wallet/Web3WalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface WalletConnectionOauth2 {
providerType: string
meta?: any
expiryCookieName?: string
logoutEndPoint?: string
}

export enum SupportedWalletProviders {
Expand Down Expand Up @@ -120,6 +121,9 @@ export class Web3WalletProvider {
break
case 'socios':
deleteCookieByName(`tn-oauth2-expiry-socios`)
if (provider.logoutEndPoint) {
fetch(provider.logoutEndPoint, { method: 'POST' })
}
break
}
}
Expand Down Expand Up @@ -271,13 +275,14 @@ export class Web3WalletProvider {
}
}

public registerNewOauth2WalletAddress(address, chainId, oAuth2Provider, blockchain: SupportedBlockchainsParam) {
public registerNewOauth2WalletAddress(address, chainId, oAuth2Provider, blockchain: SupportedBlockchainsParam, logoutEndPoint?: string) {
this.connections[address] = {
address: address,
chainId: chainId,
providerType: oAuth2Provider,
provider: oAuth2Provider,
blockchain: blockchain,
logoutEndPoint: logoutEndPoint,
}
this.saveConnections()
this.emitSavedConnection(address)
Expand Down Expand Up @@ -480,12 +485,14 @@ export class Web3WalletProvider {
let client_id
let redirect_uri
let partner_tag
let logoutEndPoint
for (const issuer of this.client.config.issuers) {
const oauthIssuer = issuer as Oauth2IssuerConfig
if (oauthIssuer.oAuth2options.consumerKey) {
client_id = oauthIssuer.oAuth2options.consumerKey
redirect_uri = oauthIssuer.oAuth2options.endpoints.redirectURI.path
partner_tag = oauthIssuer.oAuth2options.partnerTag
logoutEndPoint = oauthIssuer.oAuth2options.endpoints?.userLogout.path
break
}
}
Expand All @@ -496,7 +503,8 @@ export class Web3WalletProvider {
'socios', // address id
'socios', // chain id
'Socios', // provider
'evm', // blockchain
'evm', // blockchain,
logoutEndPoint,
)
// @ts-ignore
this.client.ui.showLoaderDelayed(['<h4>Connecting to Socios...</h4>'], 600, true)
Expand All @@ -507,7 +515,8 @@ export class Web3WalletProvider {
'socios', // address id
'socios', // chain id
'Socios', // provider
'evm', // blockchain
'evm', // blockchain,
logoutEndPoint,
)
}
return 'socios'
Expand Down

0 comments on commit ca48cf9

Please sign in to comment.