Skip to content

Commit

Permalink
Merge pull request #812 from TokenScript/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
nicktaras authored Aug 29, 2023
2 parents 29cae27 + 9b6aeac commit e2d91d4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
23 changes: 7 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
> Description
This major version of the Token Negotiator provides simplification to the library interface, and new core features including multi-attestation support.
Patch release to support the upgrade of attestations.

### Upgrade Steps

- Please refer to the migration from 2x to 3x guide. https://tokenscript.gitbook.io/token-negotiator/migrating-from-version-2x-to-3x
- Update NPM package to version 3.0.1

### Breaking Changes

- Passive Negotiation 'tokens' hook
- Off chain interface changes
- off chain Attestation schema changes (ASN / EAS)
[none]

### New Features

- Support for multi batch EAS & ASN attestation readability and authentication
- Dynamic EAS attestation support
- AlphaWallet provider selection in active UI mode
- Ultra Network support (BETA)
- Removal of Wallet Connect V1
- Migrated this libraries documentation from README to gitbooks https://tokenscript.gitbook.io/token-negotiator/
- Added attestation migration support utility function 'migrateLegacyTokenStorage'
- Ability to delete existing attestations

### Bug Fixes

- MetaMask support via Wallet Connect V2
- attestation.id modal dimensions updated for mobile and via Windows browsers
- Added support for upgrading attestations for live projects (method added via TicketStorage deleteTicketByDecodedTokenOrId)

### Performance Improvements

- Simplified off chain storage of issuer data
[none]

**Full Change log**:

https://github.com/TokenScript/token-negotiator/compare/v2.7.1...v3.0.0
https://github.com/TokenScript/token-negotiator/compare/v3.0.0...v3.0.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokenscript/token-negotiator",
"version": "3.0.0",
"version": "3.0.1",
"description": "Token-negotiator a token attestation bridge between web 2.0 and 3.0.",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ export class Client {
) {
requiredParams(type, 'Event type is not defined')

if ((type === 'tokens' || type === 'tokens-selected') && callback) {
if (type === 'tokens-selected' && callback) {
this.readTokensFromUrl()
}

Expand Down
12 changes: 6 additions & 6 deletions src/client/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrowserDataInterface } from '../utils/support/isSupported'
import { WalletConnection } from '../wallet/Web3WalletProvider'
import { DecodedToken } from '../outlet/ticketStorage'
import { EasSchemaConfig } from '../outlet/interfaces'
import { TokenData } from './tokenStore'

export type SupportedBlockchainsParam = 'evm' | 'flow' | 'solana' | 'ultra'
export const SignatureSupportedBlockchainsParamList = ['evm', 'flow', 'solana', 'ultra']
Expand Down Expand Up @@ -117,7 +118,6 @@ export interface TokenNegotiatorEventsArgs {
'connected-wallet': EventSenderConnectedWallet
'disconnected-wallet': EventSenderDisconnectedWallet
'tokens-selected': EventSenderTokensSelected
tokens: EventSenderTokens
'tokens-loaded': EventSenderTokensLoaded
'network-change': string
error: EventSenderError
Expand Down Expand Up @@ -150,11 +150,11 @@ export interface EventSenderViewChanged {
}

export interface EventSenderTokensSelected {
selectedTokens: Object
}

export interface EventSenderTokens {
data: any[]
selectedTokens: {
[collectionId: string]: {
tokens: DecodedToken[] | TokenData[]
}
}
}

export interface EventSenderTokensLoaded {
Expand Down
12 changes: 8 additions & 4 deletions src/client/tokenStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OffChainTokenConfig, OnChainIssuer, OnChainTokenConfig, SolanaIssuerConfig, UltraIssuerConfig } from './interface'

import { logger } from '../utils'
import { DecodedToken } from '../outlet/ticketStorage'

interface IssuerLookup {
[collectionID: string]: TokenConfig & { timestamp: number }
Expand All @@ -10,14 +11,17 @@ interface TokenLookup {
[issuer: string]: { timestamp: number; tokens: TokenData[] | null }
}

interface TokenData {
export interface TokenData {
tokenId: string | number
walletAddress?: string
// TODO: add more common fields to this interface
[key: string]: any
}

type TokenConfig = OnChainTokenConfig | OffChainTokenConfig | SolanaIssuerConfig | UltraIssuerConfig

type SelectedTokens = { [collectionId: string]: { tokens: DecodedToken[] | TokenData[] } }

export class TokenStore {
public static LOCAL_STORAGE_KEY = 'tn-tokenStore'

Expand All @@ -28,7 +32,7 @@ export class TokenStore {
private tokenLookup: IssuerLookup = {}

// TODO: change to disabled tokens
private selectedTokens: any = {}
private selectedTokens: SelectedTokens = {}

constructor(
private autoEnableTokens: boolean,
Expand Down Expand Up @@ -173,7 +177,7 @@ export class TokenStore {
return null
}

public setTokens(issuer: string, tokens: TokenData[]) {
public setTokens(issuer: string, tokens: TokenData[] | DecodedToken[]) {
this.tokenData[issuer] = { timestamp: Date.now(), tokens }

this.saveTokenStore()
Expand All @@ -185,7 +189,7 @@ export class TokenStore {
return this.selectedTokens
}

public setSelectedTokens(selectedTokens: any) {
public setSelectedTokens(selectedTokens: SelectedTokens) {
this.selectedTokens = selectedTokens
}

Expand Down
3 changes: 1 addition & 2 deletions src/client/views/token-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ export class TokenList extends AbstractView {

this.viewContainer.querySelectorAll('.mobileToggle-tn').forEach((token: any, index: number) => {
if (index === 0) {
selectedTokens[token.dataset.key] = {}
selectedTokens[token.dataset.key]['tokens'] = []
selectedTokens[token.dataset.key] = { tokens: [] }
}

if (token.checked === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/outlet/localOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MultiTokenAuthRequest, MultiTokenAuthResult, OutletInterface, OutletIss
import { OutletAction } from '../client/messaging'

export class LocalOutlet {
protected ticketStorage: TicketStorage
public readonly ticketStorage: TicketStorage

constructor(config: OutletInterface) {
this.ticketStorage = new TicketStorage(config)
Expand Down
20 changes: 19 additions & 1 deletion src/outlet/ticketStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface EasFieldData {
}

interface TicketStorageSchema {
[collectionHash: string]: StoredTicketRecord[]
[collectionHash: string]: Array<StoredTicketRecord>
}

export interface FilterInterface {
Expand Down Expand Up @@ -167,6 +167,24 @@ export class TicketStorage {
})
}

public deleteTicketByDecodedTokenOrId(collectionId: string, decodedTokenOrId: DecodedToken | string) {
const config = this.config.issuers.find((issuer) => issuer.collectionID === collectionId)
const hashes = createIssuerHashArray(config)
const tokenId = typeof decodedTokenOrId === 'string' ? decodedTokenOrId : decodedTokenOrId.tokenId

for (const hash of hashes) {
for (let i = 0; i < this.ticketCollections[hash].length; i++) {
if (tokenId === this.ticketCollections[hash][0].tokenId) {
this.ticketCollections[hash].splice(i, 1)
this.storeTickets()
return true
}
}
}

return false
}

/**
* Take in a request of collection hashes and return the returns, keyed by client provided ID
* @param request
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// modified by build process.
export const VERSION = '3.0.0'
export const VERSION = '3.0.1'

1 comment on commit e2d91d4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements 37.56% 1365/3634
🔴 Branches 24.65% 391/1586
🔴 Functions 38.49% 184/478
🔴 Lines 37.98% 1163/3062

Test suite run success

84 tests passing in 9 suites.

Report generated by 🧪jest coverage report action from e2d91d4

Please sign in to comment.